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"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue