Create client transport package

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2015-05-15 16:50:17 -07:00
parent 94e375c5d1
commit 2874454224
7 changed files with 17 additions and 10 deletions

View file

@ -18,16 +18,17 @@ import (
"github.com/docker/distribution" "github.com/docker/distribution"
"github.com/docker/distribution/context" "github.com/docker/distribution/context"
"github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/api/v2"
"github.com/docker/distribution/registry/client/transport"
"github.com/docker/distribution/registry/storage/cache" "github.com/docker/distribution/registry/storage/cache"
) )
// NewRepository creates a new Repository for the given repository name and endpoint // NewRepository creates a new Repository for the given repository name and base URL
func NewRepository(ctx context.Context, name, endpoint string, transport http.RoundTripper) (distribution.Repository, error) { func NewRepository(ctx context.Context, name, baseURL string, transport http.RoundTripper) (distribution.Repository, error) {
if err := v2.ValidateRespositoryName(name); err != nil { if err := v2.ValidateRespositoryName(name); err != nil {
return nil, err return nil, err
} }
ub, err := v2.NewURLBuilderFromString(endpoint) ub, err := v2.NewURLBuilderFromString(baseURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -292,7 +293,7 @@ func (ls *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.Rea
return nil, err return nil, err
} }
return NewHTTPReadSeeker(ls.repository.client, blobURL, stat.Length), nil return transport.NewHTTPReadSeeker(ls.repository.client, blobURL, stat.Length), nil
} }
func (ls *blobs) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error { func (ls *blobs) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error {

View file

@ -1,4 +1,4 @@
package client package transport
import ( import (
"net/http" "net/http"

View file

@ -1,4 +1,4 @@
package client package transport
import ( import (
"net/http" "net/http"

View file

@ -1,4 +1,4 @@
package client package transport
import ( import (
"bufio" "bufio"

View file

@ -1,4 +1,4 @@
package client package transport
import ( import (
"encoding/json" "encoding/json"

View file

@ -1,4 +1,4 @@
package client package transport
import ( import (
"encoding/base64" "encoding/base64"
@ -11,6 +11,12 @@ import (
"github.com/docker/distribution/testutil" "github.com/docker/distribution/testutil"
) )
func testServer(rrm testutil.RequestResponseMap) (string, func()) {
h := testutil.NewHandler(rrm)
s := httptest.NewServer(h)
return s.URL, s.Close
}
type testAuthenticationWrapper struct { type testAuthenticationWrapper struct {
headers http.Header headers http.Header
authCheck func(string) bool authCheck func(string) bool

View file

@ -1,4 +1,4 @@
package client package transport
import ( import (
"io" "io"