Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into enjamin/deprecate_cre…
Browse files Browse the repository at this point in the history
…ate_trunk
  • Loading branch information
biglittlebigben committed Oct 21, 2024
2 parents f7f6919 + 4ef948e commit 769e802
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
24 changes: 17 additions & 7 deletions cmd/lk/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,32 @@ func setupTemplate(ctx context.Context, cmd *cli.Command) error {
}

func cloneTemplate(_ context.Context, cmd *cli.Command, url, appName string) error {
var out []byte
var cmdErr error

tempName, relocate, cleanup := useTempPath(appName)
defer cleanup()

if err := spinner.New().
Title("Cloning template from " + url).
Action(func() {
c := exec.Command("git", "clone", "--depth=1", url, appName)
var out []byte
if out, cmdErr = c.CombinedOutput(); len(out) > 0 && cmd.Bool("verbose") {
fmt.Println(string(out))
}
os.RemoveAll(path.Join(appName, ".git"))
c := exec.Command("git", "clone", "--depth=1", url, tempName)
out, cmdErr = c.CombinedOutput()
os.RemoveAll(path.Join(tempName, ".git"))
}).
Style(theme.Focused.Title).
Run(); err != nil {
return err
}
return cmdErr

if len(out) > 0 && (cmdErr != nil || cmd.Bool("verbose")) {
fmt.Println(string(out))
}

if cmdErr != nil {
return cmdErr
}
return relocate()
}

func instantiateEnv(ctx context.Context, cmd *cli.Command, rootPath string, addlEnv *map[string]string) error {
Expand Down
15 changes: 0 additions & 15 deletions cmd/lk/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,6 @@ var (
},

// Deprecated commands kept for compatibility
{
Hidden: true, // deprecated: use `sip trunk create`
Name: "create-sip-trunk",
Usage: "Create a SIP Trunk",
Action: createSIPTrunkLegacy,
Category: sipCategory,
Flags: []cli.Flag{
//lint:ignore SA1019 we still support it
RequestFlag[livekit.CreateSIPTrunkRequest](),
},
},
{
Hidden: true, // deprecated: use `sip trunk list`
Name: "list-sip-trunk",
Expand Down Expand Up @@ -236,10 +225,6 @@ func createSIPClient(cmd *cli.Command) (*lksdk.SIPClient, error) {
return lksdk.NewSIPClient(pc.URL, pc.APIKey, pc.APISecret, withDefaultClientOpts(pc)...), nil
}

func createSIPTrunkLegacy(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("create-sip-trunk is deprecated and not supported anymore. Use 'sip in create' or 'sip out create' instead.")
}

func createSIPInboundTrunk(ctx context.Context, cmd *cli.Command) error {
cli, err := createSIPClient(cmd)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions cmd/lk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net/url"
"os"
"path"
"path/filepath"
"strings"

Expand All @@ -30,6 +31,7 @@ import (
"github.com/twitchtv/twirp"
"github.com/urfave/cli/v3"

"github.com/livekit/protocol/utils/guid"
"github.com/livekit/protocol/utils/interceptors"

"github.com/livekit/livekit-cli/pkg/config"
Expand Down Expand Up @@ -153,6 +155,20 @@ func wrapWith(wrap string) func(string) string {
}
}

// Provides a temporary path, a function to relocate it to a permanent path,
// and a function to clean up the temporary path that should always be deferred
// in the case of a failure to relocate.
func useTempPath(permanentPath string) (string, func() error, func() error) {
tempPath := path.Join(os.TempDir(), guid.New("LK_"))
relocate := func() error {
return os.Rename(tempPath, permanentPath)
}
cleanup := func() error {
return os.RemoveAll(tempPath)
}
return tempPath, relocate, cleanup
}

func hashString(str string) (string, error) {
hash := sha256.New()
if _, err := hash.Write([]byte(str)); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/livekit/livekit-cli

go 1.22.7

toolchain go1.23.1
toolchain go1.23.2

replace github.com/livekit/protocol => ../protocol

Expand All @@ -14,8 +14,8 @@ require (
github.com/go-logr/logr v1.4.2
github.com/go-task/task/v3 v3.39.2
github.com/joho/godotenv v1.5.1
github.com/livekit/protocol v1.24.0
github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241015094126-b8538ae5d67b
github.com/livekit/protocol v1.26.0
github.com/livekit/server-sdk-go/v2 v2.3.0
github.com/pion/rtcp v1.2.14
github.com/pion/rtp v1.8.9
github.com/pion/webrtc/v3 v3.3.4
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,10 @@ 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-20240730083616-559fa5ece598 h1:yLlkHk2feSLHstD9n4VKg7YEBR4rLODTI4WE8gNBEnQ=
github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598/go.mod h1:jwKUCmObuiEDH0iiuJHaGMXwRs3RjrB4G6qqgkr/5oE=
github.com/livekit/protocol v1.24.0 h1:GyRCWsqsmgGXbWGou1uv2A2xKmHJWSDXwz0yIpZQzRo=
github.com/livekit/protocol v1.24.0/go.mod h1:nxRzmQBKSYK64gqr7ABWwt78hvrgiO2wYuCojRYb7Gs=
github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9 h1:33oBjGpVD9tYkDXQU42tnHl8eCX9G6PVUToBVuCUyOs=
github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0=
github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241007155002-76007e61480f h1:7Vb/gkzVnnNdsV3K47LsWOCQpMfqM927V3XogwUM3jI=
github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241007155002-76007e61480f/go.mod h1:AERqUiaZiAZjMxB5bxZn+M8PJlDD3TAOZn0PieQjnXk=
github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241015094126-b8538ae5d67b h1:R1GpKwVbSYsG08k5sIkNCukvnrkOE18R8IO1YeujR8o=
github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241015094126-b8538ae5d67b/go.mod h1:m2IukIyPCvJCdx04mdWIud9FoCBUAWc3526x3KgT8qY=
github.com/livekit/server-sdk-go/v2 v2.3.0 h1:k6kpBwJNZYUypv9567hfmLpxQumL463dNGUBfoF0bzQ=
github.com/livekit/server-sdk-go/v2 v2.3.0/go.mod h1:m2IukIyPCvJCdx04mdWIud9FoCBUAWc3526x3KgT8qY=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
Expand Down

0 comments on commit 769e802

Please sign in to comment.