Skip to content
Open
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
18 changes: 16 additions & 2 deletions cmd/lk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ var (
Before: initAuth,
Action: handleAuth,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "Project `ID` to authenticate. If not provided, you can choose from your existing projects in the browser",
Required: false,
},
&cli.BoolFlag{
Name: "revoke",
Aliases: []string{"R"},
Expand Down Expand Up @@ -271,6 +276,7 @@ func tryAuthIfNeeded(ctx context.Context, cmd *cli.Command) error {
// get devicename
if err := huh.NewInput().
Title("What is the name of this device?").
Description("A short name you can use to find and manage generated API keys on the LiveKit Cloud dashboard").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Value(&cliConfig.DeviceName).
WithTheme(util.Theme).
Run(); err != nil {
Expand All @@ -290,7 +296,11 @@ func tryAuthIfNeeded(ctx context.Context, cmd *cli.Command) error {
return err
}

authURL, err := generateConfirmURL(token.Token)
projectId := cmd.String("id")
if projectId == "" && cmd.Args().Present() {
projectId = cmd.Args().First()
}
authURL, err := generateConfirmURL(token.Token, projectId)
if err != nil {
return err
}
Expand Down Expand Up @@ -352,6 +362,7 @@ func tryAuthIfNeeded(ctx context.Context, cmd *cli.Command) error {
// persist to config file
cliConfig.Projects = append(cliConfig.Projects, config.ProjectConfig{
Name: name,
ProjectId: ak.ProjectId,
APIKey: ak.Key,
APISecret: ak.Secret,
URL: ak.URL,
Expand All @@ -367,14 +378,17 @@ func tryAuthIfNeeded(ctx context.Context, cmd *cli.Command) error {
return err
}

func generateConfirmURL(token string) (*url.URL, error) {
func generateConfirmURL(token, projectId string) (*url.URL, error) {
base, err := url.Parse(dashboardURL + confirmAuthEndpoint)
if err != nil {
return nil, err
}

params := url.Values{}
params.Add("t", token)
if projectId != "" {
params.Add("project_id", projectId)
}
base.RawQuery = params.Encode()
return base, nil
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/lk/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,19 @@ func listProjects(ctx context.Context, cmd *cli.Command) error {
return baseStyle
}
}).
Headers("Name", "URL", "API Key")
Headers("Name", "ID", "URL", "API Key")
for _, p := range cliConfig.Projects {
var pName string
if p.Name == cliConfig.DefaultProject {
pName = "* " + p.Name
} else {
pName = " " + p.Name
}
table.Row(pName, p.URL, p.APIKey)
pID := p.ProjectId
if pID == "" {
pID = "-"
}
table.Row(pName, pID, p.URL, p.APIKey)
}
fmt.Println(table)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type CLIConfig struct {

type ProjectConfig struct {
Name string `yaml:"name"`
ProjectId string `yaml:"id"`
URL string `yaml:"url"`
APIKey string `yaml:"api_key"`
APISecret string `yaml:"api_secret"`
Expand Down
Loading