-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop importing the k8s.io/kubernetes module. #6411
Changes from 1 commit
e23aa95
4c6b8f4
b95d2d3
f5969c1
e8d4cd2
a0b932b
3fa1389
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2019-2022 the Kubeapps contributors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package kube | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// The following is Copyright 2014 The Kubernetes Authors | ||
// and icensed under the Apache License, Version 2.0. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we, perhaps, need to explicitly use the same copyright text, I was thinking sth more like: Also, should we add the permalink instead of the link pointing to master? Not sure :S
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, will update. |
||
// Including here instead of importing from k8s.io/kubernetes/credentialprovider | ||
// since k8s.io/kubernetes is not supported for imports and leads | ||
// to version issues. | ||
|
||
// DockerConfigProvider is the interface that registered extensions implement | ||
// to materialize 'dockercfg' credentials. | ||
type DockerConfigProvider interface { | ||
// Enabled returns true if the config provider is enabled. | ||
// Implementations can be blocking - e.g. metadata server unavailable. | ||
Enabled() bool | ||
// Provide returns docker configuration. | ||
// Implementations can be blocking - e.g. metadata server unavailable. | ||
// The image is passed in as context in the event that the | ||
// implementation depends on information in the image name to return | ||
// credentials; implementations are safe to ignore the image. | ||
Provide(image string) DockerConfig | ||
} | ||
|
||
// 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"` | ||
} | ||
|
||
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 | ||
} | ||
|
||
func (ident DockerConfigEntry) MarshalJSON() ([]byte, error) { | ||
toEncode := dockerConfigEntryWithAuth{ident.Username, ident.Password, ident.Email, ""} | ||
toEncode.Auth = encodeDockerConfigFieldAuth(ident.Username, ident.Password) | ||
|
||
return json.Marshal(toEncode) | ||
} | ||
|
||
// 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) { | ||
decoded, err := base64.StdEncoding.DecodeString(field) | ||
if err != nil { | ||
return | ||
} | ||
|
||
parts := strings.SplitN(string(decoded), ":", 2) | ||
if len(parts) != 2 { | ||
err = fmt.Errorf("unable to parse auth field") | ||
return | ||
} | ||
|
||
username = parts[0] | ||
password = parts[1] | ||
|
||
return | ||
} | ||
|
||
func encodeDockerConfigFieldAuth(username, password string) string { | ||
fieldValue := username + ":" + password | ||
|
||
return base64.StdEncoding.EncodeToString([]byte(fieldValue)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, but unrelated, I think we should update the NOTICE file and remove this old file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I've been removing the old OSL license files later (I don't think we personally need to add them to the root of the repo anyway, given that we upload them to the release artifacts and leave them there.. wdyt?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old ones? No, I don't think so. As for the current one (the one to be released), we need it just before tagging the release, this way it would end up in the release artifact.
Right after that... I believe we can safely remove it; in fact, that file no longer represents the current status of the project, as we might add/remove deps and, moreover, it is just a document to be embedded in a release artifact.
That said... I think it's easier for us to just remove it as part of the release process: remove the old one and add the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why I think it's more useful uploading it as a (separate) release artifact for that release, rather than temporarily including it in the repo. But IANAL.