Skip to content

Commit 491e8fd

Browse files
committed
cli/registry/client: skip RepositoryInfo as intermediate
Remove RepositoryInfo as intermediate struct in some places; we want to remove the use of this additional abstration. More changes are needed to fully remove it, but chipping away its use in small bits. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 930173a commit 491e8fd

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

cli/registry/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Na
147147

148148
func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoint repositoryEndpoint) (http.RoundTripper, error) {
149149
httpTransport, err := getHTTPTransport(
150-
c.authConfigResolver(ctx, repoEndpoint.info.Index),
150+
c.authConfigResolver(ctx, repoEndpoint.indexInfo),
151151
repoEndpoint.endpoint,
152152
repoEndpoint.Name(),
153153
c.userAgent,

cli/registry/client/endpoint.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import (
1414
)
1515

1616
type repositoryEndpoint struct {
17-
info *registry.RepositoryInfo
18-
endpoint registry.APIEndpoint
19-
actions []string
17+
repoName reference.Named
18+
indexInfo *registrytypes.IndexInfo
19+
endpoint registry.APIEndpoint
20+
actions []string
2021
}
2122

2223
// Name returns the repository name
2324
func (r repositoryEndpoint) Name() string {
24-
return reference.Path(r.info.Name)
25+
return reference.Path(r.repoName)
2526
}
2627

2728
// BaseURL returns the endpoint url
@@ -30,32 +31,36 @@ func (r repositoryEndpoint) BaseURL() string {
3031
}
3132

3233
func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) {
34+
repoName := reference.TrimNamed(ref)
3335
repoInfo, _ := registry.ParseRepositoryInfo(ref)
34-
endpoint, err := getDefaultEndpointFromRepoInfo(repoInfo)
36+
indexInfo := repoInfo.Index
37+
38+
endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure)
3539
if err != nil {
3640
return repositoryEndpoint{}, err
3741
}
3842
if insecure {
3943
endpoint.TLSConfig.InsecureSkipVerify = true
4044
}
41-
return repositoryEndpoint{info: repoInfo, endpoint: endpoint}, nil
45+
return repositoryEndpoint{
46+
repoName: repoName,
47+
indexInfo: indexInfo,
48+
endpoint: endpoint,
49+
}, nil
4250
}
4351

44-
func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry.APIEndpoint, error) {
45-
var err error
46-
47-
options := registry.ServiceOptions{}
48-
registryService, err := registry.NewService(options)
52+
func getDefaultEndpoint(repoName reference.Named, insecure bool) (registry.APIEndpoint, error) {
53+
registryService, err := registry.NewService(registry.ServiceOptions{})
4954
if err != nil {
5055
return registry.APIEndpoint{}, err
5156
}
52-
endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoInfo.Name))
57+
endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoName))
5358
if err != nil {
5459
return registry.APIEndpoint{}, err
5560
}
5661
// Default to the highest priority endpoint to return
5762
endpoint := endpoints[0]
58-
if !repoInfo.Index.Secure {
63+
if insecure {
5964
for _, ep := range endpoints {
6065
if ep.URL.Scheme == "http" {
6166
endpoint = ep

cli/registry/client/fetcher.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
220220
return err
221221
}
222222

223+
repoName := reference.TrimNamed(namedRef)
223224
repoInfo, _ := registry.ParseRepositoryInfo(namedRef)
225+
indexInfo := repoInfo.Index
224226

225227
confirmedTLSRegistries := make(map[string]bool)
226228
for _, endpoint := range endpoints {
@@ -234,7 +236,11 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
234236
if c.insecureRegistry {
235237
endpoint.TLSConfig.InsecureSkipVerify = true
236238
}
237-
repoEndpoint := repositoryEndpoint{endpoint: endpoint, info: repoInfo}
239+
repoEndpoint := repositoryEndpoint{
240+
repoName: repoName,
241+
indexInfo: indexInfo,
242+
endpoint: endpoint,
243+
}
238244
repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint)
239245
if err != nil {
240246
logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint)

0 commit comments

Comments
 (0)