diff --git a/cmd/cluster_install.go b/cmd/cluster_install.go index 0adc7a76..ea0fb2b4 100644 --- a/cmd/cluster_install.go +++ b/cmd/cluster_install.go @@ -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") @@ -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"), @@ -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{}, @@ -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{ diff --git a/go.mod b/go.mod index dce55c46..3eabc3a6 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index f98e811d..d4912ec3 100644 --- a/go.sum +++ b/go.sum @@ -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=