Skip to content

Commit

Permalink
chore: make variables secret if a certain word is used
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed Nov 5, 2024
1 parent 5dedb29 commit 0d4d67f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/cmd/create/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/spf13/cobra"
)

var (
words = []string{"PASSWORD", "PWD", "SECRET", "HASH", "ENCRYPTED", "PASSCODE", "AUTH", "TOKEN", "SECRET"}
)

type Fields struct {
Key string
Value string
Expand Down Expand Up @@ -105,6 +109,10 @@ func createRequestFromFlags(cmd *cobra.Command, fields *Fields, request *api.Req
return fmt.Errorf("%w: %q", msg.ErrorSecretFlag, fields.Secret)
}
request.SetSecret(secret)
} else {
if utils.ContainSubstring(fields.Key, words) {
request.SetSecret(true)
}
}

request.SetKey(fields.Key)
Expand Down
12 changes: 10 additions & 2 deletions pkg/cmd/sync/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"github.com/aziontech/azion-cli/pkg/cmdutil"
"github.com/aziontech/azion-cli/pkg/contracts"
"github.com/aziontech/azion-cli/pkg/logger"
"github.com/aziontech/azion-cli/utils"
"go.uber.org/zap"
)

var (
opts *contracts.ListOptions
ctx context.Context = context.Background()
opts *contracts.ListOptions
ctx context.Context = context.Background()
words = []string{"PASSWORD", "PWD", "SECRET", "HASH", "ENCRYPTED", "PASSCODE", "AUTH", "TOKEN", "SECRET"}
)

func SyncLocalResources(f *cmdutil.Factory, info contracts.SyncOpts, synch *SyncCmd) error {
Expand Down Expand Up @@ -158,6 +160,9 @@ func (synch *SyncCmd) syncEnv(f *cmdutil.Factory) error {
updateRequest.SetKey(variable.GetKey())
updateRequest.SetValue(v)
updateRequest.Uuid = variable.GetUuid()
if utils.ContainSubstring(variable.GetKey(), words) {
updateRequest.SetSecret(true)
}
_, err := client.Update(ctx, updateRequest)
if err != nil {
return err
Expand All @@ -171,6 +176,9 @@ func (synch *SyncCmd) syncEnv(f *cmdutil.Factory) error {
createReq := &varApi.Request{}
createReq.Key = key
createReq.Value = value
if utils.ContainSubstring(key, words) {
createReq.SetSecret(true)
}
_, err := client.Create(ctx, *createReq)
if err != nil {
logger.Debug("Error while creating variables during sync process", zap.Error(err))
Expand Down
9 changes: 9 additions & 0 deletions utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,12 @@ func FileExists(filename string) bool {
}
return !info.IsDir()
}

func ContainSubstring(word string, words []string) bool {
for _, item := range words {
if item == word || strings.Contains(item, word) {
return true // Return immediately if a match is found
}
}
return false
}

0 comments on commit 0d4d67f

Please sign in to comment.