-
Story
-
Resolution: Unresolved
-
Undefined
-
None
-
None
-
None
-
Future Sustainability
-
False
-
-
False
-
None
-
None
-
None
openshift/oc-mirror relies on the now internal registry/client package from distribution/v3.
It imports github.com/distribution/distribution/v3/registry/client/auth to make use of api version parsing from response headers via auth.APIVersions(resp, "Docker-Distribution-API-Version") (source https://github.com/openshift/oc-mirror/blame/573ebe02729dc7c775c81a1722430c41c033da5a/pkg/metadata/storage/registry.go#L313 ).
auth.APIVersions is a generic function to parse the HTTP header provided and it's implementation can be brought into the caller.
This is the function in its entirety (source https://github.com/distribution/distribution/blob/a44f1fb058533f3f840037ebf29c0fea377ebbc6/internal/client/auth/api_version.go#L26-L38 ):
// APIVersions gets the API versions out of an HTTP response using the provided // version header as the key for the HTTP header. func APIVersions(resp *http.Response, versionHeader string) []APIVersion { versions := []APIVersion{} if versionHeader != "" { for _, supportedVersions := range resp.Header[http.CanonicalHeaderKey(versionHeader)] { for _, version := range strings.Fields(supportedVersions) { versions = append(versions, ParseAPIVersion(version)) } } } return versions }
It can be simplified so it doesn't rely in any distribution specific types. Something like:
// APIVersions gets the API versions out of an HTTP response using the provided // version header as the key for the HTTP header. func APIVersions(resp *http.Response, versionHeader string) []string { versions := []string{} if versionHeader != "" { for _, supportedVersions := range resp.Header[http.CanonicalHeaderKey(versionHeader)] { for _, version := range strings.Fields(supportedVersions) { versions = append(versions, version) } } } return versions }