internal/registryclient: repositoryEndpoint: memoize repoName

- Parse/format the repository name when constructing and store the
  result.
- Remove the Name() accessor, as this type is only used internally,
  and no longer had any special handling.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-20 14:02:26 +02:00
parent b2b7187244
commit 2ce94e4fff
3 changed files with 5 additions and 12 deletions

View File

@ -120,7 +120,7 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest
}
func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) {
repoName, err := reference.WithName(repoEndpoint.Name())
repoName, err := reference.WithName(repoEndpoint.repoName)
if err != nil {
return nil, fmt.Errorf("failed to parse repo name from %s: %w", ref, err)
}
@ -148,7 +148,7 @@ func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoi
httpTransport, err := getHTTPTransport(
c.authConfigResolver(ctx, repoEndpoint.indexInfo),
repoEndpoint.endpoint,
repoEndpoint.Name(),
repoEndpoint.repoName,
c.userAgent,
repoEndpoint.actions,
)

View File

@ -16,26 +16,19 @@ import (
)
type repositoryEndpoint struct {
repoName reference.Named
repoName string
indexInfo *registrytypes.IndexInfo
endpoint registry.APIEndpoint
actions []string
}
// Name returns the repository name
func (r repositoryEndpoint) Name() string {
return reference.Path(r.repoName)
}
// BaseURL returns the endpoint url
func (r repositoryEndpoint) BaseURL() string {
return r.endpoint.URL.String()
}
func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) {
repoName := reference.TrimNamed(ref)
indexInfo := registry.NewIndexInfo(ref)
endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure)
if err != nil {
return repositoryEndpoint{}, err
@ -44,7 +37,7 @@ func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositor
endpoint.TLSConfig.InsecureSkipVerify = true
}
return repositoryEndpoint{
repoName: repoName,
repoName: reference.Path(reference.TrimNamed(ref)),
indexInfo: indexInfo,
endpoint: endpoint,
}, nil

View File

@ -221,7 +221,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
return err
}
repoName := reference.TrimNamed(namedRef)
repoName := reference.Path(reference.TrimNamed(namedRef))
indexInfo := registry.NewIndexInfo(namedRef)
confirmedTLSRegistries := make(map[string]bool)