This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2333 from ibuildthecloud/main
Add secret update and secret create --replace/--update
- Loading branch information
Showing
21 changed files
with
197 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
docs/docs/100-reference/01-command-line/acorn_secret_update.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: "acorn secret update" | ||
--- | ||
## acorn secret update | ||
|
||
Update a secret | ||
|
||
``` | ||
acorn secret update [flags] SECRET_NAME | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Create secret with specific keys | ||
acorn secret update --data key-name=value --data key-name2=value2 my-secret | ||
# Read full secret from a file. The file should have a type and data field. | ||
acorn secret update --file secret.yaml my-secret | ||
# Read key value from a file | ||
acorn secret update --data @key-name=secret.yaml my-secret | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--data strings Secret data format key=value or @key=filename to read from file | ||
--file string File to read for entire secret in aml/yaml/json format | ||
-h, --help help for update | ||
--type string Secret type | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config-file string Path of the acorn config file to use | ||
--debug Enable debug logging | ||
--debug-level int Debug log level (valid 0-9) (default 7) | ||
--kubeconfig string Explicitly use kubeconfig file, overriding the default context | ||
-o, --output string Output format (json, yaml, {{gotemplate}}) | ||
-j, --project string Project to work in | ||
-q, --quiet Output only names | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [acorn secret](acorn_secret.md) - Manage secrets | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
cli "github.com/acorn-io/runtime/pkg/cli/builder" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewSecretUpdate(c CommandContext) *cobra.Command { | ||
cmd := cli.Command(&SecretUpdate{client: c.ClientFactory}, cobra.Command{ | ||
Use: "update [flags] SECRET_NAME", | ||
Example: ` | ||
# Create secret with specific keys | ||
acorn secret update --data key-name=value --data key-name2=value2 my-secret | ||
# Read full secret from a file. The file should have a type and data field. | ||
acorn secret update --file secret.yaml my-secret | ||
# Read key value from a file | ||
acorn secret update --data @key-name=secret.yaml my-secret`, | ||
SilenceUsage: true, | ||
Short: "Update a secret", | ||
Args: cobra.ExactArgs(1), | ||
}) | ||
return cmd | ||
} | ||
|
||
type SecretUpdate struct { | ||
SecretFactory | ||
client ClientFactory | ||
} | ||
|
||
func (a *SecretUpdate) Run(cmd *cobra.Command, args []string) error { | ||
client, err := a.client.CreateDefault() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
secret, err := a.buildSecret() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
existing, err := client.SecretReveal(cmd.Context(), args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if existing.Data == nil { | ||
existing.Data = map[string][]byte{} | ||
} | ||
|
||
for k, v := range secret.Data { | ||
existing.Data[k] = v | ||
} | ||
|
||
newSecret, err := client.SecretUpdate(cmd.Context(), args[0], existing.Data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(newSecret.Name) | ||
return nil | ||
} |
Oops, something went wrong.