Skip to content

Commit

Permalink
add override flag to the aws install command
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Sep 29, 2021
1 parent bbe7082 commit d96f8c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cli/cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and what account will be managed by command.
},
}
addAwsInstallFlags(cmd)
cmd.Flags().Bool("override", false, "force override access tokens on already installed account")
return cmd
}

Expand Down Expand Up @@ -77,6 +78,7 @@ and what account will be managed by command.
showDryRunInfo(cred)
return nil
}

return cred.cmd.Destroy()
},
}
Expand Down Expand Up @@ -164,7 +166,8 @@ func initAwsInstall(cmd *cobra.Command, args []string) (*credentials, error) {
return nil, err
}

c.cmd = setup.New(c.cli, c.version, c.accountName)
override, _ := cmd.Flags().GetBool("override")
c.cmd = setup.New(c.cli, c.version, c.accountName, override)
return &c, nil
}

Expand Down
17 changes: 11 additions & 6 deletions cli/cmd/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ type Cmd struct {
functionsPath string
awsClient *aws.AWS
accountName string
override bool
}

func New(awsClient *aws.AWS, v *VersionInfo, accountName string) *Cmd {
func New(awsClient *aws.AWS, v *VersionInfo, accountName string, override bool) *Cmd {
return &Cmd{
functionsBucket: v.functionsBucket(awsClient.Region()),
awsClient: awsClient,
functionsPath: v.functionsPath(),
accountName: accountName,
override: override,
}
}

Expand All @@ -43,7 +45,7 @@ func (c *Cmd) Create() error {
if err = commands.WorkspaceUpsertAccount(ac); err != nil {
return err
}
log.Notice("setup successfully finished")
log.Notice("install successfully finished")
return nil
}

Expand Down Expand Up @@ -94,11 +96,14 @@ func (c *Cmd) ensureLambdaExists() error {
log.Printf("[ERROR]: %w", err)
return err
}
log.Printf("alreadyRun %v", alreadyRun)
log.Printf("alreadyRun: %v override: %v", alreadyRun, c.override)
if alreadyRun {
// BUG: ovo u nastavku ne valja promjenit ce credentials pa padaju svi postojeci
log.Info("Mantil is already set up on this account, updating credentials and fetching config...")
return nil
if c.override {
return nil
}
err := fmt.Errorf("Mantil is already installed use override flag if you want to change acccess tokens")
log.Printf("Mantil already installed and override is not set returning: %s", err)
return err
}
if err := c.createLambda(); err != nil {
log.Printf("[ERROR] %w", err)
Expand Down

0 comments on commit d96f8c6

Please sign in to comment.