From 3baa1c2e65817e6843102cf45d0bb16df8fec88f Mon Sep 17 00:00:00 2001 From: Mats Linander Date: Thu, 21 Sep 2023 10:22:37 -0400 Subject: [PATCH] sub-cmd for private apps, add private list cmd (#908) --- cmd/{ => config}/config.go | 34 +++---- cmd/create.go | 98 +------------------- cmd/delete.go | 3 +- cmd/devices.go | 3 +- cmd/list.go | 3 +- cmd/login.go | 10 ++- cmd/{ => private}/bundle.go | 4 +- cmd/private/create.go | 175 ++++++++++++++++++++++++++++++++++++ cmd/{ => private}/deploy.go | 17 ++-- cmd/private/list.go | 87 ++++++++++++++++++ cmd/private/private.go | 20 +++++ cmd/{ => private}/upload.go | 8 +- cmd/push.go | 3 +- cmd/setauth.go | 5 +- main.go | 3 - main_nonjs.go | 2 + 16 files changed, 332 insertions(+), 143 deletions(-) rename cmd/{ => config}/config.go (57%) rename cmd/{ => private}/bundle.go (95%) create mode 100644 cmd/private/create.go rename cmd/{ => private}/deploy.go (78%) create mode 100644 cmd/private/list.go create mode 100644 cmd/private/private.go rename cmd/{ => private}/upload.go (95%) diff --git a/cmd/config.go b/cmd/config/config.go similarity index 57% rename from cmd/config.go rename to cmd/config/config.go index 32bd35599c..ca3df9a097 100644 --- a/cmd/config.go +++ b/cmd/config/config.go @@ -1,4 +1,4 @@ -package cmd +package config import ( "context" @@ -11,20 +11,20 @@ import ( ) const ( - oauthCallbackAddr = "localhost:8085" + OAuthCallbackAddr = "localhost:8085" ) var ( - privateConfig = viper.New() + PrivateConfig = viper.New() - oauthConf = &oauth2.Config{ + OAuthConf = &oauth2.Config{ ClientID: "d8ae7ea0-4a1a-46b0-b556-6d742687223a", Scopes: []string{"device", "offline_access", "app-admin"}, Endpoint: oauth2.Endpoint{ AuthURL: "https://login.tidbyt.com/oauth2/auth", TokenURL: "https://login.tidbyt.com/oauth2/token", }, - RedirectURL: fmt.Sprintf("http://%s", oauthCallbackAddr), + RedirectURL: fmt.Sprintf("http://%s", OAuthCallbackAddr), } ) @@ -33,32 +33,32 @@ func init() { configPath := filepath.Join(ucd, "tidbyt") if err := os.MkdirAll(configPath, os.ModePerm); err == nil { - privateConfig.AddConfigPath(configPath) + PrivateConfig.AddConfigPath(configPath) } } - privateConfig.SetConfigName("private") - privateConfig.SetConfigType("yaml") - privateConfig.SetConfigPermissions(0600) + PrivateConfig.SetConfigName("private") + PrivateConfig.SetConfigType("yaml") + PrivateConfig.SetConfigPermissions(0600) - privateConfig.SafeWriteConfig() - privateConfig.ReadInConfig() + PrivateConfig.SafeWriteConfig() + PrivateConfig.ReadInConfig() } -func oauthTokenFromConfig(ctx context.Context) string { - if !privateConfig.IsSet("token") { +func OAuthTokenFromConfig(ctx context.Context) string { + if !PrivateConfig.IsSet("token") { return "" } var tok oauth2.Token - if err := privateConfig.UnmarshalKey("token", &tok); err != nil { + if err := PrivateConfig.UnmarshalKey("token", &tok); err != nil { fmt.Println("unmarshaling API token from config:", err) os.Exit(1) } if !tok.Valid() { // probably expired, try to refresh - ts := oauthConf.TokenSource(ctx, &tok) + ts := OAuthConf.TokenSource(ctx, &tok) refreshed, err := ts.Token() if err != nil { fmt.Println("refreshing API token:", err) @@ -66,8 +66,8 @@ func oauthTokenFromConfig(ctx context.Context) string { } tok = *refreshed - privateConfig.Set("token", tok) - privateConfig.WriteConfig() + PrivateConfig.Set("token", tok) + PrivateConfig.WriteConfig() } return tok.AccessToken diff --git a/cmd/create.go b/cmd/create.go index 26eecb7ed7..f66c9f9c61 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -3,15 +3,9 @@ package cmd import ( - "bytes" - "encoding/json" "fmt" - "io" - "net/http" "os" "path/filepath" - "strings" - "time" "github.com/spf13/cobra" "tidbyt.dev/pixlet/cmd/community" @@ -19,30 +13,11 @@ import ( "tidbyt.dev/pixlet/tools/repo" ) -var createPrivate bool -var createOrg string -var createURL string - -type TidbytCreateAppRequest struct { - OrganizationID string `json:"organizationID"` - Private bool `json:"private"` -} - -type TidbytCreateAppReply struct { - AppID string `json:"appID"` -} - -func init() { - CreateCmd.Flags().StringVarP(&createOrg, "org", "o", "", "organization to create the app in") - CreateCmd.Flags().BoolVarP(&createPrivate, "private", "p", false, "create a private app") - CreateCmd.Flags().StringVarP(&createURL, "url", "u", "https://api.tidbyt.com", "base URL of the remote bundle store") -} - // CreateCmd prompts the user for info and generates a new app. var CreateCmd = &cobra.Command{ Use: "create", Short: "Creates a new app", - Long: `This command will prompt for all of the information we need to generate a new Tidbyt app. No flags are necessary unless you are creating a private app, which is only available with our Tidbyt For Teams offering.`, + Long: `This command will prompt for all of the information we need to generate a new Tidbyt app.`, RunE: func(cmd *cobra.Command, args []string) error { // Get the current working directory. cwd, err := os.Getwd() @@ -76,23 +51,6 @@ var CreateCmd = &cobra.Command{ return fmt.Errorf("app creation, couldn't get user input: %w", err) } - if createPrivate { - // create a private app - apiToken := oauthTokenFromConfig(cmd.Context()) - if apiToken == "" { - return fmt.Errorf("login with `pixlet login` or use `pixlet set-auth` to configure auth") - } - - app.ID, err = createPrivateApp(apiToken, createOrg) - if err != nil { - if strings.Contains(err.Error(), "user is not authorized to create apps") { - return fmt.Errorf("user is not authorized to create apps for organization %s, please reach out to your Tidbyt For Teams account representative to enable this feature for your account", createOrg) - } - - return fmt.Errorf("remote app creation failed: %w", err) - } - } - // Generate app. g, err := generator.NewGenerator(appType, root) if err != nil { @@ -120,60 +78,6 @@ var CreateCmd = &cobra.Command{ fmt.Println("") fmt.Println("For docs, head to:") fmt.Printf("\thttps://tidbyt.dev\n") - - if createPrivate { - fmt.Println("") - fmt.Println("To deploy your app:") - fmt.Printf("\tpixlet bundle ./\n") - fmt.Printf("\tpixlet upload bundle.tar.gz --app %s --version v0.0.1\n", app.ID) - fmt.Printf("\tpixlet deploy --app %s --version v0.0.1\n", app.ID) - } return nil }, } - -// Creates private app for organization. If org is blank, attempts to -// create a per-user private app. -func createPrivateApp(apiToken string, org string) (string, error) { - createAppRequest := &TidbytCreateAppRequest{ - OrganizationID: org, - Private: org == "", - } - - b, err := json.Marshal(createAppRequest) - if err != nil { - return "", fmt.Errorf("could not create http request: %w", err) - } - - requestURL := fmt.Sprintf("%s/v0/apps", createURL) - req, err := http.NewRequest(http.MethodPost, requestURL, bytes.NewBuffer(b)) - if err != nil { - return "", fmt.Errorf("could not create http request: %w", err) - } - - req.Header.Set("Content-Type", "application/json") - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", apiToken)) - - client := http.Client{ - Timeout: 30 * time.Second, - } - - resp, err := client.Do(req) - if err != nil { - return "", fmt.Errorf("could not make HTTP request to %s: %w", requestURL, err) - } - defer resp.Body.Close() - - if resp.StatusCode != 200 { - body, _ := io.ReadAll(resp.Body) - return "", fmt.Errorf("request returned status %d with message: %s", resp.StatusCode, body) - } - - createAppReply := &TidbytCreateAppReply{} - err = json.NewDecoder(resp.Body).Decode(&createAppReply) - if err != nil { - return "", fmt.Errorf("could not decode response: %w", err) - } - - return createAppReply.AppID, nil -} diff --git a/cmd/delete.go b/cmd/delete.go index 272db4330c..2ba96c1e5e 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -7,6 +7,7 @@ import ( "os" "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/config" ) const ( @@ -33,7 +34,7 @@ func delete(cmd *cobra.Command, args []string) error { } if apiToken == "" { - apiToken = oauthTokenFromConfig(cmd.Context()) + apiToken = config.OAuthTokenFromConfig(cmd.Context()) } if apiToken == "" { diff --git a/cmd/devices.go b/cmd/devices.go index 38755df264..772e46225a 100644 --- a/cmd/devices.go +++ b/cmd/devices.go @@ -8,6 +8,7 @@ import ( "os" "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/config" ) const ( @@ -21,7 +22,7 @@ var DevicesCmd = &cobra.Command{ } func devices(cmd *cobra.Command, args []string) { - apiToken = oauthTokenFromConfig(cmd.Context()) + apiToken = config.OAuthTokenFromConfig(cmd.Context()) if apiToken == "" { fmt.Println("login with `pixlet login`") os.Exit(1) diff --git a/cmd/list.go b/cmd/list.go index 6ff9f4ad65..ab2bf82188 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -9,6 +9,7 @@ import ( "text/tabwriter" "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/config" ) const ( @@ -43,7 +44,7 @@ func listInstallations(cmd *cobra.Command, args []string) error { } if apiToken == "" { - apiToken = oauthTokenFromConfig(cmd.Context()) + apiToken = config.OAuthTokenFromConfig(cmd.Context()) } if apiToken == "" { diff --git a/cmd/login.go b/cmd/login.go index 400f42c303..6629221f7e 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -12,6 +12,8 @@ import ( "os" "time" + "tidbyt.dev/pixlet/cmd/config" + cowsay "github.com/Code-Hex/Neo-cowsay/v2" "github.com/Code-Hex/Neo-cowsay/v2/decoration" cv "github.com/nirasan/go-oauth-pkce-code-verifier" @@ -35,7 +37,7 @@ var LoginCmd = &cobra.Command{ func login(cmd *cobra.Command, args []string) { server := &http.Server{ - Addr: oauthCallbackAddr, + Addr: config.OAuthCallbackAddr, } var authCode, authState string @@ -84,7 +86,7 @@ func login(cmd *cobra.Command, args []string) { tok, err := authhandler.TokenSourceWithPKCE( context.Background(), - oauthConf, + config.OAuthConf, state, handler, pkce, @@ -94,9 +96,9 @@ func login(cmd *cobra.Command, args []string) { os.Exit(1) } - privateConfig.Set("token", tok) + config.PrivateConfig.Set("token", tok) - if err := privateConfig.WriteConfig(); err != nil { + if err := config.PrivateConfig.WriteConfig(); err != nil { fmt.Println("persisting token:", err) os.Exit(1) } diff --git a/cmd/bundle.go b/cmd/private/bundle.go similarity index 95% rename from cmd/bundle.go rename to cmd/private/bundle.go index 6f26752f75..7bdc1c6338 100644 --- a/cmd/bundle.go +++ b/cmd/private/bundle.go @@ -1,4 +1,4 @@ -package cmd +package private import ( "fmt" @@ -17,7 +17,7 @@ func init() { var BundleCmd = &cobra.Command{ Use: "bundle", Short: "Creates a new app bundle", - Example: ` pixlet bundle apps/fuzzyclock/`, + Example: ` pixlet bundle ./my-app`, Long: `This command will create a new app bundle from an app directory. The directory should contain an app manifest and source file. The output of this command will be a gzip compressed tar file that can be uploaded to Tidbyt for deployment.`, diff --git a/cmd/private/create.go b/cmd/private/create.go new file mode 100644 index 0000000000..94d4847f1c --- /dev/null +++ b/cmd/private/create.go @@ -0,0 +1,175 @@ +//go:build !js && !wasm + +package private + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "path/filepath" + "strings" + "time" + + "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/community" + "tidbyt.dev/pixlet/cmd/config" + "tidbyt.dev/pixlet/tools/generator" + "tidbyt.dev/pixlet/tools/repo" +) + +var createOrg string +var createURL string + +type TidbytCreateAppRequest struct { + OrganizationID string `json:"organizationID"` + Private bool `json:"private"` +} + +type TidbytCreateAppReply struct { + AppID string `json:"appID"` +} + +func init() { + CreateCmd.Flags().StringVarP(&createOrg, "org", "o", "", "organization to create the app in") + CreateCmd.Flags().StringVarP(&createURL, "url", "u", "https://api.tidbyt.com", "base URL of Tidbyt API") +} + +// CreateCmd prompts the user for info and generates a new app. +var CreateCmd = &cobra.Command{ + Use: "create", + Short: "Creates a new app", + Long: `This command will prompt for all of the information we need to generate a new Tidbyt app. No flags are necessary unless you are creating a private app, which is only available with our Tidbyt For Teams offering.`, + RunE: func(cmd *cobra.Command, args []string) error { + // Get the current working directory. + cwd, err := os.Getwd() + if err != nil { + return fmt.Errorf("app creation failed, something went wrong with your local filesystem: %w", err) + } + + // Determine what type of app this is an what the root should be. + var root string + var appType generator.AppType + if repo.IsInRepo(cwd, "community") { + appType = generator.Community + root, err = repo.RepoRoot(cwd) + if err != nil { + return fmt.Errorf("app creation failed, something went wrong with your community repo: %w", err) + } + } else if repo.IsInRepo(cwd, "tidbyt") { + appType = generator.Internal + root, err = repo.RepoRoot(cwd) + if err != nil { + return fmt.Errorf("app creation failed, something went wrong with your tidbyt repo: %w", err) + } + } else { + appType = generator.Local + root = cwd + } + + // Prompt the user for input. + app, err := community.ManifestPrompt() + if err != nil { + return fmt.Errorf("app creation, couldn't get user input: %w", err) + } + + // create a private app + apiToken := config.OAuthTokenFromConfig(cmd.Context()) + if apiToken == "" { + return fmt.Errorf("login with `pixlet login` or use `pixlet set-auth` to configure auth") + } + + app.ID, err = createPrivateApp(apiToken, createOrg) + if err != nil { + if strings.Contains(err.Error(), "user is not authorized to create apps") { + return fmt.Errorf("user is not authorized to create apps for organization %s, please reach out to your Tidbyt For Teams account representative to enable this feature for your account", createOrg) + } + + return fmt.Errorf("remote app creation failed: %w", err) + } + + // Generate app. + g, err := generator.NewGenerator(appType, root) + if err != nil { + return fmt.Errorf("app creation failed %w", err) + } + absolutePath, err := g.GenerateApp(app) + if err != nil { + return fmt.Errorf("app creation failed: %w", err) + } + + // Get the relative path from where the user started. Note, we're not + // using the root here, given the root can be git repo specific. + relativePath, err := filepath.Rel(cwd, absolutePath) + if err != nil { + return fmt.Errorf("app was created, but we don't know where: %w", err) + } + + // Let the user know where the app is and how to use it. + fmt.Println("") + fmt.Println("App created at:") + fmt.Printf("\t%s\n", absolutePath) + fmt.Println("") + fmt.Println("To start the app, run:") + fmt.Printf("\tpixlet serve %s\n", relativePath) + fmt.Println("") + fmt.Println("For docs, head to:") + fmt.Printf("\thttps://tidbyt.dev\n") + + fmt.Println("") + fmt.Println("To deploy your app:") + fmt.Printf("\tpixlet bundle ./\n") + fmt.Printf("\tpixlet upload bundle.tar.gz --app %s --version v0.0.1\n", app.ID) + fmt.Printf("\tpixlet deploy --app %s --version v0.0.1\n", app.ID) + + return nil + }, +} + +// Creates private app for organization. If org is blank, attempts to +// create a per-user private app. +func createPrivateApp(apiToken string, org string) (string, error) { + createAppRequest := &TidbytCreateAppRequest{ + OrganizationID: org, + Private: org == "", + } + + b, err := json.Marshal(createAppRequest) + if err != nil { + return "", fmt.Errorf("could not create http request: %w", err) + } + + requestURL := fmt.Sprintf("%s/v0/apps", createURL) + req, err := http.NewRequest(http.MethodPost, requestURL, bytes.NewBuffer(b)) + if err != nil { + return "", fmt.Errorf("could not create http request: %w", err) + } + + req.Header.Set("Content-Type", "application/json") + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", apiToken)) + + client := http.Client{ + Timeout: 30 * time.Second, + } + + resp, err := client.Do(req) + if err != nil { + return "", fmt.Errorf("could not make HTTP request to %s: %w", requestURL, err) + } + defer resp.Body.Close() + + if resp.StatusCode != 200 { + body, _ := io.ReadAll(resp.Body) + return "", fmt.Errorf("request returned status %d with message: %s", resp.StatusCode, body) + } + + createAppReply := &TidbytCreateAppReply{} + err = json.NewDecoder(resp.Body).Decode(&createAppReply) + if err != nil { + return "", fmt.Errorf("could not decode response: %w", err) + } + + return createAppReply.AppID, nil +} diff --git a/cmd/deploy.go b/cmd/private/deploy.go similarity index 78% rename from cmd/deploy.go rename to cmd/private/deploy.go index 10f17efc95..801a101be3 100644 --- a/cmd/deploy.go +++ b/cmd/private/deploy.go @@ -1,4 +1,4 @@ -package cmd +package private import ( "bytes" @@ -9,6 +9,7 @@ import ( "time" "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/config" ) var deployVersion string @@ -25,20 +26,16 @@ func init() { DeployCmd.MarkFlagRequired("app") DeployCmd.Flags().StringVarP(&deployVersion, "version", "v", "", "version of the bundle to deploy") DeployCmd.MarkFlagRequired("version") - - DeployCmd.Flags().StringVarP(&deployURL, "url", "u", "https://api.tidbyt.com", "base URL of the remote bundle store") + DeployCmd.Flags().StringVarP(&deployURL, "url", "u", "https://api.tidbyt.com", "base URL of Tidbyt API") } var DeployCmd = &cobra.Command{ Use: "deploy", - Short: "Deploys an app to production (internal only)", - Example: ` pixlet deploy --app fuzzy-clock --version v0.0.1`, - Long: `This command will deploy an app to production in the Tidbyt backend. Note, this -command is for internal use only at the moment, and normal API tokens will not -be able to deploy apps. We fully intend to make this command generally available -once our backend can support public deploys.`, + Short: "Deploys a private app version", + Example: ` pixlet deploy --app --version v0.0.1`, + Long: `This command will deploy a private app to the Tidbyt backend.`, RunE: func(cmd *cobra.Command, args []string) error { - apiToken := oauthTokenFromConfig(cmd.Context()) + apiToken := config.OAuthTokenFromConfig(cmd.Context()) if apiToken == "" { return fmt.Errorf("login with `pixlet login` or use `pixlet set-auth` to configure auth") } diff --git a/cmd/private/list.go b/cmd/private/list.go new file mode 100644 index 0000000000..d6e93e399c --- /dev/null +++ b/cmd/private/list.go @@ -0,0 +1,87 @@ +package private + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + "time" + + "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/config" +) + +type TidbytApp struct { + ID string `json:"id"` + Name string `json:"name,omitempty"` + Version string `json:"version,omitempty"` + Private bool `json:"private,omitempty"` + OrganizationID string `json:"organizationID,omitempty"` +} + +var listURL string + +func init() { + ListCmd.Flags().StringVarP(&listURL, "url", "u", "https://api.tidbyt.com", "base URL of Tidbyt API") +} + +var ListCmd = &cobra.Command{ + Use: "list", + Short: "Lists private apps", + Long: `Lists private apps, including team apps.`, + RunE: func(cmd *cobra.Command, args []string) error { + apiToken := config.OAuthTokenFromConfig(cmd.Context()) + if apiToken == "" { + return fmt.Errorf("login with `pixlet login` or use `pixlet set-auth` to configure auth") + } + + requestURL := fmt.Sprintf("%s/v0/apps", listURL) + req, err := http.NewRequest("GET", requestURL, nil) + if err != nil { + return fmt.Errorf("could not create http request: %w", err) + } + + req.Header.Set("Content-Type", "application/json") + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", apiToken)) + + client := http.Client{ + Timeout: 10 * time.Second, + } + + resp, err := client.Do(req) + if err != nil { + return fmt.Errorf("could not make HTTP request to %s: %w", requestURL, err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if resp.StatusCode != 200 { + return fmt.Errorf("request returned status %d with message: %s", resp.StatusCode, body) + } + + if err != nil { + return fmt.Errorf("could not read response body: %w", err) + } + + var apps struct { + Apps []TidbytApp `json:"apps"` + } + err = json.Unmarshal(body, &apps) + if err != nil { + return fmt.Errorf("could not parse response body: %w", err) + } + + for _, app := range apps.Apps { + if !app.Private { + continue + } + appJson, err := json.Marshal(app) + if err != nil { + return fmt.Errorf("could not marshal app: %w", err) + } + fmt.Println(string(appJson)) + } + + return nil + }, +} diff --git a/cmd/private/private.go b/cmd/private/private.go new file mode 100644 index 0000000000..84e55aafdf --- /dev/null +++ b/cmd/private/private.go @@ -0,0 +1,20 @@ +package private + +import ( + "github.com/spf13/cobra" +) + +func init() { + PrivateCmd.AddCommand(CreateCmd) + PrivateCmd.AddCommand(BundleCmd) + PrivateCmd.AddCommand(UploadCmd) + PrivateCmd.AddCommand(DeployCmd) + PrivateCmd.AddCommand(ListCmd) +} + +var PrivateCmd = &cobra.Command{ + Use: "private", + Short: "Utilities to manage private apps", + Long: `The private subcommand provides a set of utilities for managing +private apps. Requires Tidbyt Plus or Tidbyt for Teams.`, +} diff --git a/cmd/upload.go b/cmd/private/upload.go similarity index 95% rename from cmd/upload.go rename to cmd/private/upload.go index dc2b1978eb..00e2825f08 100644 --- a/cmd/upload.go +++ b/cmd/private/upload.go @@ -1,4 +1,4 @@ -package cmd +package private import ( "bytes" @@ -13,6 +13,7 @@ import ( "github.com/spf13/cobra" "tidbyt.dev/pixlet/bundle" + "tidbyt.dev/pixlet/cmd/config" ) var uploadVersion string @@ -30,8 +31,7 @@ func init() { UploadCmd.MarkFlagRequired("app") UploadCmd.Flags().StringVarP(&uploadVersion, "version", "v", "", "version of the bundle to upload") UploadCmd.MarkFlagRequired("version") - - UploadCmd.Flags().StringVarP(&uploadURL, "url", "u", "https://api.tidbyt.com", "base URL of the remote bundle store") + UploadCmd.Flags().StringVarP(&uploadURL, "url", "u", "https://api.tidbyt.com", "base URL of Tidbyt API") } var UploadCmd = &cobra.Command{ @@ -58,7 +58,7 @@ command public once our backend is well positioned to support it.`, return fmt.Errorf("input bundle format is not correct, did you create it with `pixlet bundle`?") } - apiToken := oauthTokenFromConfig(cmd.Context()) + apiToken := config.OAuthTokenFromConfig(cmd.Context()) if apiToken == "" { return fmt.Errorf("login with `pixlet login` or use `pixlet set-auth` to configure auth") } diff --git a/cmd/push.go b/cmd/push.go index 65919a63ab..50ca5fe9d3 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -10,6 +10,7 @@ import ( "os" "github.com/spf13/cobra" + "tidbyt.dev/pixlet/cmd/config" ) const ( @@ -59,7 +60,7 @@ func push(cmd *cobra.Command, args []string) error { } if apiToken == "" { - apiToken = oauthTokenFromConfig(cmd.Context()) + apiToken = config.OAuthTokenFromConfig(cmd.Context()) } if apiToken == "" { diff --git a/cmd/setauth.go b/cmd/setauth.go index b2ecdedcaa..92343f2fb5 100644 --- a/cmd/setauth.go +++ b/cmd/setauth.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "golang.org/x/oauth2" + "tidbyt.dev/pixlet/cmd/config" ) var SetAuthCmd = &cobra.Command{ @@ -26,8 +27,8 @@ func SetAuth(cmd *cobra.Command, args []string) error { return fmt.Errorf("could not load auth JSON: %w", err) } - privateConfig.Set("token", tok) - if err := privateConfig.WriteConfig(); err != nil { + config.PrivateConfig.Set("token", tok) + if err := config.PrivateConfig.WriteConfig(); err != nil { return fmt.Errorf("could not persist auth token in config: %w", err) } diff --git a/main.go b/main.go index 620174151d..f2f64cfbc0 100644 --- a/main.go +++ b/main.go @@ -31,9 +31,6 @@ func init() { rootCmd.AddCommand(cmd.FormatCmd) rootCmd.AddCommand(cmd.LintCmd) rootCmd.AddCommand(cmd.CheckCmd) - rootCmd.AddCommand(cmd.BundleCmd) - rootCmd.AddCommand(cmd.UploadCmd) - rootCmd.AddCommand(cmd.DeployCmd) rootCmd.AddCommand(cmd.SetAuthCmd) rootCmd.AddCommand(community.CommunityCmd) } diff --git a/main_nonjs.go b/main_nonjs.go index ea77956e3e..2f82271f3a 100644 --- a/main_nonjs.go +++ b/main_nonjs.go @@ -4,8 +4,10 @@ package main import ( "tidbyt.dev/pixlet/cmd" + "tidbyt.dev/pixlet/cmd/private" ) func init() { + rootCmd.AddCommand(private.PrivateCmd) rootCmd.AddCommand(cmd.CreateCmd) }