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

fix(cmd): relocate temp files across filesystem boundaries #490

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
7 changes: 4 additions & 3 deletions cmd/lk/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/livekit/livekit-cli/pkg/bootstrap"
"github.com/livekit/livekit-cli/pkg/config"
"github.com/livekit/livekit-cli/pkg/util"
"github.com/urfave/cli/v3"
)

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

if cmd.Bool("json") {
PrintJSON(templates)
util.PrintJSON(templates)
} else {
const maxDescLength = 64
table := CreateTable().Headers("Template", "Description").BorderRow(true)
for _, t := range templates {
desc := strings.Join(wrapToLines(t.Desc, maxDescLength), "\n")
desc := strings.Join(util.WrapToLines(t.Desc, maxDescLength), "\n")
url := theme.Focused.Title.Render(t.URL)
tags := theme.Help.ShortDesc.Render("#" + strings.Join(t.Tags, " #"))
table.Row(
Expand Down Expand Up @@ -355,7 +356,7 @@ func cloneTemplate(_ context.Context, cmd *cli.Command, url, appName string) err
var stderr string
var cmdErr error

tempName, relocate, cleanup := useTempPath(appName)
tempName, relocate, cleanup := util.UseTempPath(appName)
defer cleanup()

if err := spinner.New().
Expand Down
5 changes: 3 additions & 2 deletions cmd/lk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

authutil "github.com/livekit/livekit-cli/pkg/auth"
"github.com/livekit/livekit-cli/pkg/config"
"github.com/livekit/livekit-cli/pkg/util"
"github.com/livekit/protocol/auth"
)

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

// make sure name is unique
name, err := URLSafeName(ak.URL)
name, err := util.URLSafeName(ak.URL)
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/lk/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/urfave/cli/v3"

"github.com/livekit/livekit-cli/pkg/util"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/utils"
lksdk "github.com/livekit/server-sdk-go/v2"
Expand Down Expand Up @@ -118,14 +119,14 @@ func listDispatchAndPrint(cmd *cli.Command, req *livekit.ListAgentDispatchReques
return cli.ShowSubcommandHelp(cmd)
}
if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}
res, err := dispatchClient.ListDispatch(context.Background(), req)
if err != nil {
return err
}
if cmd.Bool("json") {
PrintJSON(res)
util.PrintJSON(res)
} else {
table := CreateTable().
Headers("DispatchID", "Room", "AgentName", "Metadata")
Expand Down Expand Up @@ -164,7 +165,7 @@ func createAgentDispatch(ctx context.Context, cmd *cli.Command) error {
return errors.New("agent-name is required")
}
if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}

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

if cmd.Bool("json") {
PrintJSON(info)
util.PrintJSON(info)
} else {
fmt.Printf("Dispatch created: %v\n", info)
}
Expand Down Expand Up @@ -204,7 +205,7 @@ func deleteAgentDispatch(ctx context.Context, cmd *cli.Command) error {
}

if cmd.Bool("json") {
PrintJSON(info)
util.PrintJSON(info)
} else {
fmt.Printf("Dispatch deleted: %v\n", info)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/lk/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
lksdk "github.com/livekit/server-sdk-go/v2"

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

type egressType string
Expand Down Expand Up @@ -403,7 +404,7 @@ func handleEgressStart(ctx context.Context, cmd *cli.Command) error {
case string(EgressTypeTrackComposite):
return startTrackCompositeEgress(ctx, cmd)
default:
return errors.New("unrecognized egress type " + wrapWith("\"")(cmd.String("type")))
return errors.New("unrecognized egress type " + util.WrapWith("\"")(cmd.String("type")))
}
}

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

if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}
return nil
}
Expand Down Expand Up @@ -597,7 +598,7 @@ func listEgress(ctx context.Context, cmd *cli.Command) error {
}

if cmd.Bool("json") {
PrintJSON(items)
util.PrintJSON(items)
} else {
table := CreateTable().
Headers("EgressID", "Status", "Type", "Source", "Started At", "Error")
Expand Down
7 changes: 4 additions & 3 deletions cmd/lk/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/urfave/cli/v3"

"github.com/livekit/livekit-cli/pkg/util"
"github.com/livekit/protocol/livekit"
lksdk "github.com/livekit/server-sdk-go/v2"
)
Expand Down Expand Up @@ -177,7 +178,7 @@ func createIngress(ctx context.Context, cmd *cli.Command) error {
}

if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}

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

if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}

