From 7f4c4597f1f51af8fa373752a6c162de0651e27b Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Wed, 19 Mar 2025 14:58:40 +0200 Subject: [PATCH] Stubs for SIP update API. (#3533) --- go.mod | 2 +- go.sum | 4 +-- pkg/service/sip.go | 82 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index c5d8e471c..22bea598d 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/jxskiss/base62 v1.1.0 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mediatransportutil v0.0.0-20250310153736-45596af895b6 - github.com/livekit/protocol v1.34.1-0.20250311081227-4035de5f7f95 + github.com/livekit/protocol v1.35.1-0.20250319124948-ce72bd5bb7dc github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 github.com/mackerelio/go-osstat v0.2.5 github.com/magefile/mage v1.15.0 diff --git a/go.sum b/go.sum index 3dd4f0656..2e834ff85 100644 --- a/go.sum +++ b/go.sum @@ -170,8 +170,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20250310153736-45596af895b6 h1:6ZhtnY9I9knfm3ieIPpznQSEU2rDECO8yliW/ANLQ7U= github.com/livekit/mediatransportutil v0.0.0-20250310153736-45596af895b6/go.mod h1:36s+wwmU3O40IAhE+MjBWP3W71QRiEE9SfooSBvtBqY= -github.com/livekit/protocol v1.34.1-0.20250311081227-4035de5f7f95 h1:Ok1vTeYRUQW62vZ20FIy7DbgrDoJmuTKrWcMICs3SOY= -github.com/livekit/protocol v1.34.1-0.20250311081227-4035de5f7f95/go.mod h1:WrT/CYRxtMNOVUjnIPm5OjWtEkmreffTeE1PRZwlRg4= +github.com/livekit/protocol v1.35.1-0.20250319124948-ce72bd5bb7dc h1:RApnDTBKEI1rSMPtz39TC6fuh2Oh+7lmwCtEujgiZCc= +github.com/livekit/protocol v1.35.1-0.20250319124948-ce72bd5bb7dc/go.mod h1:WrT/CYRxtMNOVUjnIPm5OjWtEkmreffTeE1PRZwlRg4= github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 h1:fzuYpAQbCid7ySPpQWWePfQOWUrs8x6dJ0T3Wl07n+Y= github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126/go.mod h1:X5WtEZ7OnEs72Fi5/J+i0on3964F1aynQpCalcgMqRo= github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o= diff --git a/pkg/service/sip.go b/pkg/service/sip.go index 64f571c35..6ca394db9 100644 --- a/pkg/service/sip.go +++ b/pkg/service/sip.go @@ -86,6 +86,9 @@ func (s *SIPService) CreateSIPTrunk(ctx context.Context, req *livekit.CreateSIPT Name: req.Name, Metadata: req.Metadata, } + if err := info.Validate(); err != nil { + return nil, err + } // Validate all trunks including the new one first. it, err := ListSIPInboundTrunk(ctx, s.store, &livekit.ListSIPInboundTrunkRequest{}, info.AsInbound()) @@ -120,7 +123,7 @@ func (s *SIPService) CreateSIPInboundTrunk(ctx context.Context, req *livekit.Cre if info.SipTrunkId != "" { return nil, twirp.NewError(twirp.InvalidArgument, "trunk ID must be empty") } - AppendLogFields(ctx, "trunk", logger.Proto(req.Trunk)) + AppendLogFields(ctx, "trunk", logger.Proto(info)) // Keep ID empty still, so that validation can print "" instead of a non-existent ID in the error. @@ -159,7 +162,7 @@ func (s *SIPService) CreateSIPOutboundTrunk(ctx context.Context, req *livekit.Cr if info.SipTrunkId != "" { return nil, twirp.NewError(twirp.InvalidArgument, "trunk ID must be empty") } - AppendLogFields(ctx, "trunk", logger.Proto(req.Trunk)) + AppendLogFields(ctx, "trunk", logger.Proto(info)) // No additional validation needed for outbound. info.SipTrunkId = guid.New(utils.SIPTrunkPrefix) @@ -169,6 +172,44 @@ func (s *SIPService) CreateSIPOutboundTrunk(ctx context.Context, req *livekit.Cr return info, nil } +func (s *SIPService) UpdateSIPInboundTrunk(ctx context.Context, req *livekit.UpdateSIPInboundTrunkRequest) (*livekit.SIPInboundTrunkInfo, error) { + if err := EnsureSIPAdminPermission(ctx); err != nil { + return nil, twirpAuthError(err) + } + if s.store == nil { + return nil, ErrSIPNotConnected + } + if err := req.Validate(); err != nil { + return nil, err + } + + AppendLogFields(ctx, + "request", logger.Proto(req), + "trunkID", req.SipTrunkId, + ) + + return nil, twirp.NewError(twirp.Unimplemented, "not implemented") +} + +func (s *SIPService) UpdateSIPOutboundTrunk(ctx context.Context, req *livekit.UpdateSIPOutboundTrunkRequest) (*livekit.SIPOutboundTrunkInfo, error) { + if err := EnsureSIPAdminPermission(ctx); err != nil { + return nil, twirpAuthError(err) + } + if s.store == nil { + return nil, ErrSIPNotConnected + } + if err := req.Validate(); err != nil { + return nil, err + } + + AppendLogFields(ctx, + "request", logger.Proto(req), + "trunkID", req.SipTrunkId, + ) + + return nil, twirp.NewError(twirp.Unimplemented, "not implemented") +} + func (s *SIPService) GetSIPInboundTrunk(ctx context.Context, req *livekit.GetSIPInboundTrunkRequest) (*livekit.GetSIPInboundTrunkResponse, error) { if err := EnsureSIPAdminPermission(ctx); err != nil { return nil, twirpAuthError(err) @@ -326,16 +367,8 @@ func (s *SIPService) CreateSIPDispatchRule(ctx context.Context, req *livekit.Cre "trunkID", req.TrunkIds, ) // Keep ID empty, so that validation can print "" instead of a non-existent ID in the error. - info := &livekit.SIPDispatchRuleInfo{ - Rule: req.Rule, - TrunkIds: req.TrunkIds, - InboundNumbers: req.InboundNumbers, - HidePhoneNumber: req.HidePhoneNumber, - Name: req.Name, - Metadata: req.Metadata, - Attributes: req.Attributes, - RoomConfig: req.RoomConfig, - } + info := req.DispatchRuleInfo() + info.SipDispatchRuleId = "" // Validate all rules including the new one first. it, err := ListSIPDispatchRule(ctx, s.store, &livekit.ListSIPDispatchRuleRequest{ @@ -357,6 +390,25 @@ func (s *SIPService) CreateSIPDispatchRule(ctx context.Context, req *livekit.Cre return info, nil } +func (s *SIPService) UpdateSIPDispatchRule(ctx context.Context, req *livekit.UpdateSIPDispatchRuleRequest) (*livekit.SIPDispatchRuleInfo, error) { + if err := EnsureSIPAdminPermission(ctx); err != nil { + return nil, twirpAuthError(err) + } + if s.store == nil { + return nil, ErrSIPNotConnected + } + if err := req.Validate(); err != nil { + return nil, err + } + + AppendLogFields(ctx, + "request", logger.Proto(req), + "ruleID", req.SipDispatchRuleId, + ) + + return nil, twirp.NewError(twirp.Unimplemented, "not implemented") +} + func ListSIPDispatchRule(ctx context.Context, s SIPStore, req *livekit.ListSIPDispatchRuleRequest, add ...*livekit.SIPDispatchRuleInfo) (iters.Iter[*livekit.SIPDispatchRuleInfo], error) { if s == nil { return nil, ErrSIPNotConnected @@ -474,6 +526,9 @@ func (s *SIPService) CreateSIPParticipantRequest(ctx context.Context, req *livek if s.store == nil { return nil, ErrSIPNotConnected } + if err := req.Validate(); err != nil { + return nil, err + } callID := sip.NewCallID() log := logger.GetLogger().WithUnlikelyValues( "callID", callID, @@ -545,6 +600,9 @@ func (s *SIPService) transferSIPParticipantRequest(ctx context.Context, req *liv if err := EnsureAdminPermission(ctx, livekit.RoomName(req.RoomName)); err != nil { return nil, twirpAuthError(err) } + if err := req.Validate(); err != nil { + return nil, err + } resp, err := s.roomService.GetParticipant(ctx, &livekit.RoomParticipantIdentity{ Room: req.RoomName,