Skip to content

Commit

Permalink
export UdistributionTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
kaovilai committed May 24, 2022
1 parent c737ac9 commit 21f6dbd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions pkg/image/udistribution/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type udistributionClient struct {
registry string
userAgent string

ut *udistributionTransport
ut *UdistributionTransport

// tlsClientConfig is setup by newDockerClient and will be used and updated
// by detectProperties(). Callers can edit tlsClientConfig.InsecureSkipVerify in the meantime.
Expand Down Expand Up @@ -227,7 +227,7 @@ func newDockerClientFromRef(sys *types.SystemContext, ref udistributionReference
}

registry := reference.Domain(ref.ref)
client, err := newDockerClient(sys, registry, ref.ref.Name(), ref.udistributionTransport)
client, err := newDockerClient(sys, registry, ref.ref.Name(), ref.UdistributionTransport)
if err != nil {
return nil, err
}
Expand All @@ -247,7 +247,7 @@ func newDockerClientFromRef(sys *types.SystemContext, ref udistributionReference
// (e.g., "registry.com[:5000][/some/namespace]/repo").
// Please note that newDockerClient does not set all members of udistributionClient
// (e.g., username and password); those must be set by callers if necessary.
func newDockerClient(sys *types.SystemContext, registry, reference string, ut *udistributionTransport) (*udistributionClient, error) {
func newDockerClient(sys *types.SystemContext, registry, reference string, ut *UdistributionTransport) (*udistributionClient, error) {
hostName := registry
if registry == dockerHostname {
registry = dockerRegistry
Expand Down Expand Up @@ -301,7 +301,7 @@ func newDockerClient(sys *types.SystemContext, registry, reference string, ut *u
// returns an error if an error occurred while making the http request or the status code received was 401
func CheckAuth(ctx context.Context, sys *types.SystemContext, username, password, registry string) error {
var (
ut *udistributionTransport
ut *UdistributionTransport
err error
)
if username == "" && password == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/udistribution/docker_image_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (d *dockerImageDestination) blobExists(ctx context.Context, repo reference.
checkPath := fmt.Sprintf(blobsPath, reference.Path(repo), digest.String())
logrus.Debugf("Checking %s", checkPath)
if d.c.ut == nil || d.c.ut.Client == nil {
d.c.ut = d.ref.udistributionTransport
d.c.ut = d.ref.UdistributionTransport
}
res, err := d.c.makeRequest(ctx, http.MethodHead, checkPath, nil, nil, v2Auth, extraScope)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/udistribution/docker_image_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func newImageSource(ctx context.Context, sys *types.SystemContext, ref udistribu
// Given a logicalReference and a pullSource, return a udistributionImageSource if it is reachable.
// The caller must call .Close() on the returned ImageSource.
func newImageSourceAttempt(ctx context.Context, sys *types.SystemContext, logicalRef udistributionReference, pullSource sysregistriesv2.PullSource) (*udistributionImageSource, error) {
physicalRef, err := newReference(pullSource.Reference, logicalRef.udistributionTransport)
physicalRef, err := newReference(pullSource.Reference, logicalRef.UdistributionTransport)
if err != nil {
return nil, err
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/image/udistribution/docker_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import (
// }

// Transport is an ImageTransport for container registry-hosted images.
// var Transport = udistributionTransport{}
// var Transport = UdistributionTransport{}

type udistributionTransport struct {
type UdistributionTransport struct {
*client.Client
name string
uuid string
}

// Create new transport and register.
// When you are done with this transport, use Deregister() to unregister it from available transports.
func NewTransport(client *client.Client, name string) *udistributionTransport {
t := udistributionTransport{
func NewTransport(client *client.Client, name string) *UdistributionTransport {
t := UdistributionTransport{
Client: client,
name: name,
uuid: uuid.Generate().String(),
Expand All @@ -47,12 +47,12 @@ func NewTransport(client *client.Client, name string) *udistributionTransport {

// Create new transport with client params and register.
// When you are done with this transport, use Deregister() to unregister it from available transports.
func NewTransportFromNewConfig(config string, env []string) (*udistributionTransport, error) {
func NewTransportFromNewConfig(config string, env []string) (*UdistributionTransport, error) {
c, err := client.NewClient(config, env)
if err != nil {
return nil, err
}
t := udistributionTransport{
t := UdistributionTransport{
Client: c,
name: c.GetApp().Config.Storage.Type(),
uuid: uuid.Generate().String(),
Expand All @@ -63,24 +63,24 @@ func NewTransportFromNewConfig(config string, env []string) (*udistributionTrans
return &t, nil
}

func (u udistributionTransport) Deregister() {
func (u UdistributionTransport) Deregister() {
transports.Delete(u.Name())
}

func (t udistributionTransport) Name() string {
func (t UdistributionTransport) Name() string {
return constants.TransportPrefix + t.name + ":" + t.uuid
}

// ParseReference converts a string, which should not start with the ImageTransport.Name prefix, into an ImageReference.
func (t udistributionTransport) ParseReference(reference string) (types.ImageReference, error) {
func (t UdistributionTransport) ParseReference(reference string) (types.ImageReference, error) {
return ParseReference(reference, &t)
}

// ValidatePolicyConfigurationScope checks that scope is a valid name for a signature.PolicyTransportScopes keys
// (i.e. a valid PolicyConfigurationIdentity() or PolicyConfigurationNamespaces() return value).
// It is acceptable to allow an invalid value which will never be matched, it can "only" cause user confusion.
// scope passed to this function will not be "", that value is always allowed.
func (t udistributionTransport) ValidatePolicyConfigurationScope(scope string) error {
func (t UdistributionTransport) ValidatePolicyConfigurationScope(scope string) error {
// FIXME? We could be verifying the various character set and length restrictions
// from docker/distribution/reference.regexp.go, but other than that there
// are few semantically invalid strings.
Expand All @@ -90,7 +90,7 @@ func (t udistributionTransport) ValidatePolicyConfigurationScope(scope string) e
// udistributionReference is an ImageReference for Docker images.
type udistributionReference struct {
ref reference.Named // By construction we know that !reference.IsNameOnly(ref)
*udistributionTransport
*UdistributionTransport
}

// for test
Expand All @@ -99,7 +99,7 @@ func GetRef(ir types.ImageReference) reference.Named {
}

// ParseReference converts a string, which should not start with the ImageTransport.Name prefix, into an Docker ImageReference.
func ParseReference(refString string, ut *udistributionTransport) (types.ImageReference, error) {
func ParseReference(refString string, ut *UdistributionTransport) (types.ImageReference, error) {
if !strings.HasPrefix(refString, "//") {
return nil, errors.Errorf("docker: image reference %s does not start with //", refString)
}
Expand All @@ -112,12 +112,12 @@ func ParseReference(refString string, ut *udistributionTransport) (types.ImageRe
}

// NewReference returns a Docker reference for a named reference. The reference must satisfy !reference.IsNameOnly().
func NewReference(ref reference.Named, ut *udistributionTransport) (types.ImageReference, error) {
func NewReference(ref reference.Named, ut *UdistributionTransport) (types.ImageReference, error) {
return newReference(ref, ut)
}

// newReference returns a udistributionReference for a named reference.
func newReference(ref reference.Named, ut *udistributionTransport) (udistributionReference, error) {
func newReference(ref reference.Named, ut *UdistributionTransport) (udistributionReference, error) {
if ut == nil {
return udistributionReference{}, errors.Errorf("image reference is invalid: missing transport")
}
Expand All @@ -136,12 +136,12 @@ func newReference(ref reference.Named, ut *udistributionTransport) (udistributio
}
return udistributionReference{
ref: ref,
udistributionTransport: ut,
UdistributionTransport: ut,
}, nil
}

func (ref udistributionReference) Transport() types.ImageTransport {
return ref.udistributionTransport
return ref.UdistributionTransport
}

// StringWithinTransport returns a string representation of the reference, which MUST be such that
Expand Down
4 changes: 2 additions & 2 deletions pkg/image/udistribution/docker_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (

var (
testTransport types.ImageTransport
testUdistributionTransport udistributionTransport
testUdistributionTransport UdistributionTransport
)

func init() {
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestTransportValidatePolicyConfigurationScope(t *testing.T) {
}
}

// Parse Reference is expected to be incompatible because it isn't meant to be used externally without udistributionTransport initialized.
// Parse Reference is expected to be incompatible because it isn't meant to be used externally without UdistributionTransport initialized.
// func TestParseReference(t *testing.T) {
// testParseReference(t, ParseReference)
// }
Expand Down

0 comments on commit 21f6dbd

Please sign in to comment.