info, err := ingressClient.UpdateIngress(context.Background(), req)
Expand All @@ -221,7 +222,7 @@ func listIngress(ctx context.Context, cmd *cli.Command) error {
// This is inconsistent with other commands in which verbose is used for debug info, but is
// kept for compatibility with the previous behavior.
if cmd.Bool("verbose") || cmd.Bool("json") {
PrintJSON(res)
util.PrintJSON(res)
} else {
table := CreateTable().
Headers("IngressID", "Name", "Room", "StreamKey", "URL", "Status", "Error")
Expand Down
3 changes: 2 additions & 1 deletion cmd/lk/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/urfave/cli/v3"

"github.com/livekit/livekit-cli/pkg/config"
"github.com/livekit/livekit-cli/pkg/util"
)

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

if cmd.Bool("json") {
PrintJSON(cliConfig.Projects)
util.PrintJSON(cliConfig.Projects)
} else {
table := CreateTable().
StyleFunc(func(row, col int) lipgloss.Style {
Expand Down
7 changes: 4 additions & 3 deletions cmd/lk/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"reflect"

"github.com/livekit/livekit-cli/pkg/util"
"github.com/urfave/cli/v3"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -108,7 +109,7 @@ func createAndPrint[T any, P protoTypeValidator[T], R any](
return fmt.Errorf("could not read request: %w", err)
}
if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}
if err = req.Validate(); err != nil {
return err
Expand All @@ -132,7 +133,7 @@ func createAndPrintLegacy[T any, P protoType[T], R any](
return err
}
if cmd.Bool("verbose") {
PrintJSON(req)
util.PrintJSON(req)
}
info, err := create(ctx, req)
if err != nil {
Expand Down Expand Up @@ -192,7 +193,7 @@ func listAndPrint[
}

if cmd.Bool("json") {
PrintJSON(res)
util.PrintJSON(res)
} else {
table := CreateTable().
Headers(header...)
Expand Down
3 changes: 2 additions & 1 deletion cmd/lk/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/urfave/cli/v3"

authutil "github.com/livekit/livekit-cli/pkg/auth"
"github.com/livekit/livekit-cli/pkg/util"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/replay"
lksdk "github.com/livekit/server-sdk-go/v2"
Expand Down Expand Up @@ -127,7 +128,7 @@ func listReplays(ctx context.Context, cmd *cli.Command) error {
}

if cmd.Bool("json") {
PrintJSON(res.Replays)
util.PrintJSON(res.Replays)
} else {
table := CreateTable().Headers("ReplayID")
for _, info := range res.Replays {
Expand Down
17 changes: 9 additions & 8 deletions cmd/lk/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/urfave/cli/v3"
"google.golang.org/protobuf/encoding/protojson"

"github.com/livekit/livekit-cli/pkg/util"
"github.com/livekit/protocol/logger"

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

PrintJSON(room)
util.PrintJSON(room)
return nil
}

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

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

if cmd.Bool("json") {
PrintJSON(res)
util.PrintJSON(res)
} else {
table := CreateTable().Headers("RoomID", "Name", "Participants", "Publishers")
for _, rm := range res.Rooms {
Expand Down Expand Up @@ -688,7 +689,7 @@ func _deprecatedListRoom(ctx context.Context, cmd *cli.Command) error {
return nil
}
rm := res.Rooms[0]
PrintJSON(rm)
util.PrintJSON(rm)
return nil
}

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

fmt.Println("Updated room metadata")
PrintJSON(res)
util.PrintJSON(res)
return nil
}

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

fmt.Println("Updated room metadata")
PrintJSON(res)
util.PrintJSON(res)
return nil
}

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

PrintJSON(res)
util.PrintJSON(res)

return nil
}
Expand Down Expand Up @@ -971,7 +972,7 @@ func updateParticipant(ctx context.Context, cmd *cli.Command) error {
}

fmt.Println("updating participant...")
PrintJSON(req)
util.PrintJSON(req)
if _, err := roomClient.UpdateParticipant(ctx, req); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/lk/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/charmbracelet/huh"
"github.com/urfave/cli/v3"

"github.com/livekit/livekit-cli/pkg/util"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
)
Expand Down Expand Up @@ -354,7 +355,7 @@ func createToken(ctx context.Context, c *cli.Command) error {
}

fmt.Println("Token grants:")
PrintJSON(grant)
util.PrintJSON(grant)
fmt.Println()
fmt.Println("Access token:", token)
return nil
Expand Down
Loading
Loading