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:
@ -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: ®istry.IndexInfo{
|
||||
Name: IndexName,
|
||||
Secure: true,
|
||||
Official: true,
|
||||
},
|
||||
return ®istry.IndexInfo{
|
||||
Name: IndexName,
|
||||
Secure: true,
|
||||
Official: true,
|
||||
}
|
||||
}
|
||||
|
||||
return &RepositoryInfo{
|
||||
Name: reference.TrimNamed(reposName),
|
||||
Index: ®istry.IndexInfo{
|
||||
Name: indexName,
|
||||
Secure: !isInsecure(indexName),
|
||||
},
|
||||
return ®istry.IndexInfo{
|
||||
Name: indexName,
|
||||
Secure: !isInsecure(indexName),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user