Skip to content

Commit

Permalink
update code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nullfunc committed Dec 20, 2024
1 parent 74ade2c commit 277f901
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
11 changes: 1 addition & 10 deletions src/cmd/cli/command/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,11 @@ var cdListCmd = &cobra.Command{
}

if remote {
loader := configureLoader(cmd)

projectName, err := cliClient.LoadProjectNameWithFallback(cmd.Context(), loader, provider)
provider, err = canIUseProvider(cmd.Context(), provider, "")
if err != nil {
return err
}

provider, err = canIUseProvider(cmd.Context(), provider, projectName)
if err != nil {
return err
}
}

if remote {
// FIXME: this needs auth because it spawns the CD task
return cli.BootstrapCommand(cmd.Context(), "", client, provider, "list")
}
Expand Down
36 changes: 7 additions & 29 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,6 @@ func prettyError(err error) error {
return err
}

// TODO: Make call to provider to get project cd version and pass to CanIUse API call
func allowToUseProvider(ctx context.Context, providerID cliClient.ProviderID, projectName string) (string, error) {
canUseReq := defangv1.CanIUseRequest{
Project: projectName,
Provider: providerID.EnumValue(),
}

resp, err := client.CanIUse(ctx, &canUseReq)
if err != nil {
return "", err
}

return resp.CdImage, nil
}

func Execute(ctx context.Context) error {
if term.StdoutCanColor() { // TODO: should use DoColor(…) instead
restore := term.EnableANSI()
Expand Down Expand Up @@ -1136,24 +1121,17 @@ func getProvider(ctx context.Context, loader cliClient.Loader) (cliClient.Provid
}

func canIUseProvider(ctx context.Context, provider cliClient.Provider, projectName string) (cliClient.Provider, error) {
cdImage, err := allowToUseProvider(ctx, providerID, projectName)
if err != nil {
return nil, err
canUseReq := defangv1.CanIUseRequest{
Project: projectName,
Provider: providerID.EnumValue(),
}

// provide sane defaults for the CD image
if cdImage == "" {
switch providerID {
case cliClient.ProviderAWS:
cdImage = "public.ecr.aws/defang-io/cd:public-beta"
case cliClient.ProviderDO:
cdImage = "docker.io/defangio/cd:public-beta"
case cliClient.ProviderGCP:
cdImage = "docker.io/defangio/cd:pubilc-gcp-beta"
}
resp, err := client.CanIUse(ctx, &canUseReq)
if err != nil {
return nil, err
}
// Allow local override of the CD image
cdImage = pkg.Getenv("DEFANG_CD_IMAGE", cdImage)
cdImage := pkg.Getenv("DEFANG_CD_IMAGE", resp.CdImage)
provider.SetCDImage(cdImage)

return provider, nil
Expand Down

0 comments on commit 277f901

Please sign in to comment.