mirror of
https://github.com/holos-run/holos.git
synced 2026-03-19 16:54:58 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d831070f53 |
@@ -1,6 +1,7 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/holos-run/holos/pkg/cli/command"
|
||||
"github.com/holos-run/holos/pkg/holos"
|
||||
@@ -29,6 +30,7 @@ func NewCreateCmd(hc *holos.Config) *cobra.Command {
|
||||
cfg.dryRun = flagSet.Bool("dry-run", false, "dry run")
|
||||
cfg.appendHash = flagSet.Bool("append-hash", true, "append hash to kubernetes secret name")
|
||||
cfg.dataStdin = flagSet.Bool("data-stdin", false, "read data field as json from stdin if")
|
||||
cfg.trimTrailingNewlines = flagSet.Bool("trim-trailing-newlines", true, "trim trailing newlines if true")
|
||||
|
||||
cmd.Flags().SortFlags = false
|
||||
cmd.Flags().AddGoFlagSet(flagSet)
|
||||
@@ -80,7 +82,7 @@ func makeCreateRunFunc(hc *holos.Config, cfg *config) command.RunFunc {
|
||||
}
|
||||
|
||||
for _, file := range cfg.files {
|
||||
if err := filepath.WalkDir(file, makeWalkFunc(secret.Data, file)); err != nil {
|
||||
if err := filepath.WalkDir(file, makeWalkFunc(secret.Data, file, *cfg.trimTrailingNewlines)); err != nil {
|
||||
return wrapper.Wrap(err)
|
||||
}
|
||||
}
|
||||
@@ -125,7 +127,7 @@ func makeCreateRunFunc(hc *holos.Config, cfg *config) command.RunFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func makeWalkFunc(data secretData, root string) fs.WalkDirFunc {
|
||||
func makeWalkFunc(data secretData, root string, trimNewlines bool) fs.WalkDirFunc {
|
||||
return func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -143,6 +145,9 @@ func makeWalkFunc(data secretData, root string) fs.WalkDirFunc {
|
||||
if data[key], err = os.ReadFile(path); err != nil {
|
||||
return wrapper.Wrap(err)
|
||||
}
|
||||
if trimNewlines {
|
||||
data[key] = bytes.TrimRight(data[key], "\r\n")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -12,15 +12,16 @@ const ClusterLabel = "holos.run/cluster.name"
|
||||
type secretData map[string][]byte
|
||||
|
||||
type config struct {
|
||||
files holos.StringSlice
|
||||
printFile *string
|
||||
extract *bool
|
||||
dryRun *bool
|
||||
appendHash *bool
|
||||
dataStdin *bool
|
||||
cluster *string
|
||||
namespace *string
|
||||
extractTo *string
|
||||
files holos.StringSlice
|
||||
printFile *string
|
||||
extract *bool
|
||||
dryRun *bool
|
||||
appendHash *bool
|
||||
dataStdin *bool
|
||||
trimTrailingNewlines *bool
|
||||
cluster *string
|
||||
namespace *string
|
||||
extractTo *string
|
||||
}
|
||||
|
||||
func newConfig() (*config, *flag.FlagSet) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Create the secret
|
||||
holos create secret directory --from-file=$WORK/fixture --dry-run
|
||||
holos create secret directory --trim-trailing-newlines=false --from-file=$WORK/fixture --dry-run
|
||||
|
||||
# Want no warnings.
|
||||
! stderr 'WRN'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Create the secret
|
||||
holos create secret directory --from-file=$WORK/want
|
||||
holos create secret directory --trim-trailing-newlines=false --from-file=$WORK/want
|
||||
stderr 'created: directory-..........'
|
||||
stderr 'secret=directory-..........'
|
||||
stderr 'name=directory'
|
||||
|
||||
17
pkg/cli/secret/testdata/create_secret_from_dir_strip_newlines.txt
vendored
Normal file
17
pkg/cli/secret/testdata/create_secret_from_dir_strip_newlines.txt
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Create a secret from files with trailing newlines
|
||||
holos create secret smtp --from-file=$WORK/smtp
|
||||
|
||||
# Get the secret back expecting no trailing newlines
|
||||
mkdir have
|
||||
holos get secret smtp
|
||||
stdout '"username": "holos.run@gmail.com"'
|
||||
stdout '"password": "secret"'
|
||||
|
||||
-- smtp/username --
|
||||
holos.run@gmail.com
|
||||
-- smtp/password --
|
||||
secret
|
||||
-- smtp/host --
|
||||
smtp.gmail.com
|
||||
-- smtp/port --
|
||||
587
|
||||
@@ -1,5 +1,5 @@
|
||||
# Create the secret
|
||||
holos create secret directory --from-file=$WORK/want
|
||||
holos create secret directory --trim-trailing-newlines=false --from-file=$WORK/want
|
||||
|
||||
# Get the secret back
|
||||
mkdir have
|
||||
|
||||
@@ -1 +1 @@
|
||||
2
|
||||
3
|
||||
|
||||
Reference in New Issue
Block a user