internal/registry: remove RepositoryInfo, add NewIndexInfo

Most places only use IndexInfo (and may not even need that), so replace
the use of ParseRepositoryInfo for NewIndexInfo, and move the RepositoryInfo
type to the trust package, which uses it as part of its ImageRefAndAuth
struct.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-03 14:39:30 +02:00
parent f86ad2ea4c
commit 21e8bbc8a2
12 changed files with 62 additions and 63 deletions

View File

@ -252,27 +252,22 @@ func validateHostPort(s string) error {
return nil
}
// ParseRepositoryInfo performs the breakdown of a repository name into a
// [RepositoryInfo], but lacks registry configuration.
func ParseRepositoryInfo(reposName reference.Named) *RepositoryInfo {
// NewIndexInfo creates a new [registry.IndexInfo] or the given
// repository-name, and detects whether the registry is considered
// "secure" (non-localhost).
func NewIndexInfo(reposName reference.Named) *registry.IndexInfo {
indexName := normalizeIndexName(reference.Domain(reposName))
if indexName == IndexName {
return &RepositoryInfo{
Name: reference.TrimNamed(reposName),
Index: &registry.IndexInfo{
Name: IndexName,
Secure: true,
Official: true,
},
return &registry.IndexInfo{
Name: IndexName,
Secure: true,
Official: true,
}
}
return &RepositoryInfo{
Name: reference.TrimNamed(reposName),
Index: &registry.IndexInfo{
Name: indexName,
Secure: !isInsecure(indexName),
},
return &registry.IndexInfo{
Name: indexName,
Secure: !isInsecure(indexName),
}
}

View File

@ -9,7 +9,7 @@ import (
is "gotest.tools/v3/assert/cmp"
)
func TestParseRepositoryInfo(t *testing.T) {
func TestNewIndexInfo(t *testing.T) {
type staticRepositoryInfo struct {
Index *registry.IndexInfo
RemoteName string
@ -269,12 +269,13 @@ func TestParseRepositoryInfo(t *testing.T) {
named, err := reference.ParseNormalizedNamed(reposName)
assert.NilError(t, err)
repoInfo := ParseRepositoryInfo(named)
indexInfo := NewIndexInfo(named)
repoInfoName := reference.TrimNamed(named)
assert.Check(t, is.DeepEqual(repoInfo.Index, expected.Index))
assert.Check(t, is.Equal(reference.Path(repoInfo.Name), expected.RemoteName))
assert.Check(t, is.Equal(reference.FamiliarName(repoInfo.Name), expected.LocalName))
assert.Check(t, is.Equal(repoInfo.Name.Name(), expected.CanonicalName))
assert.Check(t, is.DeepEqual(indexInfo, expected.Index))
assert.Check(t, is.Equal(reference.Path(repoInfoName), expected.RemoteName))
assert.Check(t, is.Equal(reference.FamiliarName(repoInfoName), expected.LocalName))
assert.Check(t, is.Equal(repoInfoName.Name(), expected.CanonicalName))
})
}
}

View File

@ -1,13 +0,0 @@
package registry
import (
"github.com/distribution/reference"
"github.com/moby/moby/api/types/registry"
)
// RepositoryInfo describes a repository
type RepositoryInfo struct {
Name reference.Named
// Index points to registry information
Index *registry.IndexInfo
}