github.com/SupersunnySea/draft@v0.16.0/pkg/builder/registry.go (about) 1 package builder 2 3 import ( 4 "encoding/base64" 5 "encoding/json" 6 7 "github.com/docker/docker/api/types" 8 ) 9 10 // DockerConfigEntryWithAuth is used solely for translating docker's AuthConfig token 11 // into a credentialprovider.dockerConfigEntry during JSON deserialization. 12 // 13 // pulled from https://github.com/kubernetes/kubernetes/blob/97892854cfa736315378cc2c206a7f4b3e190d05/pkg/credentialprovider/config.go#L232-L243 14 type DockerConfigEntryWithAuth struct { 15 // +optional 16 Username string `json:"username,omitempty"` 17 // +optional 18 Password string `json:"password,omitempty"` 19 // +optional 20 Email string `json:"email,omitempty"` 21 // +optional 22 Auth string `json:"auth,omitempty"` 23 } 24 25 // FromAuthConfigToken converts a docker auth token into type DockerConfigEntryWithAuth. This allows us to 26 // Marshal the object into a Kubernetes registry auth secret. 27 func FromAuthConfigToken(authToken string) (*DockerConfigEntryWithAuth, error) { 28 data, err := base64.StdEncoding.DecodeString(authToken) 29 if err != nil { 30 return nil, err 31 } 32 var regAuth types.AuthConfig 33 if err := json.Unmarshal(data, ®Auth); err != nil { 34 return nil, err 35 } 36 return FromAuthConfig(regAuth), nil 37 } 38 39 // FromAuthConfig converts a docker auth token into type DockerConfigEntryWithAuth. This allows us to 40 // Marshal the object into a Kubernetes registry auth secret. 41 func FromAuthConfig(ac types.AuthConfig) *DockerConfigEntryWithAuth { 42 return &DockerConfigEntryWithAuth{ 43 Username: ac.Username, 44 Password: ac.Password, 45 Email: ac.Email, 46 Auth: ac.Auth, 47 } 48 }