Skip to content

Commit 9f5cef0

Browse files
authored
Support SIP media config for trunks. (#888)
1 parent 34a663f commit 9f5cef0

2 files changed

Lines changed: 69 additions & 22 deletions

File tree

autocomplete/fish_autocomplete

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,11 @@ complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcomman
632632
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and not __fish_seen_subcommand_from list create update delete help h' -a 'create' -d 'Create an inbound SIP Trunk'
633633
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l name -r -d 'Sets a new name for the trunk'
634634
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l numbers -r -d 'Sets a list of numbers for the trunk'
635-
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l media-enc -r -d 'Sets media encryption for outbound call'
636635
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l auth-user -r -d 'Set username for authentication'
637636
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l auth-pass -r -d 'Set password for authentication'
637+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l media-enc -r -d 'Sets media encryption for outbound call'
638+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l no-default-codecs -d 'Disables a builtin list of default SIP codecs'
639+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l codecs -r -d 'Sets a list of SIP codecs for outbound call'
638640
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create' -f -l help -s h -d 'show help'
639641
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from create; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
640642
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and not __fish_seen_subcommand_from list create update delete help h' -a 'update' -d 'Update an inbound SIP Trunk'
@@ -643,6 +645,9 @@ complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_f
643645
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l numbers -r -d 'Sets a new list of numbers for the trunk'
644646
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l auth-user -r -d 'Set username for authentication'
645647
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l auth-pass -r -d 'Set password for authentication'
648+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l media-enc -r -d 'Sets media encryption for outbound call'
649+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l no-default-codecs -d 'Disables a builtin list of default SIP codecs'
650+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l codecs -r -d 'Sets a list of SIP codecs for outbound call'
646651
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update' -f -l help -s h -d 'show help'
647652
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and __fish_seen_subcommand_from update; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
648653
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from inbound in inbound-trunk; and not __fish_seen_subcommand_from list create update delete help h' -a 'delete' -d 'Delete a SIP Trunk'
@@ -660,10 +665,12 @@ complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_f
660665
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l address -r -d 'Sets a destination address for the trunk'
661666
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l transport -r -d 'Sets a transport for the trunk'
662667
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l destination-country -r -d 'Sets a destination country for the trunk as ISO 3166-1 alpha-2 (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)'
663-
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l media-enc -r -d 'Sets media encryption for outbound call'
664668
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l numbers -r -d 'Sets a list of numbers for the trunk'
665669
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l auth-user -r -d 'Set username for authentication'
666670
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l auth-pass -r -d 'Set password for authentication'
671+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l media-enc -r -d 'Sets media encryption for outbound call'
672+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l no-default-codecs -d 'Disables a builtin list of default SIP codecs'
673+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l codecs -r -d 'Sets a list of SIP codecs for outbound call'
667674
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create' -f -l help -s h -d 'show help'
668675
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from create; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
669676
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and not __fish_seen_subcommand_from list create update delete help h' -a 'update' -d 'Update an outbound SIP Trunk'
@@ -675,6 +682,9 @@ complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_f
675682
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l numbers -r -d 'Sets a new list of numbers for the trunk'
676683
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l auth-user -r -d 'Set username for authentication'
677684
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l auth-pass -r -d 'Set password for authentication'
685+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l media-enc -r -d 'Sets media encryption for outbound call'
686+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l no-default-codecs -d 'Disables a builtin list of default SIP codecs'
687+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l codecs -r -d 'Sets a list of SIP codecs for outbound call'
678688
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update' -f -l help -s h -d 'show help'
679689
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and __fish_seen_subcommand_from update; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
680690
complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from outbound out outbound-trunk; and not __fish_seen_subcommand_from list create update delete help h' -a 'delete' -d 'Delete SIP Trunk'
@@ -703,6 +713,9 @@ complete -x -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcomman
703713
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l id -r -d 'ID for the rule to update'
704714
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l name -r -d 'Sets a new name for the rule'
705715
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l trunks -r -d 'Sets a new list of trunk IDs'
716+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l media-enc -r -d 'Sets media encryption for outbound call'
717+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l no-default-codecs -d 'Disables a builtin list of default SIP codecs'
718+
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l codecs -r -d 'Sets a list of SIP codecs for outbound call'
706719
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l help -s h -d 'show help'
707720
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l direct -r -d 'Sets a direct dispatch to a specified room'
708721
complete -c lk -n '__fish_seen_subcommand_from sip; and __fish_seen_subcommand_from dispatch dispatch-rule; and __fish_seen_subcommand_from update' -f -l caller -s individual -r -d 'Sets a individual caller dispatch to a new room with a specific prefix'

cmd/lk/sip.go

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var (
5656
Usage: "Create an inbound SIP Trunk",
5757
Action: createSIPInboundTrunk,
5858
ArgsUsage: RequestDesc[livekit.CreateSIPInboundTrunkRequest](),
59-
Flags: []cli.Flag{
59+
Flags: appendSIPMediaFlags([]cli.Flag{
6060
&cli.StringFlag{
6161
Name: "name",
6262
Usage: "Sets a new name for the trunk",
@@ -65,7 +65,6 @@ var (
6565
Name: "numbers",
6666
Usage: "Sets a list of numbers for the trunk",
6767
},
68-
sipMediaEncFlag(),
6968
&cli.StringFlag{
7069
Name: "auth-user",
7170
Usage: "Set username for authentication",
@@ -74,14 +73,14 @@ var (
7473
Name: "auth-pass",
7574
Usage: "Set password for authentication",
7675
},
77-
},
76+
}),
7877
},
7978
{
8079
Name: "update",
8180
Usage: "Update an inbound SIP Trunk",
8281
Action: updateSIPInboundTrunk,
8382
ArgsUsage: RequestDesc[livekit.UpdateSIPInboundTrunkRequest](),
84-
Flags: []cli.Flag{
83+
Flags: appendSIPMediaFlags([]cli.Flag{
8584
&cli.StringFlag{
8685
Name: "id",
8786
Usage: "ID for the trunk to update",
@@ -102,7 +101,7 @@ var (
102101
Name: "auth-pass",
103102
Usage: "Set password for authentication",
104103
},
105-
},
104+
}),
106105
},
107106
{
108107
Name: "delete",
@@ -128,7 +127,7 @@ var (
128127
Usage: "Create an outbound SIP Trunk",
129128
Action: createSIPOutboundTrunk,
130129
ArgsUsage: RequestDesc[livekit.CreateSIPOutboundTrunkRequest](),
131-
Flags: []cli.Flag{
130+
Flags: appendSIPMediaFlags([]cli.Flag{
132131
&cli.StringFlag{
133132
Name: "name",
134133
Usage: "Sets a new name for the trunk",
@@ -145,7 +144,6 @@ var (
145144
Name: "destination-country",
146145
Usage: "Sets a destination country for the trunk as ISO 3166-1 alpha-2 (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)",
147146
},
148-
sipMediaEncFlag(),
149147
&cli.StringSliceFlag{
150148
Name: "numbers",
151149
Usage: "Sets a list of numbers for the trunk",
@@ -158,14 +156,14 @@ var (
158156
Name: "auth-pass",
159157
Usage: "Set password for authentication",
160158
},
161-
},
159+
}),
162160
},
163161
{
164162
Name: "update",
165163
Usage: "Update an outbound SIP Trunk",
166164
Action: updateSIPOutboundTrunk,
167165
ArgsUsage: RequestDesc[livekit.UpdateSIPOutboundTrunkRequest](),
168-
Flags: []cli.Flag{
166+
Flags: appendSIPMediaFlags([]cli.Flag{
169167
&cli.StringFlag{
170168
Name: "id",
171169
Usage: "ID for the trunk to update",
@@ -198,7 +196,7 @@ var (
198196
Name: "auth-pass",
199197
Usage: "Set password for authentication",
200198
},
201-
},
199+
}),
202200
},
203201
{
204202
Name: "delete",
@@ -269,7 +267,7 @@ var (
269267
Usage: "Update a SIP Dispatch Rule",
270268
Action: updateSIPDispatchRule,
271269
ArgsUsage: RequestDesc[livekit.UpdateSIPDispatchRuleRequest](),
272-
Flags: []cli.Flag{
270+
Flags: appendSIPMediaFlags([]cli.Flag{
273271
&cli.StringFlag{
274272
Name: "id",
275273
Usage: "ID for the rule to update",
@@ -282,7 +280,7 @@ var (
282280
Name: "trunks",
283281
Usage: "Sets a new list of trunk IDs",
284282
},
285-
},
283+
}),
286284
MutuallyExclusiveFlags: []cli.MutuallyExclusiveFlags{
287285
{
288286
Flags: [][]cli.Flag{
@@ -484,16 +482,12 @@ func optBoolFlag(cmd *cli.Command, setName string) (bool, bool) {
484482
return cmd.Bool(setName), true
485483
}
486484

487-
func sipMediaEncFlag() cli.Flag {
488-
return &cli.StringFlag{
489-
Name: "media-enc",
490-
Usage: "Sets media encryption for outbound call",
491-
}
492-
}
493-
494485
func appendSIPMediaFlags(flags []cli.Flag) []cli.Flag {
495486
flags = append(flags,
496-
sipMediaEncFlag(),
487+
&cli.StringFlag{
488+
Name: "media-enc",
489+
Usage: "Sets media encryption for outbound call",
490+
},
497491
&cli.BoolFlag{
498492
Name: "no-default-codecs",
499493
Usage: "Disables a builtin list of default SIP codecs",
@@ -600,6 +594,11 @@ func createSIPInboundTrunk(ctx context.Context, cmd *cli.Command) error {
600594
if val, ok := listSetFlag(cmd, "numbers"); ok {
601595
p.Numbers = val
602596
}
597+
if m, err := parseSIPMediaConfig(cmd); err == nil {
598+
p.Media = m
599+
} else if err != nil {
600+
return err
601+
}
603602
if enc, err := parseSIPMediaEnc(cmd); err == nil && enc != nil {
604603
p.MediaEncryption = *enc
605604
} else if err != nil {
@@ -663,6 +662,16 @@ func updateSIPInboundTrunk(ctx context.Context, cmd *cli.Command) error {
663662
if val := cmd.String("auth-pass"); val != "" {
664663
req.AuthPassword = &val
665664
}
665+
if m, err := parseSIPMediaConfig(cmd); err == nil {
666+
req.Media = m
667+
} else if err != nil {
668+
return err
669+
}
670+
if enc, err := parseSIPMediaEnc(cmd); err == nil && enc != nil {
671+
req.MediaEncryption = enc
672+
} else if err != nil {
673+
return err
674+
}
666675
req.Numbers = listUpdateFlag(cmd, "numbers")
667676
info, err := cli.UpdateSIPInboundTrunk(ctx, &livekit.UpdateSIPInboundTrunkRequest{
668677
SipTrunkId: id,
@@ -707,6 +716,11 @@ func createSIPOutboundTrunk(ctx context.Context, cmd *cli.Command) error {
707716
if val := cmd.String("destination-country"); val != "" {
708717
p.DestinationCountry = val
709718
}
719+
if m, err := parseSIPMediaConfig(cmd); err == nil {
720+
p.Media = m
721+
} else if err != nil {
722+
return err
723+
}
710724
if enc, err := parseSIPMediaEnc(cmd); err == nil && enc != nil {
711725
p.MediaEncryption = *enc
712726
} else if err != nil {
@@ -791,6 +805,16 @@ func updateSIPOutboundTrunk(ctx context.Context, cmd *cli.Command) error {
791805
if val := cmd.String("auth-pass"); val != "" {
792806
req.AuthPassword = &val
793807
}
808+
if m, err := parseSIPMediaConfig(cmd); err == nil {
809+
req.Media = m
810+
} else if err != nil {
811+
return err
812+
}
813+
if enc, err := parseSIPMediaEnc(cmd); err == nil && enc != nil {
814+
req.MediaEncryption = enc
815+
} else if err != nil {
816+
return err
817+
}
794818
req.Numbers = listUpdateFlag(cmd, "numbers")
795819
info, err := cli.UpdateSIPOutboundTrunk(ctx, &livekit.UpdateSIPOutboundTrunkRequest{
796820
SipTrunkId: id,
@@ -1083,6 +1107,16 @@ func updateSIPDispatchRule(ctx context.Context, cmd *cli.Command) error {
10831107
req.Name = &val
10841108
}
10851109
req.TrunkIds = listUpdateFlag(cmd, "trunks")
1110+
if m, err := parseSIPMediaConfig(cmd); err == nil {
1111+
req.Media = m
1112+
} else if err != nil {
1113+
return err
1114+
}
1115+
if enc, err := parseSIPMediaEnc(cmd); err == nil && enc != nil {
1116+
req.MediaEncryption = enc
1117+
} else if err != nil {
1118+
return err
1119+
}
10861120
if val := cmd.String("direct"); val != "" {
10871121
if req.Rule != nil {
10881122
return fmt.Errorf("only one dispatch rule type is allowed")

0 commit comments

Comments
 (0)