Skip to content

Commit

Permalink
Refactoring for list deployments (#1205)
Browse files Browse the repository at this point in the history
* Refactoring for list deployments

* Movings calls to single function

* Correcting variable name
  • Loading branch information
kushalmalani committed May 18, 2023
1 parent f5847ce commit 783ec69
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
23 changes: 13 additions & 10 deletions cloud/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func List(ws string, all bool, client astro.Client, out io.Writer) error {
ws = ""
tab = newTableOutAll()
}
deployments, err := client.ListDeployments(c.Organization, ws)
deployments, err := GetDeployments(ws, c.Organization, client)
if err != nil {
return errors.Wrap(err, astro.AstronomerConnectionErrMsg)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func Create(label, workspaceID, description, clusterID, runtimeVersion, dagDeplo
if label == "" {
return errors.New("you must give your Deployment a name")
}
deployments, err := GetDeployments(workspaceID, client)
deployments, err := GetDeployments(workspaceID, organizationID, client)
if err != nil {
return errors.Wrap(err, errInvalidDeployment.Error())
}
Expand Down Expand Up @@ -549,7 +549,7 @@ func healthPoll(deploymentID, ws string, client astro.Client) error {
// Got a tick, we should check if deployment is healthy
case <-ticker.C:
buf.Reset()
deployments, err := GetDeployments(ws, client)
deployments, err := GetDeployments(ws, "", client)
if err != nil {
return err
}
Expand Down Expand Up @@ -745,13 +745,16 @@ func Delete(deploymentID, ws, deploymentName string, forceDelete bool, client as
return nil
}

var GetDeployments = func(ws string, client astro.Client) ([]astro.Deployment, error) {
c, err := config.GetCurrentContext()
if err != nil {
return []astro.Deployment{}, err
var GetDeployments = func(ws, org string, client astro.Client) ([]astro.Deployment, error) {
if org == "" {
c, err := config.GetCurrentContext()
if err != nil {
return []astro.Deployment{}, err
}
org = c.Organization
}

deployments, err := client.ListDeployments(c.Organization, ws)
deployments, err := client.ListDeployments(org, ws)
if err != nil {
return deployments, errors.Wrap(err, astro.AstronomerConnectionErrMsg)
}
Expand Down Expand Up @@ -805,7 +808,7 @@ var SelectDeployment = func(deployments []astro.Deployment, message string) (ast
}

func GetDeployment(ws, deploymentID, deploymentName string, client astro.Client, coreClient astrocore.CoreClient) (astro.Deployment, error) {
deployments, err := GetDeployments(ws, client)
deployments, err := GetDeployments(ws, "", client)
if err != nil {
return astro.Deployment{}, errors.Wrap(err, errInvalidDeployment.Error())
}
Expand Down Expand Up @@ -879,7 +882,7 @@ func deploymentSelectionProcess(ws string, deployments []astro.Deployment, clien
}

// get a new deployment list
deployments, err = GetDeployments(ws, client)
deployments, err = GetDeployments(ws, "", client)
if err != nil {
return astro.Deployment{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/deployment/fromfile/fromfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func CreateOrUpdate(inputFile, action string, client astro.Client, out io.Writer
return err
}

existingDeployments, err = client.ListDeployments(c.Organization, workspaceID)
existingDeployments, err = deployment.GetDeployments(workspaceID, c.Organization, client)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cloud/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
astro "github.com/astronomer/astro-cli/astro-client"
astrocore "github.com/astronomer/astro-cli/astro-client-core"
"github.com/astronomer/astro-cli/cloud/auth"
"github.com/astronomer/astro-cli/cloud/deployment"
"github.com/astronomer/astro-cli/cloud/organization"
"github.com/astronomer/astro-cli/context"
"github.com/astronomer/astro-cli/pkg/httputil"
Expand Down Expand Up @@ -324,7 +325,7 @@ func checkAPIKeys(astroClient astro.Client, coreClient astrocore.CoreClient, isD
orgProduct := fmt.Sprintf("%s", *org.Product) //nolint

// get workspace ID
deployments, err := astroClient.ListDeployments(orgID, "")
deployments, err := deployment.GetDeployments("", orgID, astroClient)
if err != nil {
return false, errors.Wrap(err, astro.AstronomerConnectionErrMsg)
}
Expand Down

0 comments on commit 783ec69

Please sign in to comment.