Skip to content

Commit

Permalink
refactor: conflict merge
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed Sep 17, 2024
2 parents 05b0f6e + cad0af3 commit 680aff5
Show file tree
Hide file tree
Showing 14 changed files with 671 additions and 61 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/schollz/progressbar/v3 v3.14.6
github.com/schollz/progressbar/v3 v3.15.0
github.com/segmentio/analytics-go/v3 v3.3.0
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.1
Expand Down Expand Up @@ -84,8 +84,8 @@ require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/schollz/progressbar/v3 v3.14.6 h1:GyjwcWBAf+GFDMLziwerKvpuS7ZF+mNTAXIB2aspiZs=
github.com/schollz/progressbar/v3 v3.14.6/go.mod h1:Nrzpuw3Nl0srLY0VlTvC4V6RL50pcEymjy6qyJAaLa0=
github.com/schollz/progressbar/v3 v3.15.0 h1:cNZmcNiVyea6oofBTg80ZhVXxf3wG/JoAhqCCwopkQo=
github.com/schollz/progressbar/v3 v3.15.0/go.mod h1:ncBdc++eweU0dQoeZJ3loXoAc+bjaallHRIm8pVVeQM=
github.com/segmentio/analytics-go/v3 v3.3.0 h1:8VOMaVGBW03pdBrj1CMFfY9o/rnjJC+1wyQHlVxjw5o=
github.com/segmentio/analytics-go/v3 v3.3.0/go.mod h1:p8owAF8X+5o27jmvUognuXxdtqvSGtD0ZrfY2kcS9bE=
github.com/segmentio/backo-go v1.0.0 h1:kbOAtGJY2DqOR0jfRkYEorx/b18RgtepGtY3+Cpe6qA=
Expand Down Expand Up @@ -441,15 +441,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
1 change: 1 addition & 0 deletions messages/deploy/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
EdgeApplicationDeployPathFlag = "Path to where your static files are stored"
EdgeApplicationDeployProjectConfFlag = "Relative path to where your custom azion.json and args.json files are stored"
EdgeApplicationDeploySync = "Synchronizes the local azion.json file with remote resources"
EdgeApplicationDeployDryrun = "Simulates the deploy process without carrying out any actual action"
EnvFlag = "Relative path to where your custom .env file is stored"
OriginsSuccessful = "Created Origin for Edge Application\n"
OriginsUpdateSuccessful = "Updated Origin for Edge Application %v with ID %v \n"
Expand Down
27 changes: 27 additions & 0 deletions messages/dryrun/messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dryrun

var (
SkipManifest = "This project has not been built yet. Skipping the simulation for resources found in your azion.config file\n"
CreateEdgeApp = "Creating Edge Application named '%s'\n"
UpdateEdgeApp = "Updating Edge Application with ID '%d', named '%s'\n"
CreateOrigin = "Creating Origin named '%s'\n"
UpdateOrigin = "Updating Origin with ID '%d' and Key '%s', named '%s'\n"
CreateCacheSetting = "Creating Cache Setting named '%s'\n"
UpdateCacheSetting = "Updating Cache Setting with ID '%d', named '%s'\n"
CreateRule = "Creating Rule Engine named '%s'\n"
UpdateRule = "Updating Rule Engine with ID '%d', named '%s'\n"
CreateBucket = "Creating Bucket named '%s'\n"
CreateDomain = "Creating Domain named '%s'\n"
UpdateDomain = "Updating Domain with ID '%d', named '%s'\n"
CreateOriginSingle = "Creating single Origin named '%s'\n"
UpdateDefaultRule = "Updating default Rule Engine - Set Origin '%s'\n"
DeletingRuleEngine = "Deleting Rule Engine with ID '%d', named '%s'"
DeletingOrigin = "Deleting Origin with ID '%d' and Key '%s', named '%s'"
DeletingCacheSetting = "Deleting Cache Setting with ID '%d', named '%s'"
CreateRulesCache = "Presenting the option to create Cache Setting (details below) and Rule Engine setting said Cache Setting\n"
AskCreateCacheSettings = `Cache Settings specifications:
- Browser Cache Settings: Override Cache Settings
- Maximum TTL for Browser Cache Settings (in seconds): 7200
- Edge Application Cache Settings: Override Cache Settings
- Maximum TTL for Edge Application Cache Settings (in seconds): 7200`
)
1 change: 1 addition & 0 deletions messages/init/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ var (
ErrorModeNotFound = errors.New("No mode was found for the selected template. For more information, run the command again using the '--debug' flag. If the problem persists, contact Azion’s support")
ErrorReadingGitignore = errors.New("Failed to read your .gitignore file")
ErrorWritingGitignore = errors.New("Failed to write to your .gitignore file")
ErrorGetProjectInfo = errors.New("Failed to get project info (preset and mode)")
)
14 changes: 14 additions & 0 deletions pkg/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
apiEdgeApplications "github.com/aziontech/azion-cli/pkg/api/edge_applications"
"github.com/aziontech/azion-cli/pkg/cmd/build"
"github.com/aziontech/azion-cli/pkg/cmd/sync"

