Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address deprecations and dead code #71

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/arch/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"net/http"
"slices"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -633,7 +632,7 @@ func keys(set map[string]struct{}) []string {
for k := range set {
r = append(r, k)
}
sort.Sort(sort.StringSlice(r))
slices.Sort(r)
return r
}

Expand Down
36 changes: 0 additions & 36 deletions pkg/registry/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -228,41 +227,6 @@ func (r RegistryAuthenticator) getAuthCandidates(ctx context.Context, cfg Docker
return candidates
}

// TODO: change to handle www-authenticate for HTTP/1.1 401 Unauthorized responses
// Www-Authenticate: Bearer realm="https://ghcr.io/token",service="ghcr.io",scope="repository:user/image:pull"
// Www-Authenticate: Bearer realm="https://auth.ipv6.docker.com/token",service="registry.docker.io"
func getDockerHubToken(ctx context.Context, registry, image, tag, token string) string {
authHost := registry
if authHost == "docker.io" {
authHost = "auth.docker.io"
registry = "registry." + registry
}

req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/token?service=%s&scope=repository:%s:pull", authHost, registry, image), nil)
if err != nil {
return token
}
req = req.WithContext(ctx)
if token != "" {
req.Header.Set("Authorization", "Basic "+token)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return ""
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return ""
}
authResponse := registryAuthResponse{}
err = json.NewDecoder(resp.Body).Decode(&authResponse)
if err != nil {
return ""
}
return authResponse.Token
}

func (r RegistryAuthenticator) tryAllCandidates(ctx context.Context, cfg DockerConfig, registry, image, tag string, candidates chan AuthenticationToken) {
for auth := range r.getAuthCandidates(ctx, cfg, registry, image) {
select {
Expand Down
14 changes: 7 additions & 7 deletions pkg/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package registry
import (
"context"
"encoding/base64"
"io/ioutil"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestListArchsWithAuthenticationAndManifestListV2(t *testing.T) {
assert.Equal(t, "repository:my/image:pull", req.URL.Query().Get("scope"))
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(`{"token":"my-token"}`)),
Body: io.NopCloser(strings.NewReader(`{"token":"my-token"}`)),
}, nil
case "registry.company.corp":
switch req.URL.Path {
Expand All @@ -184,7 +184,7 @@ func TestListArchsWithAuthenticationAndManifestListV2(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: headers,
Body: ioutil.NopCloser(strings.NewReader(`{
Body: io.NopCloser(strings.NewReader(`{
"manifests":[
{
"platform":{
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestListArchsWithAuthenticationAndManifestIndexV1(t *testing.T) {
assert.Equal(t, "repository:my/image:pull", req.URL.Query().Get("scope"))
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(`{"token":"my-token"}`)),
Body: io.NopCloser(strings.NewReader(`{"token":"my-token"}`)),
}, nil
case "registry.company.corp":
switch req.URL.Path {
Expand All @@ -259,7 +259,7 @@ func TestListArchsWithAuthenticationAndManifestIndexV1(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: headers,
Body: ioutil.NopCloser(strings.NewReader(`{
Body: io.NopCloser(strings.NewReader(`{
"manifests":[
{
"platform":{
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestListArchsWithAuthenticationAndPlainManifest(t *testing.T) {
assert.Equal(t, "repository:my/image:pull", req.URL.Query().Get("scope"))
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(`{"token":"my-token"}`)),
Body: io.NopCloser(strings.NewReader(`{"token":"my-token"}`)),
}, nil
case "registry.company.corp":
switch req.URL.Path {
Expand All @@ -339,7 +339,7 @@ func TestListArchsWithAuthenticationAndPlainManifest(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Header: headers,
Body: ioutil.NopCloser(strings.NewReader(`{
Body: io.NopCloser(strings.NewReader(`{
"architecture": "amd64"
}`)),
}, nil
Expand Down
Loading