Skip to content

Commit

Permalink
fix(cli): init should set appVersionGetter with correct app name (#5126)
Browse files Browse the repository at this point in the history
Right now `init` interactive wizard is broken because we don't set `appVersionGetter` with correct app name. This PR fixes this issue.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
  • Loading branch information
iamhopaul123 authored Jul 27, 2023
1 parent 0a886d6 commit b86cf91
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 56 deletions.
50 changes: 25 additions & 25 deletions internal/pkg/cli/env_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,23 @@ type initEnvOpts struct {
initEnvVars

// Interfaces to interact with dependencies.
sessProvider sessionProvider
store store
envDeployer deployer
appDeployer deployer
identity identityService
envIdentity identityService
ec2Client ec2Client
appVersionGetter versionGetter
iam roleManager
cfn stackExistChecker
prog progress
prompt prompter
selVPC ec2Selector
selCreds func() (credsSelector, error)
selApp appSelector
appCFN appResourcesGetter
manifestWriter environmentManifestWriter
sessProvider sessionProvider
store store
envDeployer deployer
appDeployer deployer
identity identityService
envIdentity identityService
ec2Client ec2Client
newAppVersionGetter func(appName string) (versionGetter, error)
iam roleManager
cfn stackExistChecker
prog progress
prompt prompter
selVPC ec2Selector
selCreds func() (credsSelector, error)
selApp appSelector
appCFN appResourcesGetter
manifestWriter environmentManifestWriter

sess *session.Session // Session pointing to environment's AWS account and region.

Expand Down Expand Up @@ -218,6 +218,9 @@ func newInitEnvOpts(vars initEnvVars) (*initEnvOpts, error) {
Prompt: prompt.New(),
}, nil
},
newAppVersionGetter: func(appName string) (versionGetter, error) {
return describe.NewAppDescriber(appName)
},
selApp: selector.NewAppEnvSelector(prompt.New(), store),
appCFN: deploycfn.New(defaultSession, deploycfn.WithProgressTracker(os.Stderr)),
manifestWriter: ws,
Expand Down Expand Up @@ -269,7 +272,11 @@ func (o *initEnvOpts) Execute() error {
return err
}
if !o.allowAppDowngrade {
if err := validateAppVersion(o.appVersionGetter, o.appName, o.templateVersion); err != nil {
versionGetter, err := o.newAppVersionGetter(o.appName)
if err != nil {
return err
}
if err := validateAppVersion(versionGetter, o.appName, o.templateVersion); err != nil {
return err
}
}
Expand Down Expand Up @@ -354,13 +361,6 @@ func (o *initEnvOpts) initRuntimeClients() error {
if o.iam == nil {
o.iam = iam.New(o.sess)
}
if o.appVersionGetter == nil {
appDescriber, err := describe.NewAppDescriber(o.appName)
if err != nil {
return err
}
o.appVersionGetter = appDescriber
}
return nil
}

Expand Down
28 changes: 15 additions & 13 deletions internal/pkg/cli/env_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,19 +1283,21 @@ func TestInitEnvOpts_Execute(t *testing.T) {
},
allowAppDowngrade: tc.allowDowngrade,
},
store: m.store,
envDeployer: m.deployer,
appDeployer: m.deployer,
identity: m.identity,
envIdentity: m.identity,
iam: m.iam,
cfn: m.cfn,
prog: m.progress,
sess: sess,
appCFN: m.appCFN,
appVersionGetter: m.appVersionGetter,
manifestWriter: m.manifestWriter,
templateVersion: mockCurrVersion,
store: m.store,
envDeployer: m.deployer,
appDeployer: m.deployer,
identity: m.identity,
envIdentity: m.identity,
iam: m.iam,
cfn: m.cfn,
prog: m.progress,
sess: sess,
appCFN: m.appCFN,
newAppVersionGetter: func(appName string) (versionGetter, error) {
return m.appVersionGetter, nil
},
manifestWriter: m.manifestWriter,
templateVersion: mockCurrVersion,
}

// WHEN
Expand Down
30 changes: 12 additions & 18 deletions internal/pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ func newInitOpts(vars initVars) (*initOpts, error) {
id := identity.New(defaultSess)
deployer := cloudformation.New(defaultSess, cloudformation.WithProgressTracker(os.Stderr))
iamClient := iam.New(defaultSess)
appVersionGetter, err := describe.NewAppDescriber(vars.appName)
if err != nil {
return nil, err
}
initAppCmd := &initAppOpts{
initAppVars: initAppVars{
name: vars.appName,
Expand All @@ -141,24 +137,24 @@ func newInitOpts(vars initVars) (*initOpts, error) {
}
initEnvCmd := &initEnvOpts{
initEnvVars: initEnvVars{
appName: vars.appName,
name: defaultEnvironmentName,
isProduction: false,
},
store: configStore,
appDeployer: deployer,
prog: spin,
prompt: prompt,
identity: id,
appVersionGetter: appVersionGetter,
appCFN: cloudformation.New(defaultSess, cloudformation.WithProgressTracker(os.Stderr)),
sess: defaultSess,
templateVersion: version.LatestTemplateVersion(),
store: configStore,
appDeployer: deployer,
prog: spin,
prompt: prompt,
identity: id,
newAppVersionGetter: func(appName string) (versionGetter, error) {
return describe.NewAppDescriber(appName)
},
appCFN: cloudformation.New(defaultSess, cloudformation.WithProgressTracker(os.Stderr)),
sess: defaultSess,
templateVersion: version.LatestTemplateVersion(),
}
deployEnvCmd := &deployEnvOpts{
deployEnvVars: deployEnvVars{
appName: vars.appName,
name: defaultEnvironmentName,
name: defaultEnvironmentName,
},
store: configStore,
sessionProvider: sessProvider,
Expand All @@ -178,7 +174,6 @@ func newInitOpts(vars initVars) (*initOpts, error) {
deployWkldVars: deployWkldVars{
envName: defaultEnvironmentName,
imageTag: vars.imageTag,
appName: vars.appName,
},

store: configStore,
Expand All @@ -197,7 +192,6 @@ func newInitOpts(vars initVars) (*initOpts, error) {
deployWkldVars: deployWkldVars{
envName: defaultEnvironmentName,
imageTag: vars.imageTag,
appName: vars.appName,
},
store: configStore,
newInterpolator: newManifestInterpolator,
Expand Down

0 comments on commit b86cf91

Please sign in to comment.