-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcredentials.go
More file actions
48 lines (41 loc) · 1.31 KB
/
Copy pathcredentials.go
File metadata and controls
48 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"sync"
)
// RegistryCredentials holds authentication credentials for a registry
type RegistryCredentials struct {
Username string
Password string
}
// CredentialStore manages credentials for multiple registries
type CredentialStore struct {
credentials map[string]RegistryCredentials
mu sync.RWMutex
}
var globalCredentialStore = &CredentialStore{
credentials: make(map[string]RegistryCredentials),
}
// SetCredentials sets credentials for a specific registry
func SetCredentials(registry string, username, password string) {
globalCredentialStore.mu.Lock()
defer globalCredentialStore.mu.Unlock()
globalCredentialStore.credentials[normalizeRegistry(registry)] = RegistryCredentials{
Username: username,
Password: password,
}
}
// GetCredentials retrieves credentials for a specific registry
func GetCredentials(registry string) (RegistryCredentials, bool) {
globalCredentialStore.mu.RLock()
defer globalCredentialStore.mu.RUnlock()
creds, ok := globalCredentialStore.credentials[normalizeRegistry(registry)]
return creds, ok
}
// normalizeRegistry normalizes registry names for consistent lookup
func normalizeRegistry(registry string) string {
switch registry {
case "docker.io", "index.docker.io", "registry-1.docker.io":
return "registry-1.docker.io"
}
return registry
}