-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace k8s.io/kubernetes dep with a copy. (#7)
* Replace k8s.io/kubernetes dep with a small copy. * Group k8s updates. * Run tests.
- Loading branch information
Showing
11 changed files
with
930 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
Copyright 2014 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package credentialprovider | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// DockerConfigJSON represents ~/.docker/config.json file info | ||
// see https://github.com/docker/docker/pull/12009 | ||
type DockerConfigJSON struct { | ||
Auths DockerConfig `json:"auths"` | ||
// +optional | ||
HTTPHeaders map[string]string `json:"HttpHeaders,omitempty"` | ||
} | ||
|
||
// DockerConfig represents the config file used by the docker CLI. | ||
// This config that represents the credentials that should be used | ||
// when pulling images from specific image repositories. | ||
type DockerConfig map[string]DockerConfigEntry | ||
|
||
// DockerConfigEntry wraps a docker config as a entry | ||
type DockerConfigEntry struct { | ||
Username string | ||
Password string | ||
Email string | ||
Provider DockerConfigProvider | ||
} | ||
|
||
// dockerConfigEntryWithAuth is used solely for deserializing the Auth field | ||
// into a dockerConfigEntry during JSON deserialization. | ||
type dockerConfigEntryWithAuth struct { | ||
// +optional | ||
Username string `json:"username,omitempty"` | ||
// +optional | ||
Password string `json:"password,omitempty"` | ||
// +optional | ||
Email string `json:"email,omitempty"` | ||
// +optional | ||
Auth string `json:"auth,omitempty"` | ||
} | ||
|
||
// UnmarshalJSON implements the json.Unmarshaler interface. | ||
func (ident *DockerConfigEntry) UnmarshalJSON(data []byte) error { | ||
var tmp dockerConfigEntryWithAuth | ||
err := json.Unmarshal(data, &tmp) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ident.Username = tmp.Username | ||
ident.Password = tmp.Password | ||
ident.Email = tmp.Email | ||
|
||
if len(tmp.Auth) == 0 { | ||
return nil | ||
} | ||
|
||
ident.Username, ident.Password, err = decodeDockerConfigFieldAuth(tmp.Auth) | ||
return err | ||
} | ||
|
||
// decodeDockerConfigFieldAuth deserializes the "auth" field from dockercfg into a | ||
// username and a password. The format of the auth field is base64(<username>:<password>). | ||
func decodeDockerConfigFieldAuth(field string) (username, password string, err error) { | ||
|
||
var decoded []byte | ||
|
||
// StdEncoding can only decode padded string | ||
// RawStdEncoding can only decode unpadded string | ||
if strings.HasSuffix(strings.TrimSpace(field), "=") { | ||
// decode padded data | ||
decoded, err = base64.StdEncoding.DecodeString(field) | ||
} else { | ||
// decode unpadded data | ||
decoded, err = base64.RawStdEncoding.DecodeString(field) | ||
} | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
parts := strings.SplitN(string(decoded), ":", 2) | ||
if len(parts) != 2 { | ||
err = fmt.Errorf("unable to parse auth field, must be formatted as base64(username:password)") | ||
return | ||
} | ||
|
||
username = parts[0] | ||
password = parts[1] | ||
|
||
return | ||
} | ||
|
||
func encodeDockerConfigFieldAuth(username, password string) string { | ||
fieldValue := username + ":" + password | ||
|
||
return base64.StdEncoding.EncodeToString([]byte(fieldValue)) | ||
} |
Oops, something went wrong.