Skip to content

Commit 7716219

Browse files
committed
internal/registry: remove dead code
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f6b90bc commit 7716219

12 files changed

+18
-1578
lines changed

internal/registry/auth.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -127,44 +127,6 @@ func v2AuthHTTPClient(endpoint *url.URL, authTransport http.RoundTripper, modifi
127127
}, nil
128128
}
129129

130-
// ConvertToHostname normalizes a registry URL which has http|https prepended
131-
// to just its hostname. It is used to match credentials, which may be either
132-
// stored as hostname or as hostname including scheme (in legacy configuration
133-
// files).
134-
func ConvertToHostname(maybeURL string) string {
135-
stripped := maybeURL
136-
if scheme, remainder, ok := strings.Cut(stripped, "://"); ok {
137-
switch scheme {
138-
case "http", "https":
139-
stripped = remainder
140-
default:
141-
// unknown, or no scheme; doing nothing for now, as we never did.
142-
}
143-
}
144-
stripped, _, _ = strings.Cut(stripped, "/")
145-
return stripped
146-
}
147-
148-
// ResolveAuthConfig matches an auth configuration to a server address or a URL
149-
func ResolveAuthConfig(authConfigs map[string]registry.AuthConfig, index *registry.IndexInfo) registry.AuthConfig {
150-
configKey := GetAuthConfigKey(index)
151-
// First try the happy case
152-
if c, found := authConfigs[configKey]; found || index.Official {
153-
return c
154-
}
155-
156-
// Maybe they have a legacy config file, we will iterate the keys converting
157-
// them to the new format and testing
158-
for registryURL, ac := range authConfigs {
159-
if configKey == ConvertToHostname(registryURL) {
160-
return ac
161-
}
162-
}
163-
164-
// When all else fails, return an empty auth config
165-
return registry.AuthConfig{}
166-
}
167-
168130
// PingResponseError is used when the response from a ping
169131
// was received but invalid.
170132
type PingResponseError struct {

internal/registry/auth_test.go

Lines changed: 0 additions & 106 deletions
This file was deleted.

internal/registry/config.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,6 @@ func newServiceConfig(options ServiceOptions) (*serviceConfig, error) {
106106
return config, nil
107107
}
108108

109-
// copy constructs a new ServiceConfig with a copy of the configuration in config.
110-
func (config *serviceConfig) copy() *registry.ServiceConfig {
111-
ic := make(map[string]*registry.IndexInfo)
112-
for key, value := range config.IndexConfigs {
113-
ic[key] = value
114-
}
115-
return &registry.ServiceConfig{
116-
InsecureRegistryCIDRs: append([]*registry.NetIPNet(nil), config.InsecureRegistryCIDRs...),
117-
IndexConfigs: ic,
118-
Mirrors: append([]string(nil), config.Mirrors...),
119-
}
120-
}
121-
122109
// loadMirrors loads mirrors to config, after removing duplicates.
123110
// Returns an error if mirrors contains an invalid mirror.
124111
func (config *serviceConfig) loadMirrors(mirrors []string) error {
@@ -320,18 +307,12 @@ func ValidateIndexName(val string) (string, error) {
320307
}
321308

322309
func normalizeIndexName(val string) string {
323-
// TODO(thaJeztah): consider normalizing other known options, such as "(https://)registry-1.docker.io", "https://index.docker.io/v1/".
324-
// TODO: upstream this to check to reference package
325310
if val == "index.docker.io" {
326311
return "docker.io"
327312
}
328313
return val
329314
}
330315

331-
func hasScheme(reposName string) bool {
332-
return strings.Contains(reposName, "://")
333-
}
334-
335316
func validateHostPort(s string) error {
336317
// Split host and port, and in case s can not be split, assume host only
337318
host, port, err := net.SplitHostPort(s)
@@ -356,32 +337,6 @@ func validateHostPort(s string) error {
356337
return nil
357338
}
358339

359-
// newIndexInfo returns IndexInfo configuration from indexName
360-
func newIndexInfo(config *serviceConfig, indexName string) *registry.IndexInfo {
361-
indexName = normalizeIndexName(indexName)
362-
363-
// Return any configured index info, first.
364-
if index, ok := config.IndexConfigs[indexName]; ok {
365-
return index
366-
}
367-
368-
// Construct a non-configured index info.
369-
return &registry.IndexInfo{
370-
Name: indexName,
371-
Mirrors: []string{},
372-
Secure: config.isSecureIndex(indexName),
373-
}
374-
}
375-
376-
// GetAuthConfigKey special-cases using the full index address of the official
377-
// index as the AuthConfig key, and uses the (host)name[:port] for private indexes.
378-
func GetAuthConfigKey(index *registry.IndexInfo) string {
379-
if index.Official {
380-
return IndexServer
381-
}
382-
return index.Name
383-
}
384-
385340
// ParseRepositoryInfo performs the breakdown of a repository name into a
386341
// [RepositoryInfo], but lacks registry configuration.
387342
//

internal/registry/errors.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,3 @@ func (invalidParameterErr) InvalidParameter() {}
4949
func (e invalidParameterErr) Unwrap() error {
5050
return e.error
5151
}
52-
53-
type systemErr struct{ error }
54-
55-
func (systemErr) System() {}
56-
57-
func (e systemErr) Unwrap() error {
58-
return e.error
59-
}
60-
61-
type errUnknown struct{ error }
62-
63-
func (errUnknown) Unknown() {}
64-
65-
func (e errUnknown) Unwrap() error {
66-
return e.error
67-
}

internal/registry/registry_mock_test.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import (
1313
"gotest.tools/v3/assert"
1414
)
1515

16-
var (
17-
testHTTPServer *httptest.Server
18-
testHTTPSServer *httptest.Server
19-
)
16+
var testHTTPServer *httptest.Server
2017

2118
func init() {
2219
r := http.NewServeMux()
@@ -29,7 +26,6 @@ func init() {
2926
r.HandleFunc("/v2/version", handlerGetPing)
3027

3128
testHTTPServer = httptest.NewServer(handlerAccessLog(r))
32-
testHTTPSServer = httptest.NewTLSServer(handlerAccessLog(r))
3329
}
3430

3531
func handlerAccessLog(handler http.Handler) http.Handler {
@@ -44,30 +40,6 @@ func makeURL(req string) string {
4440
return testHTTPServer.URL + req
4541
}
4642

47-
func makeHTTPSURL(req string) string {
48-
return testHTTPSServer.URL + req
49-
}
50-
51-
func makeIndex(req string) *registry.IndexInfo {
52-
return &registry.IndexInfo{
53-
Name: makeURL(req),
54-
}
55-
}
56-
57-
func makeHTTPSIndex(req string) *registry.IndexInfo {
58-
return &registry.IndexInfo{
59-
Name: makeHTTPSURL(req),
60-
}
61-
}
62-
63-
func makePublicIndex() *registry.IndexInfo {
64-
return &registry.IndexInfo{
65-
Name: IndexServer,
66-
Secure: true,
67-
Official: true,
68-
}
69-
}
70-
7143
func writeHeaders(w http.ResponseWriter) {
7244
h := w.Header()
7345
h.Add("Server", "docker-tests/mock")

internal/registry/registry_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ func overrideLookupIP(t *testing.T) {
3434
})
3535
}
3636

37+
// newIndexInfo returns IndexInfo configuration from indexName
38+
func newIndexInfo(config *serviceConfig, indexName string) *registry.IndexInfo {
39+
indexName = normalizeIndexName(indexName)
40+
41+
// Return any configured index info, first.
42+
if index, ok := config.IndexConfigs[indexName]; ok {
43+
return index
44+
}
45+
46+
// Construct a non-configured index info.
47+
return &registry.IndexInfo{
48+
Name: indexName,
49+
Mirrors: []string{},
50+
Secure: config.isSecureIndex(indexName),
51+
}
52+
}
53+
3754
func TestParseRepositoryInfo(t *testing.T) {
3855
type staticRepositoryInfo struct {
3956
Index *registry.IndexInfo

0 commit comments

Comments
 (0)