Skip to content

Commit

Permalink
Merge pull request #361 from Qovery/update_api
Browse files Browse the repository at this point in the history
feat: update credentials api
  • Loading branch information
fabienfleureau authored Aug 30, 2024
2 parents 33e4a54 + 7201de9 commit 566b215
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
46 changes: 44 additions & 2 deletions cmd/cluster_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ var clusterInstallCmd = &cobra.Command{
} else {
var items []string
for _, creds := range clusterCreds.Results {
items = append(items, creds.Name)
name, err := GetName(creds)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
}
items = append(items, name)
}
items = append(items, "Create new credentials")

Expand All @@ -274,6 +279,17 @@ var clusterInstallCmd = &cobra.Command{
return clusterCreds.Results[ix]
}()

credentialsId, err := GetId(credentials)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
}
credentialsName, err := GetName(credentials)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
}

selfManagedMode := qovery.KUBERNETESENUM_SELF_MANAGED
clusterRes, resp, err := client.ClustersAPI.CreateCluster(context.Background(), string(organization.ID)).ClusterRequest(qovery.ClusterRequest{
Name: promptForClusterName("my-cluster"),
Expand All @@ -282,7 +298,7 @@ var clusterInstallCmd = &cobra.Command{
Kubernetes: &selfManagedMode,
CloudProviderCredentials: &qovery.ClusterCloudProviderInfoRequest{
CloudProvider: &cloudProviderType,
Credentials: &qovery.ClusterCloudProviderInfoCredentials{Id: &credentials.Id, Name: &credentials.Name},
Credentials: &qovery.ClusterCloudProviderInfoCredentials{Id: &credentialsId, Name: &credentialsName},
Region: clusterRegion,
},
Features: []qovery.ClusterRequestFeaturesInner{},
Expand Down Expand Up @@ -385,6 +401,32 @@ var clusterInstallCmd = &cobra.Command{
},
}

func GetName(creds qovery.ClusterCredentials) (string, error) {
switch castedCreds := creds.GetActualInstance().(type) {
case *qovery.AwsClusterCredentials:
return castedCreds.GetName(), nil
case *qovery.ScalewayClusterCredentials:
return castedCreds.GetName(), nil
case *qovery.GenericClusterCredentials:
return castedCreds.GetName(), nil
default:
return "", errors.New("unknown credentials type")
}
}

func GetId(creds qovery.ClusterCredentials) (string, error) {
switch castedCreds := creds.GetActualInstance().(type) {
case *qovery.AwsClusterCredentials:
return castedCreds.GetId(), nil
case *qovery.ScalewayClusterCredentials:
return castedCreds.GetId(), nil
case *qovery.GenericClusterCredentials:
return castedCreds.GetId(), nil
default:
return "", errors.New("unknown credentials type")
}
}

func createCredentials(client *qovery.APIClient, orgaId string, providerType qovery.CloudProviderEnum) *qovery.ClusterCredentials {
credsName, err := func() *promptui.Prompt {
return &promptui.Prompt{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/posthog/posthog-go v0.0.0-20240327112532-87b23fe11103
github.com/pterm/pterm v0.12.79
github.com/qovery/qovery-client-go v0.0.0-20240722093023-66bc47fd14f7
github.com/qovery/qovery-client-go v0.0.0-20240829125759-9d70b41b65c9
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ github.com/qovery/qovery-client-go v0.0.0-20240722091047-2112666815f8 h1:k4jz1Ie
github.com/qovery/qovery-client-go v0.0.0-20240722091047-2112666815f8/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240722093023-66bc47fd14f7 h1:vQVPYk6DlAE7z48iwiCEcvkoOJO20zS7iaSXtKwkOWc=
github.com/qovery/qovery-client-go v0.0.0-20240722093023-66bc47fd14f7/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240829125759-9d70b41b65c9 h1:Rl08uwi1qnz1NEQPCqagb4RXer0v8c7hXaxeuT3m4Dw=
github.com/qovery/qovery-client-go v0.0.0-20240829125759-9d70b41b65c9/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down

0 comments on commit 566b215

Please sign in to comment.