"github.com/aziontech/azion-cli/pkg/cmdutil"
"github.com/aziontech/azion-cli/pkg/contracts"
dryrun "github.com/aziontech/azion-cli/pkg/dry_run"
"github.com/aziontech/azion-cli/pkg/iostreams"
"github.com/aziontech/azion-cli/pkg/logger"
manifestInt "github.com/aziontech/azion-cli/pkg/manifest"
Expand Down Expand Up @@ -50,6 +52,7 @@ var (
SkipBuild bool
ProjectConf string
Sync bool
DryRun bool
Env string
)

Expand Down Expand Up @@ -95,6 +98,7 @@ func NewCobraCmd(deploy *DeployCmd) *cobra.Command {
deployCmd.Flags().BoolVar(&SkipBuild, "skip-build", false, msg.DeployFlagSkipBuild)
deployCmd.Flags().StringVar(&ProjectConf, "config-dir", "azion", msg.EdgeApplicationDeployProjectConfFlag)
deployCmd.Flags().BoolVar(&Sync, "sync", false, msg.EdgeApplicationDeploySync)
deployCmd.Flags().BoolVar(&DryRun, "dry-run", false, msg.EdgeApplicationDeployDryrun)
deployCmd.Flags().StringVar(&Env, "env", ".edge/.env", msg.EnvFlag)
return deployCmd
}
Expand All @@ -109,6 +113,16 @@ func (cmd *DeployCmd) ExternalRun(f *cmdutil.Factory, configPath string) error {
}

