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>
This commit is contained in:
parent
930173a2ab
commit
491e8fdaf8
@ -147,7 +147,7 @@ func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Na
|
||||
|
||||
func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoint repositoryEndpoint) (http.RoundTripper, error) {
|
||||
httpTransport, err := getHTTPTransport(
|
||||
c.authConfigResolver(ctx, repoEndpoint.info.Index),
|
||||
c.authConfigResolver(ctx, repoEndpoint.indexInfo),
|
||||
repoEndpoint.endpoint,
|
||||
repoEndpoint.Name(),
|
||||
c.userAgent,
|
||||
|
@ -14,14 +14,15 @@ import (
|
||||
)
|
||||
|
||||
type repositoryEndpoint struct {
|
||||
info *registry.RepositoryInfo
|
||||
endpoint registry.APIEndpoint
|
||||
actions []string
|
||||
repoName reference.Named
|
||||
indexInfo *registrytypes.IndexInfo
|
||||
endpoint registry.APIEndpoint
|
||||
actions []string
|
||||
}
|
||||
|
||||
// Name returns the repository name
|
||||
func (r repositoryEndpoint) Name() string {
|
||||
return reference.Path(r.info.Name)
|
||||
return reference.Path(r.repoName)
|
||||
}
|
||||
|
||||
// BaseURL returns the endpoint url
|
||||
@ -30,32 +31,36 @@ func (r repositoryEndpoint) BaseURL() string {
|
||||
}
|
||||
|
||||
func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) {
|
||||
repoName := reference.TrimNamed(ref)
|
||||
repoInfo, _ := registry.ParseRepositoryInfo(ref)
|
||||
endpoint, err := getDefaultEndpointFromRepoInfo(repoInfo)
|
||||
indexInfo := repoInfo.Index
|
||||
|
||||
endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure)
|
||||
if err != nil {
|
||||
return repositoryEndpoint{}, err
|
||||
}
|
||||
if insecure {
|
||||
endpoint.TLSConfig.InsecureSkipVerify = true
|
||||
}
|
||||
return repositoryEndpoint{info: repoInfo, endpoint: endpoint}, nil
|
||||
return repositoryEndpoint{
|
||||
repoName: repoName,
|
||||
indexInfo: indexInfo,
|
||||
endpoint: endpoint,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry.APIEndpoint, error) {
|
||||
var err error
|
||||
|
||||
options := registry.ServiceOptions{}
|
||||
registryService, err := registry.NewService(options)
|
||||
func getDefaultEndpoint(repoName reference.Named, insecure bool) (registry.APIEndpoint, error) {
|
||||
registryService, err := registry.NewService(registry.ServiceOptions{})
|
||||
if err != nil {
|
||||
return registry.APIEndpoint{}, err
|
||||
}
|
||||
endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoInfo.Name))
|
||||
endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoName))
|
||||
if err != nil {
|
||||
return registry.APIEndpoint{}, err
|
||||
}
|
||||
// Default to the highest priority endpoint to return
|
||||
endpoint := endpoints[0]
|
||||
if !repoInfo.Index.Secure {
|
||||
if insecure {
|
||||
for _, ep := range endpoints {
|
||||
if ep.URL.Scheme == "http" {
|
||||
endpoint = ep
|
||||
|
@ -220,7 +220,9 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
|
||||
return err
|
||||
}
|
||||
|
||||
repoName := reference.TrimNamed(namedRef)
|
||||
repoInfo, _ := registry.ParseRepositoryInfo(namedRef)
|
||||
indexInfo := repoInfo.Index
|
||||
|
||||
confirmedTLSRegistries := make(map[string]bool)
|
||||
for _, endpoint := range endpoints {
|
||||
@ -234,7 +236,11 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
|
||||
if c.insecureRegistry {
|
||||
endpoint.TLSConfig.InsecureSkipVerify = true
|
||||
}
|
||||
repoEndpoint := repositoryEndpoint{endpoint: endpoint, info: repoInfo}
|
||||
repoEndpoint := repositoryEndpoint{
|
||||
repoName: repoName,
|
||||
indexInfo: indexInfo,
|
||||
endpoint: endpoint,
|
||||
}
|
||||
repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint)
|
||||
if err != nil {
|
||||
logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint)
|
||||
|
Loading…
x
Reference in New Issue
Block a user