Skip to content

Commit

Permalink
fix cutting provider with hyphen in name
Browse files Browse the repository at this point in the history
  • Loading branch information
njuettner committed Nov 7, 2024
1 parent b760161 commit 76b8f83
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions sdk/api/v1alpha1/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,12 @@ func (r *Release) LookupComponentSpec(appName string) (ReleaseSpecComponent, boo
}

func (r *Release) getResourceNameParts() (Provider, string, error) {
lastHyphenIndex := strings.LastIndex(r.Name, "-")
if lastHyphenIndex == -1 {
return "", "", microerror.Maskf(InvalidReleaseResourceNameError, "Release resource must be in format '{provider}-{version}', but '-' is not found in '%s'.", r.Name)
}

providerString := r.Name[:lastHyphenIndex]
releaseVersion := r.Name[lastHyphenIndex+1:]

provider := Provider(providerString)

if !IsProviderSupported(provider) {
return "", "", microerror.Maskf(UnsupportedProviderError, "Provider '%s' is not supported. Supported providers are: %s.", provider, SupportedProviders)
for _, provider := range SupportedProviders {
prefix := string(provider) + "-"
if strings.HasPrefix(r.Name, prefix) {
releaseVersion := strings.TrimPrefix(r.Name, prefix)
return provider, releaseVersion, nil
}
}

releaseVersion = strings.TrimPrefix(releaseVersion, "v")
return provider, releaseVersion, nil
return "", "", microerror.Maskf(UnsupportedProviderError, "Provider '%s' is not supported. Supported providers are: %s.", r.Name, SupportedProviders)
}

0 comments on commit 76b8f83

Please sign in to comment.