Skip to content

Commit dbd9126

Browse files
authored
fix(cmd): relocate temp files across filesystem boundaries (#490)
1 parent a94c6ef commit dbd9126

File tree

16 files changed

+283
-181
lines changed

16 files changed

+283
-181
lines changed

cmd/lk/app.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/charmbracelet/lipgloss"
2828
"github.com/livekit/livekit-cli/pkg/bootstrap"
2929
"github.com/livekit/livekit-cli/pkg/config"
30+
"github.com/livekit/livekit-cli/pkg/util"
3031
"github.com/urfave/cli/v3"
3132
)
3233

@@ -192,12 +193,12 @@ func listTemplates(ctx context.Context, cmd *cli.Command) error {
192193
}
193194

194195
if cmd.Bool("json") {
195-
PrintJSON(templates)
196+
util.PrintJSON(templates)
196197
} else {
197198
const maxDescLength = 64
198199
table := CreateTable().Headers("Template", "Description").BorderRow(true)
199200
for _, t := range templates {
200-
desc := strings.Join(wrapToLines(t.Desc, maxDescLength), "\n")
201+
desc := strings.Join(util.WrapToLines(t.Desc, maxDescLength), "\n")
201202
url := theme.Focused.Title.Render(t.URL)
202203
tags := theme.Help.ShortDesc.Render("#" + strings.Join(t.Tags, " #"))
203204
table.Row(
@@ -355,7 +356,7 @@ func cloneTemplate(_ context.Context, cmd *cli.Command, url, appName string) err
355356
var stderr string
356357
var cmdErr error
357358

358-
tempName, relocate, cleanup := useTempPath(appName)
359+
tempName, relocate, cleanup := util.UseTempPath(appName)
359360
defer cleanup()
360361

361362
if err := spinner.New().

cmd/lk/cloud.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
authutil "github.com/livekit/livekit-cli/pkg/auth"
3232
"github.com/livekit/livekit-cli/pkg/config"
33+
"github.com/livekit/livekit-cli/pkg/util"
3334
"github.com/livekit/protocol/auth"
3435
)
3536

@@ -250,7 +251,7 @@ func requireToken(_ context.Context, cmd *cli.Command) (string, error) {
250251
// construct a token from the chosen project, using the hashed secret as the identity
251252
// as a means of preventing any old token generated with this key/secret pair from
252253
// deleting it
253-
hash, err := hashString(project.APISecret)
254+
hash, err := util.HashString(project.APISecret)
254255
if err != nil {
255256
return "", err
256257
}
@@ -324,7 +325,7 @@ func tryAuthIfNeeded(ctx context.Context, cmd *cli.Command) error {
324325
}
325326

326327
// make sure name is unique
327-
name, err := URLSafeName(ak.URL)
328+
name, err := util.URLSafeName(ak.URL)
328329
if err != nil {
329330
return err
330331
}

cmd/lk/dispatch.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/urfave/cli/v3"
99

10+
"github.com/livekit/livekit-cli/pkg/util"
1011
"github.com/livekit/protocol/livekit"
1112
"github.com/livekit/protocol/utils"
1213
lksdk "github.com/livekit/server-sdk-go/v2"
@@ -118,14 +119,14 @@ func listDispatchAndPrint(cmd *cli.Command, req *livekit.ListAgentDispatchReques
118119
return cli.ShowSubcommandHelp(cmd)
119120
}
120121
if cmd.Bool("verbose") {
121-
PrintJSON(req)
122+
util.PrintJSON(req)
122123
}
123124
res, err := dispatchClient.ListDispatch(context.Background(), req)
124125
if err != nil {
125126
return err
126127
}
127128
if cmd.Bool("json") {
128-
PrintJSON(res)
129+
util.PrintJSON(res)
129130
} else {
130131
table := CreateTable().
131132
Headers("DispatchID", "Room", "AgentName", "Metadata")
@@ -164,7 +165,7 @@ func createAgentDispatch(ctx context.Context, cmd *cli.Command) error {
164165
return errors.New("agent-name is required")
165166
}
166167
if cmd.Bool("verbose") {
167-
PrintJSON(req)
168+
util.PrintJSON(req)
168169
}
169170

170171
info, err := dispatchClient.CreateDispatch(context.Background(), req)
@@ -173,7 +174,7 @@ func createAgentDispatch(ctx context.Context, cmd *cli.Command) error {
173174
}
174175

175176
if cmd.Bool("json") {
176-
PrintJSON(info)
177+
util.PrintJSON(info)
177178
} else {
178179
fmt.Printf("Dispatch created: %v\n", info)
179180
}
@@ -204,7 +205,7 @@ func deleteAgentDispatch(ctx context.Context, cmd *cli.Command) error {
204205
}
205206

206207
if cmd.Bool("json") {
207-
PrintJSON(info)
208+
util.PrintJSON(info)
208209
} else {
209210
fmt.Printf("Dispatch deleted: %v\n", info)
210211
}

cmd/lk/egress.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
lksdk "github.com/livekit/server-sdk-go/v2"
3737

3838
"github.com/livekit/livekit-cli/pkg/loadtester"
39+
"github.com/livekit/livekit-cli/pkg/util"
3940
)
4041

4142
type egressType string
@@ -403,7 +404,7 @@ func handleEgressStart(ctx context.Context, cmd *cli.Command) error {
403404
case string(EgressTypeTrackComposite):
404405
return startTrackCompositeEgress(ctx, cmd)
405406
default:
406-
return errors.New("unrecognized egress type " + wrapWith("\"")(cmd.String("type")))
407+
return errors.New("unrecognized egress type " + util.WrapWith("\"")(cmd.String("type")))
407408
}
408409
}
409410

@@ -568,7 +569,7 @@ func unmarshalEgressRequest(cmd *cli.Command, req proto.Message) error {
568569
}
569570

570571
if cmd.Bool("verbose") {
571-
PrintJSON(req)
572+
util.PrintJSON(req)
572573
}
573574
return nil
574575
}
@@ -597,7 +598,7 @@ func listEgress(ctx context.Context, cmd *cli.Command) error {
597598
}
598599

599600
if cmd.Bool("json") {
600-
PrintJSON(items)
601+
util.PrintJSON(items)
601602
} else {
602603
table := CreateTable().
603604
Headers("EgressID", "Status", "Type", "Source", "Started At", "Error")

cmd/lk/ingress.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/urfave/cli/v3"
2222

23+
"github.com/livekit/livekit-cli/pkg/util"
2324
"github.com/livekit/protocol/livekit"
2425
lksdk "github.com/livekit/server-sdk-go/v2"
2526
)
@@ -177,7 +178,7 @@ func createIngress(ctx context.Context, cmd *cli.Command) error {
177178
}
178179

179180
if cmd.Bool("verbose") {
180-
PrintJSON(req)
181+
util.PrintJSON(req)
181182
}
182183

183184
info, err := ingressClient.CreateIngress(context.Background(), req)
@@ -196,7 +197,7 @@ func updateIngress(ctx context.Context, cmd *cli.Command) error {
196197
}
197198

198199
if cmd.Bool("verbose") {
199-
PrintJSON(req)
200+
util.PrintJSON(req)
200201
}
201202

202203
info, err := ingressClient.UpdateIngress(context.Background(), req)
@@ -221,7 +222,7 @@ func listIngress(ctx context.Context, cmd *cli.Command) error {
221222
// This is inconsistent with other commands in which verbose is used for debug info, but is
222223
// kept for compatibility with the previous behavior.
223224
if cmd.Bool("verbose") || cmd.Bool("json") {
224-
PrintJSON(res)
225+
util.PrintJSON(res)
225226
} else {
226227
table := CreateTable().
227228
Headers("IngressID", "Name", "Room", "StreamKey", "URL", "Status", "Error")

cmd/lk/project.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/urfave/cli/v3"
2828

2929
"github.com/livekit/livekit-cli/pkg/config"
30+
"github.com/livekit/livekit-cli/pkg/util"
3031
)
3132

3233
var (
@@ -248,7 +249,7 @@ func listProjects(ctx context.Context, cmd *cli.Command) error {
248249
selectedStyle := theme.Focused.Title.Padding(0, 1)
249250

250251
if cmd.Bool("json") {
251-
PrintJSON(cliConfig.Projects)
252+
util.PrintJSON(cliConfig.Projects)
252253
} else {
253254
table := CreateTable().
254255
StyleFunc(func(row, col int) lipgloss.Style {

cmd/lk/proto.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"reflect"
2323

24+
"github.com/livekit/livekit-cli/pkg/util"
2425
"github.com/urfave/cli/v3"
2526
"google.golang.org/protobuf/encoding/protojson"
2627
"google.golang.org/protobuf/proto"
@@ -108,7 +109,7 @@ func createAndPrint[T any, P protoTypeValidator[T], R any](
108109
return fmt.Errorf("could not read request: %w", err)
109110
}
110111
if cmd.Bool("verbose") {
111-
PrintJSON(req)
112+
util.PrintJSON(req)
112113
}
113114
if err = req.Validate(); err != nil {
114115
return err
@@ -132,7 +133,7 @@ func createAndPrintLegacy[T any, P protoType[T], R any](
132133
return err
133134
}
134135
if cmd.Bool("verbose") {
135-
PrintJSON(req)
136+
util.PrintJSON(req)
136137
}
137138
info, err := create(ctx, req)
138139
if err != nil {
@@ -192,7 +193,7 @@ func listAndPrint[
192193
}
193194

194195
if cmd.Bool("json") {
195-
PrintJSON(res)
196+
util.PrintJSON(res)
196197
} else {
197198
table := CreateTable().
198199
Headers(header...)

cmd/lk/replay.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/urfave/cli/v3"
1010

1111
authutil "github.com/livekit/livekit-cli/pkg/auth"
12+
"github.com/livekit/livekit-cli/pkg/util"
1213
"github.com/livekit/protocol/auth"
1314
"github.com/livekit/protocol/replay"
1415
lksdk "github.com/livekit/server-sdk-go/v2"
@@ -127,7 +128,7 @@ func listReplays(ctx context.Context, cmd *cli.Command) error {
127128
}
128129

129130
if cmd.Bool("json") {
130-
PrintJSON(res.Replays)
131+
util.PrintJSON(res.Replays)
131132
} else {
132133
table := CreateTable().Headers("ReplayID")
133134
for _, info := range res.Replays {

cmd/lk/room.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/urfave/cli/v3"
2828
"google.golang.org/protobuf/encoding/protojson"
2929

30+
"github.com/livekit/livekit-cli/pkg/util"
3031
"github.com/livekit/protocol/logger"
3132

3233
"github.com/livekit/protocol/livekit"
@@ -635,7 +636,7 @@ func createRoom(ctx context.Context, cmd *cli.Command) error {
635636
return err
636637
}
637638

638-
PrintJSON(room)
639+
util.PrintJSON(room)
639640
return nil
640641
}
641642

@@ -644,7 +645,7 @@ func listRooms(ctx context.Context, cmd *cli.Command) error {
644645
if cmd.Bool("verbose") && len(names) > 0 {
645646
fmt.Printf(
646647
"Querying rooms matching %s",
647-
strings.Join(mapStrings(names, wrapWith("\"")), ", "),
648+
strings.Join(util.MapStrings(names, util.WrapWith("\"")), ", "),
648649
)
649650
}
650651

@@ -659,7 +660,7 @@ func listRooms(ctx context.Context, cmd *cli.Command) error {
659660
}
660661

661662
if cmd.Bool("json") {
662-
PrintJSON(res)
663+
util.PrintJSON(res)
663664
} else {
664665
table := CreateTable().Headers("RoomID", "Name", "Participants", "Publishers")
665666
for _, rm := range res.Rooms {
@@ -688,7 +689,7 @@ func _deprecatedListRoom(ctx context.Context, cmd *cli.Command) error {
688689
return nil
689690
}
690691
rm := res.Rooms[0]
691-
PrintJSON(rm)
692+
util.PrintJSON(rm)
692693
return nil
693694
}
694695

@@ -720,7 +721,7 @@ func updateRoomMetadata(ctx context.Context, cmd *cli.Command) error {
720721
}
721722

722723
fmt.Println("Updated room metadata")
723-
PrintJSON(res)
724+
util.PrintJSON(res)
724725
return nil
725726
}
726727

@@ -735,7 +736,7 @@ func _deprecatedUpdateRoomMetadata(ctx context.Context, cmd *cli.Command) error
735736
}
736737

737738
fmt.Println("Updated room metadata")
738-
PrintJSON(res)
739+
util.PrintJSON(res)
739740
return nil
740741
}
741742

@@ -934,7 +935,7 @@ func getParticipant(ctx context.Context, cmd *cli.Command) error {
934935
return err
935936
}
936937

937-
PrintJSON(res)
938+
util.PrintJSON(res)
938939

939940
return nil
940941
}
@@ -971,7 +972,7 @@ func updateParticipant(ctx context.Context, cmd *cli.Command) error {
971972
}
972973

973974
fmt.Println("updating participant...")
974-
PrintJSON(req)
975+
util.PrintJSON(req)
975976
if _, err := roomClient.UpdateParticipant(ctx, req); err != nil {
976977
return err
977978
}

cmd/lk/token.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/charmbracelet/huh"
2626
"github.com/urfave/cli/v3"
2727

28+
"github.com/livekit/livekit-cli/pkg/util"
2829
"github.com/livekit/protocol/auth"
2930
"github.com/livekit/protocol/livekit"
3031
)
@@ -354,7 +355,7 @@ func createToken(ctx context.Context, c *cli.Command) error {
354355
}
355356

356357
fmt.Println("Token grants:")
357-
PrintJSON(grant)
358+
util.PrintJSON(grant)
358359
fmt.Println()
359360
fmt.Println("Access token:", token)
360361
return nil

0 commit comments

Comments
 (0)