Skip to content

Commit

Permalink
feat(cloud-provisioning): Fixes issue with CloudProviderType unknown
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rvelaVenafi committed May 31, 2024
1 parent 9a6c6b0 commit 983d909
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions pkg/webclient/cloudproviders/cloudproviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand Down

0 comments on commit 983d909

Please sign in to comment.