From fbd79629a9191f8d28c594e9f3d2d2f14023f058 Mon Sep 17 00:00:00 2001 From: Alec Fong Date: Tue, 24 Feb 2026 11:53:08 -0800 Subject: [PATCH] Remove non-functioning brev secret command Remove the secret command, its store types, and registration from the CLI. --- pkg/cmd/cmd.go | 2 - pkg/cmd/secret/secret.go | 204 ---------------------------------- pkg/cmd/secret/secret_test.go | 1 - pkg/store/secret.go | 69 ------------ 4 files changed, 276 deletions(-) delete mode 100644 pkg/cmd/secret/secret.go delete mode 100644 pkg/cmd/secret/secret_test.go delete mode 100644 pkg/store/secret.go diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index c6a7edfec..e5c647422 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -38,7 +38,6 @@ import ( "github.com/brevdev/brev-cli/pkg/cmd/reset" "github.com/brevdev/brev-cli/pkg/cmd/runtasks" "github.com/brevdev/brev-cli/pkg/cmd/scale" - "github.com/brevdev/brev-cli/pkg/cmd/secret" "github.com/brevdev/brev-cli/pkg/cmd/set" "github.com/brevdev/brev-cli/pkg/cmd/setupworkspace" "github.com/brevdev/brev-cli/pkg/cmd/shell" @@ -283,7 +282,6 @@ func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *stor cmd.AddCommand(ollama.NewCmdOllama(t, loginCmdStore)) cmd.AddCommand(background.NewCmdBackground(t, loginCmdStore)) cmd.AddCommand(status.NewCmdStatus(t, loginCmdStore)) - cmd.AddCommand(secret.NewCmdSecret(loginCmdStore, t)) cmd.AddCommand(sshkeys.NewCmdSSHKeys(t, loginCmdStore)) cmd.AddCommand(start.NewCmdStart(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(stop.NewCmdStop(t, loginCmdStore, noLoginCmdStore)) diff --git a/pkg/cmd/secret/secret.go b/pkg/cmd/secret/secret.go deleted file mode 100644 index bc4258950..000000000 --- a/pkg/cmd/secret/secret.go +++ /dev/null @@ -1,204 +0,0 @@ -// Package secret lets you add secrests. Language Go makes you write extra. -package secret - -import ( - "encoding/json" - "fmt" - - "github.com/brevdev/brev-cli/pkg/cmdcontext" - "github.com/brevdev/brev-cli/pkg/entity" - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - - "github.com/spf13/cobra" -) - -type SecretStore interface { - CreateSecret(req store.CreateSecretRequest) (*store.CreateSecretRequest, error) - GetCurrentUser() (*entity.User, error) - GetActiveOrganizationOrDefault() (*entity.Organization, error) -} - -func NewCmdSecret(secretStore SecretStore, t *terminal.Terminal) *cobra.Command { - var envtype string - var name string - var value string - var path string - var scope string - - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "secret", - Short: "Add a secret/environment variable", - Long: "Add a secret/environment variable to your instance, all instances in an org, or all of your instances", - Example: ` - brev secret --name my_value --value my_value --type [file, variable] --file-path --scope [org, user] - brev secret --name SERVER_URL --value https://brev.sh --type variable --scope [org, user] - brev secret --name AWS_KEY --value ... --type file --file-path --scope [org, user] - `, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - err := cmdcontext.InvokeParentPersistentPreRun(cmd, args) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - return nil - }, - // Args: cobra.MinimumNArgs(0), - // ValidArgs: []string{"orgs", "workspaces"}, - RunE: func(cmd *cobra.Command, args []string) error { - err := addSecret(secretStore, t, envtype, name, value, path, scope) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - - cmd.Flags().StringVarP(&envtype, "type", "t", "", "type of secret (env var or file)") - cmd.Flags().StringVarP(&name, "name", "n", "", "name of environment variable or secret file") - cmd.Flags().StringVarP(&value, "value", "v", "", "value of environment variable or secret file") - cmd.Flags().StringVarP(&path, "file-path", "p", "", "file path (if secret file)") - cmd.Flags().StringVarP(&scope, "scope", "s", "", "scope for env var (org or private)") - - err := cmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"file", "variable"}, cobra.ShellCompDirectiveNoSpace - }) - if err != nil { - breverrors.GetDefaultErrorReporter().ReportError(breverrors.WrapAndTrace(err)) - fmt.Print(breverrors.WrapAndTrace(err)) - } - - err = cmd.RegisterFlagCompletionFunc("scope", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"org", "private"}, cobra.ShellCompDirectiveNoSpace - }) - if err != nil { - breverrors.GetDefaultErrorReporter().ReportError(breverrors.WrapAndTrace(err)) - fmt.Print(breverrors.WrapAndTrace(err)) - } - - return cmd -} - -func addSecret(secretStore SecretStore, t *terminal.Terminal, envtype string, name string, value string, path string, scope string) error { //nolint:funlen, gocyclo // todo simplify me - if name == "" || envtype == "" || value == "" || path == "" { - t.Vprintf("%s", t.Yellow("\nSome flags omitted, running interactive mode!\n")) - } - - if name == "" { - name = terminal.PromptGetInput(terminal.PromptContent{ - Label: "Environment variable/secret name: ", - ErrorMsg: "error", - }) - } - - if envtype == "" { - envtype = terminal.PromptSelectInput(terminal.PromptSelectContent{ - Label: "Type of variable: ", - ErrorMsg: "error", - Items: []string{"file", "variable"}, - }) - } - - if value == "" { - value = terminal.PromptGetInput(terminal.PromptContent{ - Label: "Environment variable/secret value: ", - ErrorMsg: "error", - }) - } - - if path == "" && envtype == "file" { - path = terminal.PromptGetInput(terminal.PromptContent{ - Label: "Path for the file: ", - ErrorMsg: "error", - Default: "/home/brev/workspace/secret.txt", - }) - } - - if scope == "" { - scope = terminal.PromptSelectInput(terminal.PromptSelectContent{ - Label: "Scope: ", - ErrorMsg: "error", - Items: []string{"org", "user"}, - }) - } - - if envtype == "file" { - t.Vprintf("brev secret --name %s --value %s --type %s --file-path %s --scope %s\n", name, value, envtype, path, scope) - } else { - t.Vprintf("brev secret --name %s --value %s --type %s --scope %s\n", name, value, envtype, scope) - } - - s := t.NewSpinner() - s.Suffix = " encrypting and saving secret var" - s.Start() - - iScope := store.Org - var hierarchyID string - if scope == "user" { - iScope = store.User - // get user id - me, err := secretStore.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - hierarchyID = me.ID - } else { - // get org id - defaultOrg, err := secretStore.GetActiveOrganizationOrDefault() - if err != nil { - return breverrors.WrapAndTrace(err) - } - if defaultOrg == nil { - return fmt.Errorf("no orgs exist") - } - hierarchyID = defaultOrg.ID - } - - var configDest store.DestConfig - iType := store.File - if envtype == "variable" { - iType = store.EnvVariable - configDest = store.DestConfig{ - Name: name, - } - } else { - configDest = store.DestConfig{ - Path: path, - } - } - - // NOTE: hieararchyID needs to be the org ID user ID - - b := store.CreateSecretRequest{ - Name: name, - HierarchyType: iScope, - HierarchyID: hierarchyID, - Src: store.SecretReqSrc{ - Type: store.KeyValue, - Config: store.SrcConfig{ - Value: value, - }, - }, - Dest: store.SecretReqDest{ - Type: iType, - Config: configDest, - }, - } - asstring, _ := json.MarshalIndent(b, "", "\t") - fmt.Print(string(asstring)) - secret, err := secretStore.CreateSecret(b) - if err != nil { - s.Stop() - t.Vprintf("%s", t.Red(err.Error())) - return breverrors.WrapAndTrace(err) - } - t.Vprintf("%s", secret.Name) - s.Suffix = " environment secret added" - s.Stop() - - t.Vprintf("%s", t.Green("\nEnvironment %s added\n", iType)+t.Yellow("\tNote: It might take up to 2 minutes to load into your environment.")) - - return nil -} diff --git a/pkg/cmd/secret/secret_test.go b/pkg/cmd/secret/secret_test.go deleted file mode 100644 index a48db44e5..000000000 --- a/pkg/cmd/secret/secret_test.go +++ /dev/null @@ -1 +0,0 @@ -package secret diff --git a/pkg/store/secret.go b/pkg/store/secret.go deleted file mode 100644 index 784829a13..000000000 --- a/pkg/store/secret.go +++ /dev/null @@ -1,69 +0,0 @@ -package store - -import breverrors "github.com/brevdev/brev-cli/pkg/errors" - -type CreateSecretRequest struct { - Name string `json:"name"` - HierarchyType HierarchyType `json:"hierarchyType"` - HierarchyID string `json:"hierarchyID"` - Src SecretReqSrc `json:"src"` - Dest SecretReqDest `json:"dest"` -} - -type HierarchyType string - -const ( - Org HierarchyType = "org" - User HierarchyType = "user" -) - -type SecretReqDest struct { - Type DestType `json:"type"` - Config DestConfig `json:"config"` -} - -type DestConfig struct { - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` -} - -type SecretReqSrc struct { - Type SrcType `json:"type"` - Config SrcConfig `json:"config"` -} - -type SrcConfig struct { - Value string `json:"value"` -} - -type SrcType string - -const ( - KeyValue SrcType = "kv2" -) - -type DestType string - -const ( - File DestType = "file" - EnvVariable DestType = "env" -) - -var secretsPath = "api/secrets" - -func (s AuthHTTPStore) CreateSecret(req CreateSecretRequest) (*CreateSecretRequest, error) { - var result CreateSecretRequest - res, err := s.authHTTPClient.restyClient.R(). - SetHeader("Content-Type", "application/json"). - SetResult(&result). - SetBody(req). - Post(secretsPath) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - if res.IsError() { - return nil, NewHTTPResponseError(res) - } - - return &result, nil -}