@@ -16,6 +16,7 @@ package main
1616
1717import (
1818 "context"
19+ "errors"
1920 "fmt"
2021 "maps"
2122 "slices"
5253 Action : createSIPInboundTrunk ,
5354 ArgsUsage : RequestDesc [livekit.CreateSIPInboundTrunkRequest ](),
5455 },
56+ {
57+ Name : "update" ,
58+ Usage : "Update an inbound SIP Trunk" ,
59+ Action : updateSIPInboundTrunk ,
60+ ArgsUsage : RequestDesc [livekit.UpdateSIPInboundTrunkRequest ](),
61+ Flags : []cli.Flag {
62+ & cli.StringFlag {
63+ Name : "id" ,
64+ Usage : "ID for the trunk to update" ,
65+ },
66+ & cli.StringFlag {
67+ Name : "name" ,
68+ Usage : "Sets a new name for the trunk" ,
69+ },
70+ & cli.StringSliceFlag {
71+ Name : "numbers" ,
72+ Usage : "Sets a new list of numbers for the trunk" ,
73+ },
74+ & cli.StringFlag {
75+ Name : "auth-user" ,
76+ Usage : "Set username for authentication" ,
77+ },
78+ & cli.StringFlag {
79+ Name : "auth-pass" ,
80+ Usage : "Set password for authentication" ,
81+ },
82+ },
83+ },
5584 {
5685 Name : "delete" ,
5786 Usage : "Delete a SIP Trunk" ,
@@ -73,10 +102,46 @@ var (
73102 },
74103 {
75104 Name : "create" ,
76- Usage : "Create a outbound SIP Trunk" ,
105+ Usage : "Create an outbound SIP Trunk" ,
77106 Action : createSIPOutboundTrunk ,
78107 ArgsUsage : RequestDesc [livekit.CreateSIPOutboundTrunkRequest ](),
79108 },
109+ {
110+ Name : "update" ,
111+ Usage : "Update an outbound SIP Trunk" ,
112+ Action : updateSIPOutboundTrunk ,
113+ ArgsUsage : RequestDesc [livekit.UpdateSIPOutboundTrunkRequest ](),
114+ Flags : []cli.Flag {
115+ & cli.StringFlag {
116+ Name : "id" ,
117+ Usage : "ID for the trunk to update" ,
118+ },
119+ & cli.StringFlag {
120+ Name : "name" ,
121+ Usage : "Sets a new name for the trunk" ,
122+ },
123+ & cli.StringFlag {
124+ Name : "address" ,
125+ Usage : "Sets a new destination address for the trunk" ,
126+ },
127+ & cli.StringFlag {
128+ Name : "transport" ,
129+ Usage : "Sets a new transport for the trunk" ,
130+ },
131+ & cli.StringSliceFlag {
132+ Name : "numbers" ,
133+ Usage : "Sets a new list of numbers for the trunk" ,
134+ },
135+ & cli.StringFlag {
136+ Name : "auth-user" ,
137+ Usage : "Set username for authentication" ,
138+ },
139+ & cli.StringFlag {
140+ Name : "auth-pass" ,
141+ Usage : "Set password for authentication" ,
142+ },
143+ },
144+ },
80145 {
81146 Name : "delete" ,
82147 Usage : "Delete SIP Trunk" ,
@@ -102,6 +167,26 @@ var (
102167 Action : createSIPDispatchRule ,
103168 ArgsUsage : RequestDesc [livekit.CreateSIPDispatchRuleRequest ](),
104169 },
170+ {
171+ Name : "update" ,
172+ Usage : "Update a SIP Dispatch Rule" ,
173+ Action : updateSIPDispatchRule ,
174+ ArgsUsage : RequestDesc [livekit.UpdateSIPDispatchRuleRequest ](),
175+ Flags : []cli.Flag {
176+ & cli.StringFlag {
177+ Name : "id" ,
178+ Usage : "ID for the rule to update" ,
179+ },
180+ & cli.StringFlag {
181+ Name : "name" ,
182+ Usage : "Sets a new name for the rule" ,
183+ },
184+ & cli.StringSliceFlag {
185+ Name : "trunks" ,
186+ Usage : "Sets a new list of trunk IDs" ,
187+ },
188+ },
189+ },
105190 {
106191 Name : "delete" ,
107192 Usage : "Delete SIP Dispatch Rule" ,
@@ -230,6 +315,17 @@ var (
230315 }
231316)
232317
318+ func listUpdateFlag (cmd * cli.Command , setName string ) * livekit.ListUpdate {
319+ if ! cmd .IsSet (setName ) {
320+ return nil
321+ }
322+ val := cmd .StringSlice (setName )
323+ if len (val ) == 1 && val [0 ] == "" {
324+ val = []string {}
325+ }
326+ return & livekit.ListUpdate {Set : val }
327+ }
328+
233329func createSIPClient (cmd * cli.Command ) (* lksdk.SIPClient , error ) {
234330 pc , err := loadProjectDetails (cmd )
235331 if err != nil {
@@ -246,6 +342,68 @@ func createSIPInboundTrunk(ctx context.Context, cmd *cli.Command) error {
246342 return createAndPrintReqs (ctx , cmd , nil , cli .CreateSIPInboundTrunk , printSIPInboundTrunkID )
247343}
248344
345+ func updateSIPInboundTrunk (ctx context.Context , cmd * cli.Command ) error {
346+ cli , err := createSIPClient (cmd )
347+ if err != nil {
348+ return err
349+ }
350+ id := cmd .String ("id" )
351+ if cmd .Args ().Len () > 1 {
352+ return errors .New ("expected one JSON file or flags" )
353+ }
354+ if cmd .Args ().Len () == 1 {
355+ // Update from the JSON
356+ req , err := ReadRequestFileOrLiteral [livekit.SIPInboundTrunkInfo ](cmd .Args ().First ())
357+ if err != nil {
358+ return fmt .Errorf ("could not read request: %w" , err )
359+ }
360+ if id == "" {
361+ id = req .SipTrunkId
362+ }
363+ req .SipTrunkId = ""
364+ if id == "" {
365+ return errors .New ("no ID specified, use flag or set it in JSON" )
366+ }
367+ info , err := cli .UpdateSIPInboundTrunk (ctx , & livekit.UpdateSIPInboundTrunkRequest {
368+ SipTrunkId : id ,
369+ Action : & livekit.UpdateSIPInboundTrunkRequest_Replace {
370+ Replace : req ,
371+ },
372+ })
373+ if err != nil {
374+ return err
375+ }
376+ printSIPInboundTrunkID (info )
377+ return err
378+ }
379+ // Update from flags
380+ if id == "" {
381+ return errors .New ("no ID specified" )
382+ }
383+ req := & livekit.SIPInboundTrunkUpdate {}
384+ if val := cmd .String ("name" ); val != "" {
385+ req .Name = & val
386+ }
387+ if val := cmd .String ("auth-user" ); val != "" {
388+ req .AuthUsername = & val
389+ }
390+ if val := cmd .String ("auth-pass" ); val != "" {
391+ req .AuthPassword = & val
392+ }
393+ req .Numbers = listUpdateFlag (cmd , "numbers" )
394+ info , err := cli .UpdateSIPInboundTrunk (ctx , & livekit.UpdateSIPInboundTrunkRequest {
395+ SipTrunkId : id ,
396+ Action : & livekit.UpdateSIPInboundTrunkRequest_Update {
397+ Update : req ,
398+ },
399+ })
400+ if err != nil {
401+ return err
402+ }
403+ printSIPInboundTrunkID (info )
404+ return err
405+ }
406+
249407func createSIPOutboundTrunk (ctx context.Context , cmd * cli.Command ) error {
250408 cli , err := createSIPClient (cmd )
251409 if err != nil {
@@ -254,6 +412,83 @@ func createSIPOutboundTrunk(ctx context.Context, cmd *cli.Command) error {
254412 return createAndPrintReqs (ctx , cmd , nil , cli .CreateSIPOutboundTrunk , printSIPOutboundTrunkID )
255413}
256414
415+ func updateSIPOutboundTrunk (ctx context.Context , cmd * cli.Command ) error {
416+ cli , err := createSIPClient (cmd )
417+ if err != nil {
418+ return err
419+ }
420+ id := cmd .String ("id" )
421+ if cmd .Args ().Len () > 1 {
422+ return errors .New ("expected one JSON file or flags" )
423+ }
424+ if cmd .Args ().Len () == 1 {
425+ // Update from the JSON
426+ req , err := ReadRequestFileOrLiteral [livekit.SIPOutboundTrunkInfo ](cmd .Args ().First ())
427+ if err != nil {
428+ return fmt .Errorf ("could not read request: %w" , err )
429+ }
430+ if id == "" {
431+ id = req .SipTrunkId
432+ }
433+ req .SipTrunkId = ""
434+ if id == "" {
435+ return errors .New ("no ID specified, use flag or set it in JSON" )
436+ }
437+ info , err := cli .UpdateSIPOutboundTrunk (ctx , & livekit.UpdateSIPOutboundTrunkRequest {
438+ SipTrunkId : id ,
439+ Action : & livekit.UpdateSIPOutboundTrunkRequest_Replace {
440+ Replace : req ,
441+ },
442+ })
443+ if err != nil {
444+ return err
445+ }
446+ printSIPOutboundTrunkID (info )
447+ return err
448+ }
449+ // Update from flags
450+ if id == "" {
451+ return errors .New ("no ID specified" )
452+ }
453+ req := & livekit.SIPOutboundTrunkUpdate {}
454+ if val := cmd .String ("name" ); val != "" {
455+ req .Name = & val
456+ }
457+ if val := cmd .String ("address" ); val != "" {
458+ req .Address = & val
459+ }
460+ if val := cmd .String ("transport" ); val != "" {
461+ val = strings .ToUpper (val )
462+ if ! strings .HasPrefix (val , "SIP_TRANSPORT_" ) {
463+ val = "SIP_TRANSPORT_" + val
464+ }
465+ trv , ok := livekit .SIPTransport_value [val ]
466+ if ! ok {
467+ return fmt .Errorf ("unsupported transport: %q" , val )
468+ }
469+ tr := livekit .SIPTransport (trv )
470+ req .Transport = & tr
471+ }
472+ if val := cmd .String ("auth-user" ); val != "" {
473+ req .AuthUsername = & val
474+ }
475+ if val := cmd .String ("auth-pass" ); val != "" {
476+ req .AuthPassword = & val
477+ }
478+ req .Numbers = listUpdateFlag (cmd , "numbers" )
479+ info , err := cli .UpdateSIPOutboundTrunk (ctx , & livekit.UpdateSIPOutboundTrunkRequest {
480+ SipTrunkId : id ,
481+ Action : & livekit.UpdateSIPOutboundTrunkRequest_Update {
482+ Update : req ,
483+ },
484+ })
485+ if err != nil {
486+ return err
487+ }
488+ printSIPOutboundTrunkID (info )
489+ return err
490+ }
491+
257492func userPass (user string , hasPass bool ) string {
258493 if user == "" && ! hasPass {
259494 return ""
@@ -434,6 +669,62 @@ func createSIPDispatchRuleLegacy(ctx context.Context, cmd *cli.Command) error {
434669 return createAndPrintLegacy (ctx , cmd , cli .CreateSIPDispatchRule , printSIPDispatchRuleID )
435670}
436671
672+ func updateSIPDispatchRule (ctx context.Context , cmd * cli.Command ) error {
673+ cli , err := createSIPClient (cmd )
674+ if err != nil {
675+ return err
676+ }
677+ id := cmd .String ("id" )
678+ if cmd .Args ().Len () > 1 {
679+ return errors .New ("expected one JSON file or flags" )
680+ }
681+ if cmd .Args ().Len () == 1 {
682+ // Update from the JSON
683+ req , err := ReadRequestFileOrLiteral [livekit.SIPDispatchRuleInfo ](cmd .Args ().First ())
684+ if err != nil {
685+ return fmt .Errorf ("could not read request: %w" , err )
686+ }
687+ if id == "" {
688+ id = req .SipDispatchRuleId
689+ }
690+ req .SipDispatchRuleId = ""
691+ if id == "" {
692+ return errors .New ("no ID specified, use flag or set it in JSON" )
693+ }
694+ info , err := cli .UpdateSIPDispatchRule (ctx , & livekit.UpdateSIPDispatchRuleRequest {
695+ SipDispatchRuleId : id ,
696+ Action : & livekit.UpdateSIPDispatchRuleRequest_Replace {
697+ Replace : req ,
698+ },
699+ })
700+ if err != nil {
701+ return err
702+ }
703+ printSIPDispatchRuleID (info )
704+ return err
705+ }
706+ // Update from flags
707+ if id == "" {
708+ return errors .New ("no ID specified" )
709+ }
710+ req := & livekit.SIPDispatchRuleUpdate {}
711+ if val := cmd .String ("name" ); val != "" {
712+ req .Name = & val
713+ }
714+ req .TrunkIds = listUpdateFlag (cmd , "trunks" )
715+ info , err := cli .UpdateSIPDispatchRule (ctx , & livekit.UpdateSIPDispatchRuleRequest {
716+ SipDispatchRuleId : id ,
717+ Action : & livekit.UpdateSIPDispatchRuleRequest_Update {
718+ Update : req ,
719+ },
720+ })
721+ if err != nil {
722+ return err
723+ }
724+ printSIPDispatchRuleID (info )
725+ return err
726+ }
727+
437728func listSipDispatchRule (ctx context.Context , cmd * cli.Command ) error {
438729 cli , err := createSIPClient (cmd )
439730 if err != nil {
0 commit comments