From 4ebb18479d4b560950597ad94800a1aa4c22e572 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Feb 2022 01:05:27 +0100 Subject: [PATCH] registry: un-export Session, remove NewSession() It's only used internally for search. Signed-off-by: Sebastiaan van Stijn --- registry/registry_test.go | 10 ++++++---- registry/service.go | 2 +- registry/session.go | 22 ++++++---------------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/registry/registry_test.go b/registry/registry_test.go index 9bed60ca09..184dfe0565 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -16,7 +16,7 @@ import ( "gotest.tools/v3/skip" ) -func spawnTestRegistrySession(t *testing.T) *Session { +func spawnTestRegistrySession(t *testing.T) *session { authConfig := &types.AuthConfig{} endpoint, err := newV1Endpoint(makeIndex("/v1/"), "", nil) if err != nil { @@ -26,10 +26,12 @@ func spawnTestRegistrySession(t *testing.T) *Session { var tr http.RoundTripper = debugTransport{newTransport(nil), t.Log} tr = transport.NewTransport(AuthTransport(tr, authConfig, false), Headers(userAgent, nil)...) client := httpClient(tr) - r, err := NewSession(client, authConfig, endpoint) - if err != nil { + + if err := authorizeClient(client, authConfig, endpoint); err != nil { t.Fatal(err) } + r := newSession(client, endpoint) + // In a normal scenario for the v1 registry, the client should send a `X-Docker-Token: true` // header while authenticating, in order to retrieve a token that can be later used to // perform authenticated actions. @@ -544,7 +546,7 @@ func TestMirrorEndpointLookup(t *testing.T) { func TestSearchRepositories(t *testing.T) { r := spawnTestRegistrySession(t) - results, err := r.SearchRepositories("fakequery", 25) + results, err := r.searchRepositories("fakequery", 25) if err != nil { t.Fatal(err) } diff --git a/registry/service.go b/registry/service.go index 8d85c8a2dc..7903918064 100644 --- a/registry/service.go +++ b/registry/service.go @@ -224,7 +224,7 @@ func (s *defaultService) Search(ctx context.Context, term string, limit int, aut // If pull "library/foo", it's stored locally under "foo" remoteName = strings.TrimPrefix(remoteName, "library/") } - return r.SearchRepositories(remoteName, limit) + return r.searchRepositories(remoteName, limit) } // ResolveRepository splits a repository name into its components diff --git a/registry/session.go b/registry/session.go index 1c3ed5e119..6316b75c43 100644 --- a/registry/session.go +++ b/registry/session.go @@ -21,8 +21,8 @@ import ( "github.com/sirupsen/logrus" ) -// A Session is used to communicate with a V1 registry -type Session struct { +// A session is used to communicate with a V1 registry +type session struct { indexEndpoint *v1Endpoint client *http.Client id string @@ -176,26 +176,16 @@ func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint return nil } -func newSession(client *http.Client, endpoint *v1Endpoint) *Session { - return &Session{ +func newSession(client *http.Client, endpoint *v1Endpoint) *session { + return &session{ client: client, indexEndpoint: endpoint, id: stringid.GenerateRandomID(), } } -// NewSession creates a new session -// TODO(tiborvass): remove authConfig param once registry client v2 is vendored -func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *v1Endpoint) (*Session, error) { - if err := authorizeClient(client, authConfig, endpoint); err != nil { - return nil, err - } - - return newSession(client, endpoint), nil -} - -// SearchRepositories performs a search against the remote repository -func (r *Session) SearchRepositories(term string, limit int) (*registrytypes.SearchResults, error) { +// searchRepositories performs a search against the remote repository +func (r *session) searchRepositories(term string, limit int) (*registrytypes.SearchResults, error) { if limit < 1 || limit > 100 { return nil, errdefs.InvalidParameter(errors.Errorf("Limit %d is outside the range of [1, 100]", limit)) }