Skip to content

Commit

Permalink
Deprecate transport.New (#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoss committed Jul 19, 2022
1 parent 53e6bea commit f79ec21
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/v1/remote/check.go
Expand Up @@ -24,7 +24,7 @@ func CheckPushPermission(ref name.Reference, kc authn.Keychain, t http.RoundTrip
}

scopes := []string{ref.Scope(transport.PushScope)}
tr, err := transport.New(ref.Context().Registry, auth, t, scopes)
tr, err := transport.NewWithContext(context.TODO(), ref.Context().Registry, auth, t, scopes)
if err != nil {
return fmt.Errorf("creating push check transport for %v failed: %w", ref.Context().Registry, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/v1/remote/transport/transport.go
Expand Up @@ -27,7 +27,7 @@ import (
// setup to authenticate with the remote registry "reg", in the capacity
// laid out by the specified scopes.
//
// TODO(jonjohnsonjr): Deprecate this.
// Deprecated: Use NewWithContext.
func New(reg name.Registry, auth authn.Authenticator, t http.RoundTripper, scopes []string) (http.RoundTripper, error) {
return NewWithContext(context.Background(), reg, auth, t, scopes)
}
Expand Down
40 changes: 20 additions & 20 deletions pkg/v1/remote/transport/transport_test.go
Expand Up @@ -65,9 +65,9 @@ func TestTransportSelectionAnonymous(t *testing.T) {
basic := &authn.Basic{Username: "foo", Password: "bar"}
reg := testReference.Context().Registry

tp, err := New(reg, basic, recorder, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), reg, basic, recorder, []string{testReference.Scope(PullScope)})
if err != nil {
t.Errorf("New() = %v", err)
t.Errorf("NewWithContext() = %v", err)
}

req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/v2/anything", reg), nil)
Expand Down Expand Up @@ -102,14 +102,14 @@ func TestTransportSelectionBasic(t *testing.T) {

basic := &authn.Basic{Username: "foo", Password: "bar"}

tp, err := New(testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
if err != nil {
t.Errorf("New() = %v", err)
t.Errorf("NewWithContext() = %v", err)
}
if tpw, ok := tp.(*Wrapper); !ok {
t.Errorf("New(); got %T, want *Wrapper", tp)
t.Errorf("NewWithContext(); got %T, want *Wrapper", tp)
} else if _, ok := tpw.inner.(*basicTransport); !ok {
t.Errorf("New(); got %T, want *basicTransport", tp)
t.Errorf("NewWithContext(); got %T, want *basicTransport", tp)
}
}

Expand All @@ -132,8 +132,8 @@ func TestTransportBadAuth(t *testing.T) {
},
}

if _, err := New(testReference.Context().Registry, &badAuth{}, tprt, []string{testReference.Scope(PullScope)}); err == nil {
t.Errorf("New() expected err, got nil")
if _, err := NewWithContext(context.Background(), testReference.Context().Registry, &badAuth{}, tprt, []string{testReference.Scope(PullScope)}); err == nil {
t.Errorf("NewWithContext() expected err, got nil")
}
}

Expand Down Expand Up @@ -173,14 +173,14 @@ func TestTransportSelectionBearer(t *testing.T) {
}

basic := &authn.Basic{Username: "foo", Password: "bar"}
tp, err := New(testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
if err != nil {
t.Errorf("New() = %v", err)
t.Errorf("NewWithContext() = %v", err)
}
if tpw, ok := tp.(*Wrapper); !ok {
t.Errorf("New(); got %T, want *Wrapper", tp)
t.Errorf("NewWithContext(); got %T, want *Wrapper", tp)
} else if _, ok := tpw.inner.(*bearerTransport); !ok {
t.Errorf("New(); got %T, want *bearerTransport", tp)
t.Errorf("NewWithContext(); got %T, want *bearerTransport", tp)
}
}

Expand All @@ -198,9 +198,9 @@ func TestTransportSelectionBearerMissingRealm(t *testing.T) {
}

basic := &authn.Basic{Username: "foo", Password: "bar"}
tp, err := New(testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
if err == nil || !strings.Contains(err.Error(), "missing realm") {
t.Errorf("New() = %v, %v", tp, err)
t.Errorf("NewWithContext() = %v, %v", tp, err)
}
}

Expand All @@ -225,9 +225,9 @@ func TestTransportSelectionBearerAuthError(t *testing.T) {
}

basic := &authn.Basic{Username: "foo", Password: "bar"}
tp, err := New(testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
if err == nil {
t.Errorf("New() = %v", tp)
t.Errorf("NewWithContext() = %v", tp)
}
}

Expand All @@ -245,9 +245,9 @@ func TestTransportSelectionUnrecognizedChallenge(t *testing.T) {
}

basic := &authn.Basic{Username: "foo", Password: "bar"}
tp, err := New(testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), testReference.Context().Registry, basic, tprt, []string{testReference.Scope(PullScope)})
if err == nil || !strings.Contains(err.Error(), "challenge") {
t.Errorf("New() = %v, %v", tp, err)
t.Errorf("NewWithContext() = %v, %v", tp, err)
}
}

Expand All @@ -272,9 +272,9 @@ func TestTransportAlwaysTriesHttps(t *testing.T) {
}

basic := &authn.Basic{Username: "foo", Password: "bar"}
tp, err := New(registry, basic, server.Client().Transport, []string{testReference.Scope(PullScope)})
tp, err := NewWithContext(context.Background(), registry, basic, server.Client().Transport, []string{testReference.Scope(PullScope)})
if err != nil {
t.Fatalf("New() = %v, %v", tp, err)
t.Fatalf("NewWithContext() = %v, %v", tp, err)
}
if count == 0 {
t.Errorf("failed to call TLS localhost server")
Expand Down

0 comments on commit f79ec21

Please sign in to comment.