Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new flag to print curl commands #321

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/livekit-cli/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"

"github.com/livekit/livekit-cli/pkg/loadtester"
"github.com/livekit/protocol/egress"
"github.com/livekit/protocol/livekit"
lksdk "github.com/livekit/server-sdk-go/v2"

"github.com/livekit/livekit-cli/pkg/loadtester"
)

const egressCategory = "Egress"
Expand Down Expand Up @@ -233,7 +234,7 @@ func createEgressClient(c *cli.Context) error {
return err
}

egressClient = lksdk.NewEgressClient(pc.URL, pc.APIKey, pc.APISecret)
egressClient = lksdk.NewEgressClient(pc.URL, pc.APIKey, pc.APISecret, withDefaultClientOpts(pc)...)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func createIngressClient(c *cli.Context) error {
return err
}

ingressClient = lksdk.NewIngressClient(pc.URL, pc.APIKey, pc.APISecret)
ingressClient = lksdk.NewIngressClient(pc.URL, pc.APIKey, pc.APISecret, withDefaultClientOpts(pc)...)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func createRoomClient(c *cli.Context) error {
return err
}

roomClient = lksdk.NewRoomServiceClient(pc.URL, pc.APIKey, pc.APISecret)
roomClient = lksdk.NewRoomServiceClient(pc.URL, pc.APIKey, pc.APISecret, withDefaultClientOpts(pc)...)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func createSIPClient(c *cli.Context) error {
return err
}

sipClient = lksdk.NewSIPClient(pc.URL, pc.APIKey, pc.APISecret)
sipClient = lksdk.NewSIPClient(pc.URL, pc.APIKey, pc.APISecret, withDefaultClientOpts(pc)...)
return nil
}

Expand Down
24 changes: 24 additions & 0 deletions cmd/livekit-cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"path/filepath"
"strings"

"github.com/livekit/protocol/utils/interceptors"
"github.com/twitchtv/twirp"
"github.com/urfave/cli/v2"

"github.com/livekit/livekit-cli/pkg/config"
Expand Down Expand Up @@ -60,6 +62,13 @@ var (
Name: "verbose",
Required: false,
}
printCurl bool
curlFlag = &cli.BoolFlag{
Name: "curl",
Usage: "print curl commands for API actions",
Destination: &printCurl,
Required: false,
}
)

func withDefaultFlags(flags ...cli.Flag) []cli.Flag {
Expand All @@ -68,10 +77,25 @@ func withDefaultFlags(flags ...cli.Flag) []cli.Flag {
apiKeyFlag,
secretFlag,
projectFlag,
curlFlag,
verboseFlag,
}, flags...)
}

func withDefaultClientOpts(c *config.ProjectConfig) []twirp.ClientOption {
var (
opts []twirp.ClientOption
ics []twirp.Interceptor
)
if printCurl {
ics = append(ics, interceptors.NewCurlPrinter(os.Stdout, c.URL))
}
if len(ics) != 0 {
opts = append(opts, twirp.WithClientInterceptors(ics...))
}
return opts
}

func PrintJSON(obj interface{}) {
txt, _ := json.MarshalIndent(obj, "", " ")
fmt.Println(string(txt))
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ toolchain go1.22.2
require (
github.com/frostbyte73/core v0.0.10
github.com/go-logr/logr v1.4.1
github.com/livekit/protocol v1.14.1-0.20240426104403-e7962f444464
github.com/livekit/server-sdk-go/v2 v2.1.2
github.com/livekit/protocol v1.14.1-0.20240501190830-e0c63d76982c
github.com/livekit/server-sdk-go/v2 v2.1.3-0.20240430213107-857de3e1d247
github.com/manifoldco/promptui v0.9.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pion/rtcp v1.2.14
Expand All @@ -17,6 +17,7 @@ require (
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
github.com/twitchtv/twirp v8.1.3+incompatible
github.com/urfave/cli/v2 v2.27.1
go.uber.org/atomic v1.11.0
golang.org/x/sync v0.7.0
Expand Down Expand Up @@ -75,7 +76,6 @@ require (
github.com/puzpuzpuz/xsync/v3 v3.1.0 // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/twitchtv/twirp v8.1.3+incompatible // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ 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-20240302142739-1c3dd691a1b8 h1:xawydPEACNO5Ncs2LgioTjWghXQ0eUN1q1RnVUUyVnI=
github.com/livekit/mediatransportutil v0.0.0-20240302142739-1c3dd691a1b8/go.mod h1:jwKUCmObuiEDH0iiuJHaGMXwRs3RjrB4G6qqgkr/5oE=
github.com/livekit/protocol v1.14.1-0.20240426104403-e7962f444464 h1:5IxCPDkibpvnAYN6+djltH6Gj4dMOL0hNecHn5jZKmk=
github.com/livekit/protocol v1.14.1-0.20240426104403-e7962f444464/go.mod h1:pnn0Dv+/0K0OFqKHX6J6SreYO1dZxl6tDuAZ1ns8L/w=
github.com/livekit/protocol v1.14.1-0.20240501190830-e0c63d76982c h1:qBT99Exblr8np8r7zvsuGN20i2HMQ4fZQRh/4sftObs=
github.com/livekit/protocol v1.14.1-0.20240501190830-e0c63d76982c/go.mod h1:pnn0Dv+/0K0OFqKHX6J6SreYO1dZxl6tDuAZ1ns8L/w=
github.com/livekit/psrpc v0.5.3-0.20240228172457-3724cb4adbc4 h1:253WtQ2VGVHzIIzW9MUZj7vUDDILESU3zsEbiRdxYF0=
github.com/livekit/psrpc v0.5.3-0.20240228172457-3724cb4adbc4/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0=
github.com/livekit/server-sdk-go/v2 v2.1.2 h1:3MhFqptHjzpsNAcisHYDtn77qrJ9szsAy4zJkeI3Mic=
github.com/livekit/server-sdk-go/v2 v2.1.2/go.mod h1:ZjOQBtoFcU+oq1c2xaMLHhcQ3DNcfkwC3FHG8DAvkZ8=
github.com/livekit/server-sdk-go/v2 v2.1.3-0.20240430213107-857de3e1d247 h1:2dSZR9neMfMevsXRYrNvdes/SsVQJ/+zPFS4d61qZr8=
github.com/livekit/server-sdk-go/v2 v2.1.3-0.20240430213107-857de3e1d247/go.mod h1:ZjOQBtoFcU+oq1c2xaMLHhcQ3DNcfkwC3FHG8DAvkZ8=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
Expand Down
Loading