diff --git a/messages/init/messages.go b/messages/init/messages.go index 3c3e5cd3e..da18e8c94 100644 --- a/messages/init/messages.go +++ b/messages/init/messages.go @@ -19,7 +19,7 @@ var ( EdgeApplicationsInitFlagYes = "Answers all yes/no interactions automatically with yes" EdgeApplicationsInitFlagNo = "Answers all yes/no interactions automatically with no" WebAppInitContentOverridden = "This application was already configured. Do you want to override the previous configuration? (default: no) " - WebAppInitCmdSuccess = "Template successfully fetched and configured\n" + WebAppInitCmdSuccess = "Template successfully configured\n" InitGettingTemplates = "\nGetting presets available (Some dependencies may need to be installed)\n" InitGettingVulcan = "\nGetting templates available\n" InitProjectQuestion = "Your application's name: " diff --git a/messages/sync/messages.go b/messages/sync/messages.go index 7c15c00fd..639665225 100644 --- a/messages/sync/messages.go +++ b/messages/sync/messages.go @@ -8,7 +8,9 @@ const ( SYNCMESSAGECACHE = "Adding out of sync cache '%s' to your azion.json file\n" SYNCMESSAGEORIGIN = "Adding out of sync origin '%s' to your azion.json file\n" SYNCMESSAGEENV = "Adding out of sync variable '%s' to your azion account\n" + SYNCUPDATEENV = "Updating remote variable '%s' with local details\n" HELPFLAG = "Displays more information about the sync command" CONFDIRFLAG = "Relative path to where your custom azion.json and args.json files are stored" ENVFLAG = "Relative path to where your custom .env file is stored" + VARIABLESETSECRET = "Setting secret to true due to the variable key using one of the following words: 'PASSWORD', 'PWD', 'SECRET', 'HASH', 'ENCRYPTED', 'PASSCODE', 'AUTH', 'TOKEN', 'SECRET'\n" ) diff --git a/messages/variables/messages.go b/messages/variables/messages.go index 8ac8b68c0..d3dfd46f2 100644 --- a/messages/variables/messages.go +++ b/messages/variables/messages.go @@ -56,4 +56,6 @@ var ( AskValue = "Enter the Variable's value:" AskSecret = "Enter the Variable's secret:" AskVariableID = "Enter the Variable's variable ID:" + + VariableSetSecret = "Setting secret to true due to the variable key using one of the following words: 'PASSWORD', 'PWD', 'SECRET', 'HASH', 'ENCRYPTED', 'PASSCODE', 'AUTH', 'TOKEN', 'SECRET'\n" ) diff --git a/pkg/cmd/create/variables/variables.go b/pkg/cmd/create/variables/variables.go index 67521a93e..83d3aad66 100644 --- a/pkg/cmd/create/variables/variables.go +++ b/pkg/cmd/create/variables/variables.go @@ -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 @@ -48,7 +52,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return utils.ErrorUnmarshalReader } } else { - err := createRequestFromFlags(cmd, fields, &request) + err := createRequestFromFlags(cmd, f, fields, &request) if err != nil { return err } @@ -76,7 +80,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return cmd } -func createRequestFromFlags(cmd *cobra.Command, fields *Fields, request *api.Request) error { +func createRequestFromFlags(cmd *cobra.Command, f *cmdutil.Factory, fields *Fields, request *api.Request) error { if !cmd.Flags().Changed("key") { answers, err := utils.AskInput(msg.AskKey) @@ -105,6 +109,11 @@ 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) { + logger.FInfo(f.IOStreams.Out, msg.VariableSetSecret) + request.SetSecret(true) + } } request.SetKey(fields.Key) diff --git a/pkg/cmd/deploy/deploy.go b/pkg/cmd/deploy/deploy.go index e89b3d8ca..99a6e8688 100644 --- a/pkg/cmd/deploy/deploy.go +++ b/pkg/cmd/deploy/deploy.go @@ -150,7 +150,7 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error { if Local { deployLocal := deploy.NewDeployCmd(f) - return deployLocal.ExternalRun(f, ProjectConf, Sync) + return deployLocal.ExternalRun(f, ProjectConf, Env, Sync, Auto, SkipBuild) } msgs := []string{} diff --git a/pkg/cmd/deploy_remote/deploy.go b/pkg/cmd/deploy_remote/deploy.go index 78809f9d2..1f06be9dd 100644 --- a/pkg/cmd/deploy_remote/deploy.go +++ b/pkg/cmd/deploy_remote/deploy.go @@ -97,9 +97,12 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return NewCobraCmd(NewDeployCmd(f)) } -func (cmd *DeployCmd) ExternalRun(f *cmdutil.Factory, configPath string, shouldSync bool) error { +func (cmd *DeployCmd) ExternalRun(f *cmdutil.Factory, configPath string, env string, shouldSync, auto, skipBuild bool) error { ProjectConf = configPath Sync = shouldSync + Env = env + Auto = auto + SkipBuild = skipBuild return cmd.Run(f) } diff --git a/pkg/cmd/deploy_remote/requests.go b/pkg/cmd/deploy_remote/requests.go index ae3b0a7d0..d31e3b611 100644 --- a/pkg/cmd/deploy_remote/requests.go +++ b/pkg/cmd/deploy_remote/requests.go @@ -106,11 +106,7 @@ func (cmd *DeployCmd) doFunction(clients *Clients, ctx context.Context, conf *co return nil } -func (cmd *DeployCmd) doApplication( - client *apiapp.Client, - ctx context.Context, - conf *contracts.AzionApplicationOptions, - msgs *[]string) error { +func (cmd *DeployCmd) doApplication(client *apiapp.Client, ctx context.Context, conf *contracts.AzionApplicationOptions, msgs *[]string) error { if conf.Application.ID == 0 { var projName string for { diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 561584c26..4f7d2644a 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -10,6 +10,7 @@ import ( "os" "path" "strings" + "time" "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" @@ -25,6 +26,7 @@ import ( vulcanPkg "github.com/aziontech/azion-cli/pkg/vulcan" "github.com/aziontech/azion-cli/utils" thoth "github.com/aziontech/go-thoth" + "github.com/briandowns/spinner" "github.com/go-git/go-git/v5" "github.com/joho/godotenv" "github.com/spf13/cobra" @@ -230,12 +232,21 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error { } }() + s := spinner.New(spinner.CharSets[7], 100*time.Millisecond) + s.Suffix = " Fetching selected template..." + s.FinalMSG = "Template successfully fetched\n" + if !cmd.f.Debug { + s.Start() // Start the spinner + } + err = cmd.git.Clone(SAMPLESURL, tempDir) if err != nil { logger.Debug("Error while cloning the repository", zap.Error(err)) return err } + s.Stop() + oldPath := path.Join(tempDir, "templates", templateOptionsMap[answerTemplate].Path) newPath := path.Join(pathWorkingDirHere, cmd.name) diff --git a/pkg/cmd/sync/tasks.go b/pkg/cmd/sync/tasks.go index 2bd458c86..a377c7fa6 100644 --- a/pkg/cmd/sync/tasks.go +++ b/pkg/cmd/sync/tasks.go @@ -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 { @@ -154,6 +156,19 @@ func (synch *SyncCmd) syncEnv(f *cmdutil.Factory) error { for _, variable := range resp { if v := envs[variable.GetKey()]; v != "" { + updateRequest := &varApi.Request{} + updateRequest.SetKey(variable.GetKey()) + updateRequest.SetValue(v) + updateRequest.Uuid = variable.GetUuid() + if utils.ContainSubstring(variable.GetKey(), words) { + logger.FInfo(f.IOStreams.Out, msg.VARIABLESETSECRET) + updateRequest.SetSecret(true) + } + _, err := client.Update(ctx, updateRequest) + if err != nil { + return err + } + logger.FInfoFlags(synch.Io.Out, fmt.Sprintf(msg.SYNCUPDATEENV, variable.GetKey()), synch.F.Format, synch.F.Out) delete(envs, variable.GetKey()) } } @@ -162,13 +177,16 @@ func (synch *SyncCmd) syncEnv(f *cmdutil.Factory) error { createReq := &varApi.Request{} createReq.Key = key createReq.Value = value + if utils.ContainSubstring(key, words) { + logger.FInfo(f.IOStreams.Out, msg.VARIABLESETSECRET) + createReq.SetSecret(true) + } _, err := client.Create(ctx, *createReq) if err != nil { logger.Debug("Error while creating variables during sync process", zap.Error(err)) return err } - logger.FInfoFlags( - synch.Io.Out, fmt.Sprintf(msg.SYNCMESSAGEENV, key), synch.F.Format, synch.F.Out) + logger.FInfoFlags(synch.Io.Out, fmt.Sprintf(msg.SYNCMESSAGEENV, key), synch.F.Format, synch.F.Out) } return nil } diff --git a/utils/helpers.go b/utils/helpers.go index 560a5c3bd..39f49159b 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -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(word, item) { + return true // Return immediately if a match is found + } + } + return false +}