registry: un-export Session, remove NewSession()

It's only used internally for search.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-26 01:05:27 +01:00
parent 286992ef53
commit 4ebb18479d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 13 additions and 21 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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))
}