First commit of golang CLI.
This commit is contained in:
53
wild-cli/cmd/wild/secret/set.go
Normal file
53
wild-cli/cmd/wild/secret/set.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/wild-cloud/wild-cli/internal/config"
|
||||
"github.com/wild-cloud/wild-cli/internal/environment"
|
||||
"github.com/wild-cloud/wild-cli/internal/output"
|
||||
)
|
||||
|
||||
func newSetCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "set <path> <value>",
|
||||
Short: "Set a secret value",
|
||||
Long: `Set a secret value in secrets.yaml using a dot-notation path.
|
||||
|
||||
The value will be stored as-is in the secrets file. Be careful with sensitive data.
|
||||
|
||||
Examples:
|
||||
wild secret set database.password mySecretPassword123
|
||||
wild secret set apps.myapp.api_key abc123def456
|
||||
wild secret set certificates.tls.key "-----BEGIN PRIVATE KEY-----..."`,
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: runSet,
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runSet(cmd *cobra.Command, args []string) error {
|
||||
path := args[0]
|
||||
value := args[1]
|
||||
|
||||
// Initialize environment
|
||||
env := environment.New()
|
||||
if err := env.RequiresProject(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create config manager
|
||||
mgr := config.NewManager(env.ConfigPath(), env.SecretsPath())
|
||||
|
||||
// Set the secret value
|
||||
if err := mgr.SetSecret(path, value); err != nil {
|
||||
return fmt.Errorf("setting secret value: %w", err)
|
||||
}
|
||||
|
||||
// Don't show the actual value in output for security
|
||||
output.Success(fmt.Sprintf("Set secret %s", path))
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user