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