Skip to content

Commit

Permalink
Merge pull request #21 from Hsn723/ISSUE-20
Browse files Browse the repository at this point in the history
use header supporting OCI indices
  • Loading branch information
Hsn723 authored Feb 20, 2023
2 parents e9b53f3 + ff2b27f commit 4317ec1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ type platform struct {
Os string `json:"os"`
}

func (r RegistryClient) retrieve(method, endpoint, auth string) (int, []byte, error) {
func (r RegistryClient) retrieve(method, endpoint string, headers map[string]string) (int, []byte, error) {
req, err := http.NewRequest(method, endpoint, nil)
if err != nil {
return -1, nil, err
}
req.Header.Add("Authorization", auth)
for k, v := range headers {
req.Header.Add(k, v)
}
res, err := r.HttpClient.Do(req)
if err != nil {
return -1, nil, err
Expand All @@ -70,7 +72,10 @@ func (r RegistryClient) retrieveBearerToken(auth string) (string, error) {
} else {
endpoint = fmt.Sprintf(authAPI, r.RegistryURL, r.ImagePath)
}
status, res, err := r.retrieve(http.MethodGet, endpoint, fmt.Sprintf("Basic %s", auth))
headers := map[string]string{
"Authorization": fmt.Sprintf("Basic %s", auth),
}
status, res, err := r.retrieve(http.MethodGet, endpoint, headers)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -109,15 +114,17 @@ func (r RegistryClient) hasPlatforms(res []byte) (bool, error) {

func (r RegistryClient) checkManifestForTag(bearer, tag string) (bool, error) {
endpoint := fmt.Sprintf(manifestAPI, r.RegistryURL, r.ImagePath, tag)
auth := ""
headers := map[string]string{
"Accept": "application/vnd.oci.image.index.v1+json",
}
if bearer != "" {
auth = fmt.Sprintf("Bearer %s", bearer)
headers["Authorization"] = fmt.Sprintf("Bearer %s", bearer)
}
method := http.MethodHead
if r.Platforms != nil {
method = http.MethodGet
}
status, res, err := r.retrieve(method, endpoint, auth)
status, res, err := r.retrieve(method, endpoint, headers)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 4317ec1

Please sign in to comment.