From 983d909b41cada45f7719efbe358089d6128faf7 Mon Sep 17 00:00:00 2001 From: Russel Vela Date: Fri, 31 May 2024 00:52:44 -0600 Subject: [PATCH] feat(cloud-provisioning): Fixes issue with CloudProviderType unknown Fixes an issue whereby not passing a cloud provider type to GetCloudProvider request struct, results in an error due to unknown CloudProviderType. If CloudProviderType is unknown, parameter should be set to nil instead --- .../cloudproviders/cloudproviders.go | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg/webclient/cloudproviders/cloudproviders.go b/pkg/webclient/cloudproviders/cloudproviders.go index 3749fe2e..29f57115 100644 --- a/pkg/webclient/cloudproviders/cloudproviders.go +++ b/pkg/webclient/cloudproviders/cloudproviders.go @@ -31,12 +31,9 @@ func (c *CloudProvidersClient) GetCloudProvider(ctx context.Context, request dom } status := cloudProviderStatusFromDomain(request.Status) - providerType, err := cloudProviderTypeFromDomain(request.Type) - if err != nil { - return nil, err - } + providerType := cloudProviderTypeFromDomain(request.Type) - resp, err := GetCloudProviders(ctx, c.graphqlClient, &status, &providerType, request.Name) + resp, err := GetCloudProviders(ctx, c.graphqlClient, status, providerType, request.Name) if err != nil { return nil, fmt.Errorf("failed to retrieve Cloud Provider with name %s: %w", request.Name, err) } @@ -279,14 +276,16 @@ func (v CloudProviderStatus) toDomain() domain.CloudProviderStatus { } } -func cloudProviderStatusFromDomain(status domain.CloudProviderStatus) CloudProviderStatus { +func cloudProviderStatusFromDomain(status domain.CloudProviderStatus) *CloudProviderStatus { switch status { case domain.CloudProviderStatusValidated: - return CloudProviderStatusValidated + cpStatus := CloudProviderStatusValidated + return &cpStatus case domain.CloudProviderStatusNotValidated: - return CloudProviderStatusNotValidated + cpStatus := CloudProviderStatusNotValidated + return &cpStatus default: - return CloudProviderStatusNotValidated + return nil } } @@ -303,16 +302,19 @@ func (v CloudProviderType) toDomain() domain.CloudProviderType { } } -func cloudProviderTypeFromDomain(providerType domain.CloudProviderType) (CloudProviderType, error) { +func cloudProviderTypeFromDomain(providerType domain.CloudProviderType) *CloudProviderType { switch providerType { case domain.CloudProviderTypeAWS: - return CloudProviderTypeAws, nil + cpType := CloudProviderTypeAws + return &cpType case domain.CloudProviderTypeAzure: - return CloudProviderTypeAzure, nil + cpType := CloudProviderTypeAzure + return &cpType case domain.CloudProviderTypeGCP: - return CloudProviderTypeGcp, nil + cpType := CloudProviderTypeGcp + return &cpType default: - return "UNKNOWN", fmt.Errorf("failed to determine cloud provider type for %s", providerType) + return nil } }