mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
parent
286992ef53
commit
4ebb18479d
3 changed files with 13 additions and 21 deletions
|
@ -16,7 +16,7 @@ import (
|
||||||
"gotest.tools/v3/skip"
|
"gotest.tools/v3/skip"
|
||||||
)
|
)
|
||||||
|
|
||||||
func spawnTestRegistrySession(t *testing.T) *Session {
|
func spawnTestRegistrySession(t *testing.T) *session {
|
||||||
authConfig := &types.AuthConfig{}
|
authConfig := &types.AuthConfig{}
|
||||||
endpoint, err := newV1Endpoint(makeIndex("/v1/"), "", nil)
|
endpoint, err := newV1Endpoint(makeIndex("/v1/"), "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,10 +26,12 @@ func spawnTestRegistrySession(t *testing.T) *Session {
|
||||||
var tr http.RoundTripper = debugTransport{newTransport(nil), t.Log}
|
var tr http.RoundTripper = debugTransport{newTransport(nil), t.Log}
|
||||||
tr = transport.NewTransport(AuthTransport(tr, authConfig, false), Headers(userAgent, nil)...)
|
tr = transport.NewTransport(AuthTransport(tr, authConfig, false), Headers(userAgent, nil)...)
|
||||||
client := httpClient(tr)
|
client := httpClient(tr)
|
||||||
r, err := NewSession(client, authConfig, endpoint)
|
|
||||||
if err != nil {
|
if err := authorizeClient(client, authConfig, endpoint); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
r := newSession(client, endpoint)
|
||||||
|
|
||||||
// In a normal scenario for the v1 registry, the client should send a `X-Docker-Token: true`
|
// 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
|
// header while authenticating, in order to retrieve a token that can be later used to
|
||||||
// perform authenticated actions.
|
// perform authenticated actions.
|
||||||
|
@ -544,7 +546,7 @@ func TestMirrorEndpointLookup(t *testing.T) {
|
||||||
|
|
||||||
func TestSearchRepositories(t *testing.T) {
|
func TestSearchRepositories(t *testing.T) {
|
||||||
r := spawnTestRegistrySession(t)
|
r := spawnTestRegistrySession(t)
|
||||||
results, err := r.SearchRepositories("fakequery", 25)
|
results, err := r.searchRepositories("fakequery", 25)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
// If pull "library/foo", it's stored locally under "foo"
|
||||||
remoteName = strings.TrimPrefix(remoteName, "library/")
|
remoteName = strings.TrimPrefix(remoteName, "library/")
|
||||||
}
|
}
|
||||||
return r.SearchRepositories(remoteName, limit)
|
return r.searchRepositories(remoteName, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveRepository splits a repository name into its components
|
// ResolveRepository splits a repository name into its components
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Session is used to communicate with a V1 registry
|
// A session is used to communicate with a V1 registry
|
||||||
type Session struct {
|
type session struct {
|
||||||
indexEndpoint *v1Endpoint
|
indexEndpoint *v1Endpoint
|
||||||
client *http.Client
|
client *http.Client
|
||||||
id string
|
id string
|
||||||
|
@ -176,26 +176,16 @@ func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSession(client *http.Client, endpoint *v1Endpoint) *Session {
|
func newSession(client *http.Client, endpoint *v1Endpoint) *session {
|
||||||
return &Session{
|
return &session{
|
||||||
client: client,
|
client: client,
|
||||||
indexEndpoint: endpoint,
|
indexEndpoint: endpoint,
|
||||||
id: stringid.GenerateRandomID(),
|
id: stringid.GenerateRandomID(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSession creates a new session
|
// searchRepositories performs a search against the remote repository
|
||||||
// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
|
func (r *session) searchRepositories(term string, limit int) (*registrytypes.SearchResults, error) {
|
||||||
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) {
|
|
||||||
if limit < 1 || limit > 100 {
|
if limit < 1 || limit > 100 {
|
||||||
return nil, errdefs.InvalidParameter(errors.Errorf("Limit %d is outside the range of [1, 100]", limit))
|
return nil, errdefs.InvalidParameter(errors.Errorf("Limit %d is outside the range of [1, 100]", limit))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue