Skip to content

Commit

Permalink
Merge pull request #993 from aziontech/dev
Browse files Browse the repository at this point in the history
Deploy to Production - 2024/11/7
  • Loading branch information
PatrickMenoti authored Nov 8, 2024
2 parents df38d5b + 4958cef commit 95ea56d
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 14 deletions.
2 changes: 1 addition & 1 deletion messages/init/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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? <yes | no> (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: "
Expand Down
2 changes: 2 additions & 0 deletions messages/sync/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 2 additions & 0 deletions messages/variables/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
13 changes: 11 additions & 2 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 @@ -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
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/deploy_remote/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/cmd/deploy_remote/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path"
"strings"
"time"

"github.com/AlecAivazis/survey/v2"
"github.com/MakeNowJust/heredoc"
Expand All @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
26 changes: 22 additions & 4 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 @@ -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())
}
}
Expand All @@ -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
}
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(word, item) {
return true // Return immediately if a match is found
}
}
return false
}

0 comments on commit 95ea56d

Please sign in to comment.