Skip to content

Commit ff6d8cb

Browse files
committed
refactor: remove AuthenticatedClient and move code to Client
1 parent 50aa6e7 commit ff6d8cb

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

internal/registry/registry.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ type Client struct {
2929
insecureRegistries []string
3030
rootCAs *x509.CertPool
3131
timeout time.Duration
32-
}
33-
34-
type AuthenticatedClient struct {
35-
*Client
36-
pullSecrets []corev1.Secret
32+
pullSecrets []corev1.Secret
3733
}
3834

3935
func NewClient(insecureRegistries []string, rootCAs *x509.CertPool) *Client {
@@ -56,16 +52,14 @@ func (c *Client) WithTimeout(timeout time.Duration) *Client {
5652
return c
5753
}
5854

59-
func (c *Client) WithPullSecrets(pullSecrets []corev1.Secret) *AuthenticatedClient {
60-
return &AuthenticatedClient{
61-
Client: c,
62-
pullSecrets: pullSecrets,
63-
}
55+
func (c *Client) WithPullSecrets(pullSecrets []corev1.Secret) *Client {
56+
c.pullSecrets = pullSecrets
57+
return c
6458
}
6559

6660
// Execute execute a callback with authentication with options including authentication and optional timeout
67-
func (a *AuthenticatedClient) Execute(imageName string, action func(ref name.Reference, opts ...remote.Option) error) error {
68-
keychains, err := GetKeychains(imageName, a.pullSecrets)
61+
func (c *Client) Execute(imageName string, action func(ref name.Reference, opts ...remote.Option) error) error {
62+
keychains, err := GetKeychains(imageName, c.pullSecrets)
6963
if err != nil {
7064
return err
7165
}
@@ -77,16 +71,16 @@ func (a *AuthenticatedClient) Execute(imageName string, action func(ref name.Ref
7771

7872
ctx := context.Background()
7973

80-
if a.timeout > 0 {
74+
if c.timeout > 0 {
8175
// global timeout for all keychains
8276
var cancel func()
83-
ctx, cancel = context.WithTimeout(ctx, a.timeout)
77+
ctx, cancel = context.WithTimeout(ctx, c.timeout)
8478
defer func() {
8579
cancel()
8680
}()
8781
}
8882

89-
options := a.options(ctx, sourceRef)
83+
options := c.options(ctx, sourceRef)
9084

9185
if len(keychains) == 0 {
9286
keychains = append(keychains, authn.DefaultKeychain)
@@ -107,24 +101,24 @@ func (a *AuthenticatedClient) Execute(imageName string, action func(ref name.Ref
107101
return errors.Join(errs...)
108102
}
109103

110-
func (a *AuthenticatedClient) ReadDescriptor(httpMethod string, imageName string) (*v1.Descriptor, error) {
104+
func (c *Client) ReadDescriptor(httpMethod string, imageName string) (*v1.Descriptor, error) {
111105
var desc *v1.Descriptor
112-
return desc, a.Execute(imageName, func(ref name.Reference, opts ...remote.Option) (err error) {
106+
return desc, c.Execute(imageName, func(ref name.Reference, opts ...remote.Option) (err error) {
113107
desc, err = getReader(httpMethod)(ref, opts...)
114108
return err
115109
})
116110
}
117111

118-
func (a *AuthenticatedClient) GetDescriptor(imageName string) (*remote.Descriptor, error) {
112+
func (c *Client) GetDescriptor(imageName string) (*remote.Descriptor, error) {
119113
var desc *remote.Descriptor
120-
return desc, a.Execute(imageName, func(ref name.Reference, opts ...remote.Option) (err error) {
114+
return desc, c.Execute(imageName, func(ref name.Reference, opts ...remote.Option) (err error) {
121115
desc, err = remote.Get(ref, opts...)
122116
return err
123117
})
124118
}
125119

126-
func (a *AuthenticatedClient) CopyImage(src *remote.Descriptor, dest string, architectures []string) error {
127-
return a.Execute(dest, func(destRef name.Reference, opts ...remote.Option) (err error) {
120+
func (c *Client) CopyImage(src *remote.Descriptor, dest string, architectures []string) error {
121+
return c.Execute(dest, func(destRef name.Reference, opts ...remote.Option) (err error) {
128122
switch src.MediaType {
129123
case types.OCIImageIndex, types.DockerManifestList:
130124
index, err := src.ImageIndex()

0 commit comments

Comments
 (0)