func (cmd *DeployCmd) Run(f *cmdutil.Factory) error {

if DryRun {
dryStructure := dryrun.NewDryrunCmd(f)
pathWorkingDir, err := cmd.GetWorkDir()
if err != nil {
return err
}
return dryStructure.SimulateDeploy(pathWorkingDir, ProjectConf)
}

msgs := []string{}
logger.FInfoFlags(cmd.F.IOStreams.Out, "Running deploy command\n", cmd.F.Format, cmd.F.Out)
msgs = append(msgs, "Running deploy command")
Expand Down
6 changes: 1 addition & 5 deletions pkg/cmd/deploy/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,7 @@ func (cmd *DeployCmd) doDomain(client *apidom.Client, ctx context.Context, conf
return nil
}

func (cmd *DeployCmd) doRulesDeploy(
ctx context.Context,
conf *contracts.AzionApplicationOptions,
client *apiapp.Client,
msgs *[]string) error {
func (cmd *DeployCmd) doRulesDeploy(ctx context.Context, conf *contracts.AzionApplicationOptions, client *apiapp.Client, msgs *[]string) error {
if conf.NotFirstRun {
return nil
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/aziontech/azion-cli/pkg/output"
vulcanPkg "github.com/aziontech/azion-cli/pkg/vulcan"
"github.com/aziontech/azion-cli/utils"
helpers "github.com/aziontech/azion-cli/utils"
thoth "github.com/aziontech/go-thoth"
"github.com/go-git/go-git/v5"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -263,10 +262,10 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error {
vul := vulcanPkg.NewVulcan()
err = cmd.selectVulcanTemplates(vul)
if err != nil {
return err
return msg.ErrorGetProjectInfo
}

if cmd.auto || !helpers.Confirm(cmd.globalFlagAll, msg.AskLocalDev, false) {
if cmd.auto || !utils.Confirm(cmd.globalFlagAll, msg.AskLocalDev, false) {
logger.FInfoFlags(cmd.f.IOStreams.Out, msg.InitDevCommand, cmd.f.Format, cmd.f.Out)
msgs = append(msgs, msg.InitDevCommand)
} else {
Expand All @@ -282,7 +281,7 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error {
}
}

if cmd.auto || !helpers.Confirm(cmd.globalFlagAll, msg.AskDeploy, false) {
if cmd.auto || !utils.Confirm(cmd.globalFlagAll, msg.AskDeploy, false) {
logger.FInfoFlags(cmd.f.IOStreams.Out, msg.InitDeployCommand, cmd.f.Format, cmd.f.Out)
msgs = append(msgs, msg.InitDeployCommand)
msgEdgeAppInitSuccessFull := fmt.Sprintf(msg.EdgeApplicationsInitSuccessful, cmd.name)
Expand Down Expand Up @@ -315,7 +314,7 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error {

func (cmd *initCmd) deps(c *cobra.Command, m string, msgs *[]string) error {
if !c.Flags().Changed("package-manager") {
if !helpers.Confirm(cmd.globalFlagAll, m, true) {
if !utils.Confirm(cmd.globalFlagAll, m, true) {
return nil
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/cmd/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"go.uber.org/zap/zapcore"
)

var infoJsonData = `{"preset":"astro","mode":"deliver"}`

func TestNewCmd(t *testing.T) {
mock := &httpmock.Registry{}
f, _, _ := testutils.NewFactory(mock)
Expand Down Expand Up @@ -87,6 +89,9 @@ func Test_initCmd_Run(t *testing.T) {
name: "success flow",
fields: fields{
auto: true,
fileReader: func(filename string) ([]byte, error) {
return []byte(infoJsonData), nil
},
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
GlobalFlagAll: false,
Expand Down Expand Up @@ -160,6 +165,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error getWorkDir",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return []byte(infoJsonData), nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -235,6 +243,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error http.Get",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return []byte(infoJsonData), nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -310,6 +321,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error askForInput",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return []byte(infoJsonData), nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -385,6 +399,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error expected status OK",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return []byte(infoJsonData), nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -460,6 +477,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error readAll",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -537,6 +557,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error unmarshal",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -614,6 +637,9 @@ func Test_initCmd_Run(t *testing.T) {
{
name: "error askOne",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
auto: true,
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
Expand Down Expand Up @@ -795,6 +821,9 @@ func Test_initCmd_deps(t *testing.T) {
{
name: "success flow",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
GlobalFlagAll: false,
Expand Down Expand Up @@ -823,6 +852,9 @@ func Test_initCmd_deps(t *testing.T) {
{
name: "error depsInstall",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
GlobalFlagAll: false,
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/init/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Test_initCmd_createTemplateAzion(t *testing.T) {
writeFile func(filename string, data []byte, perm fs.FileMode) error
mkdir func(path string, perm os.FileMode) error
marshalIndent func(v any, prefix, indent string) ([]byte, error)
fileReader func(path string) ([]byte, error)
}
tests := []struct {
name string
Expand All @@ -33,6 +34,9 @@ func Test_initCmd_createTemplateAzion(t *testing.T) {
{
name: "success flow",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
name: "project_piece",
preset: "vite",
mode: "deliver",
Expand All @@ -49,6 +53,9 @@ func Test_initCmd_createTemplateAzion(t *testing.T) {
{
name: "error mkdir",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
name: "project_piece",
preset: "vite",
mode: "deliver",
Expand All @@ -65,6 +72,9 @@ func Test_initCmd_createTemplateAzion(t *testing.T) {
{
name: "error marshalIndent",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
name: "project_piece",
preset: "vite",
mode: "deliver",
Expand All @@ -83,6 +93,9 @@ func Test_initCmd_createTemplateAzion(t *testing.T) {
{
name: "error writeFile",
fields: fields{
fileReader: func(filename string) ([]byte, error) {
return nil, nil
},
name: "project_piece",
preset: "vite",
mode: "deliver",
Expand All @@ -106,6 +119,7 @@ func Test_initCmd_createTemplateAzion(t *testing.T) {
writeFile: tt.fields.writeFile,
mkdir: tt.fields.mkdir,
marshalIndent: tt.fields.marshalIndent,
fileReader: tt.fields.fileReader,
}
if err := cmd.createTemplateAzion(); (err != nil) != tt.wantErr {
t.Errorf("initCmd.createTemplateAzion() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
Loading

0 comments on commit 680aff5

Please sign in to comment.