Skip to content

Commit

Permalink
Merge pull request kubernetes#84478 from hvaara/fix-golint-pkg/creden…
Browse files Browse the repository at this point in the history
…tialprovider/gcp

Fix golint issues in pkg/credentialprovider/gcp
  • Loading branch information
k8s-ci-robot authored Oct 30, 2019
2 parents 86dbdbe + e40c473 commit 5e468a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
1 change: 0 additions & 1 deletion hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pkg/controller/volume/persistentvolume
pkg/controller/volume/persistentvolume/config/v1alpha1
pkg/controller/volume/persistentvolume/options
pkg/credentialprovider
pkg/credentialprovider/gcp
pkg/features
pkg/kubeapiserver
pkg/kubeapiserver/options
Expand Down
4 changes: 2 additions & 2 deletions pkg/credentialprovider/gcp/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package gcp_credentials contains implementations of DockerConfigProvider
// Package gcp contains implementations of DockerConfigProvider
// for Google Cloud Platform.
package gcp_credentials // import "k8s.io/kubernetes/pkg/credentialprovider/gcp"
package gcp // import "k8s.io/kubernetes/pkg/credentialprovider/gcp"
30 changes: 15 additions & 15 deletions pkg/credentialprovider/gcp/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gcp_credentials
package gcp

import (
"encoding/json"
Expand All @@ -31,14 +31,14 @@ import (
)

const (
metadataUrl = "http://metadata.google.internal./computeMetadata/v1/"
metadataAttributes = metadataUrl + "instance/attributes/"
metadataURL = "http://metadata.google.internal./computeMetadata/v1/"
metadataAttributes = metadataURL + "instance/attributes/"
dockerConfigKey = metadataAttributes + "google-dockercfg"
dockerConfigUrlKey = metadataAttributes + "google-dockercfg-url"
serviceAccounts = metadataUrl + "instance/service-accounts/"
metadataScopes = metadataUrl + "instance/service-accounts/default/scopes"
metadataToken = metadataUrl + "instance/service-accounts/default/token"
metadataEmail = metadataUrl + "instance/service-accounts/default/email"
dockerConfigURLKey = metadataAttributes + "google-dockercfg-url"
serviceAccounts = metadataURL + "instance/service-accounts/"
metadataScopes = metadataURL + "instance/service-accounts/default/scopes"
metadataToken = metadataURL + "instance/service-accounts/default/token"
metadataEmail = metadataURL + "instance/service-accounts/default/email"
storageScopePrefix = "https://www.googleapis.com/auth/devstorage"
cloudPlatformScopePrefix = "https://www.googleapis.com/auth/cloud-platform"
defaultServiceAccount = "default/"
Expand Down Expand Up @@ -70,7 +70,7 @@ type dockerConfigKeyProvider struct {

// A DockerConfigProvider that reads its configuration from a URL read from
// a specific Google Compute Engine metadata key: 'google-dockercfg-url'.
type dockerConfigUrlKeyProvider struct {
type dockerConfigURLKeyProvider struct {
metadataProvider
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func init() {

credentialprovider.RegisterCredentialProvider("google-dockercfg-url",
&credentialprovider.CachingDockerConfigProvider{
Provider: &dockerConfigUrlKeyProvider{
Provider: &dockerConfigURLKeyProvider{
metadataProvider{Client: httpClient},
},
Lifetime: 60 * time.Second,
Expand Down Expand Up @@ -160,9 +160,9 @@ func (g *dockerConfigKeyProvider) Provide(image string) credentialprovider.Docke
}

// Provide implements DockerConfigProvider
func (g *dockerConfigUrlKeyProvider) Provide(image string) credentialprovider.DockerConfig {
func (g *dockerConfigURLKeyProvider) Provide(image string) credentialprovider.DockerConfig {
// Read the contents of the google-dockercfg-url key and load a .dockercfg from there
if url, err := credentialprovider.ReadUrl(dockerConfigUrlKey, g.Client, metadataHeader); err != nil {
if url, err := credentialprovider.ReadUrl(dockerConfigURLKey, g.Client, metadataHeader); err != nil {
klog.Errorf("while reading 'google-dockercfg-url' metadata: %v", err)
} else {
if strings.HasPrefix(string(url), "http") {
Expand Down Expand Up @@ -268,7 +268,7 @@ type tokenBlob struct {
func (g *containerRegistryProvider) Provide(image string) credentialprovider.DockerConfig {
cfg := credentialprovider.DockerConfig{}

tokenJsonBlob, err := credentialprovider.ReadUrl(metadataToken, g.Client, metadataHeader)
tokenJSONBlob, err := credentialprovider.ReadUrl(metadataToken, g.Client, metadataHeader)
if err != nil {
klog.Errorf("while reading access token endpoint: %v", err)
return cfg
Expand All @@ -281,8 +281,8 @@ func (g *containerRegistryProvider) Provide(image string) credentialprovider.Doc
}

var parsedBlob tokenBlob
if err := json.Unmarshal([]byte(tokenJsonBlob), &parsedBlob); err != nil {
klog.Errorf("while parsing json blob %s: %v", tokenJsonBlob, err)
if err := json.Unmarshal([]byte(tokenJSONBlob), &parsedBlob); err != nil {
klog.Errorf("while parsing json blob %s: %v", tokenJSONBlob, err)
return cfg
}

Expand Down
30 changes: 15 additions & 15 deletions pkg/credentialprovider/gcp/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package gcp_credentials
package gcp

import (
"encoding/base64"
Expand Down Expand Up @@ -42,7 +42,7 @@ func createProductNameFile() (string, error) {
}

func TestDockerKeyringFromGoogleDockerConfigMetadata(t *testing.T) {
registryUrl := "hello.kubernetes.io"
registryURL := "hello.kubernetes.io"
email := "foo@bar.baz"
username := "foo"
password := "bar"
Expand All @@ -52,7 +52,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadata(t *testing.T) {
"email": %q,
"auth": %q
}
}`, registryUrl, email, auth)
}`, registryURL, email, auth)

var err error
gceProductNameFile, err = createProductNameFile()
Expand Down Expand Up @@ -93,9 +93,9 @@ func TestDockerKeyringFromGoogleDockerConfigMetadata(t *testing.T) {

keyring.Add(provider.Provide(""))

creds, ok := keyring.Lookup(registryUrl)
creds, ok := keyring.Lookup(registryURL)
if !ok {
t.Errorf("Didn't find expected URL: %s", registryUrl)
t.Errorf("Didn't find expected URL: %s", registryURL)
return
}
if len(creds) > 1 {
Expand All @@ -115,7 +115,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadata(t *testing.T) {
}

func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {
registryUrl := "hello.kubernetes.io"
registryURL := "hello.kubernetes.io"
email := "foo@bar.baz"
username := "foo"
password := "bar"
Expand All @@ -125,7 +125,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {
"email": %q,
"auth": %q
}
}`, registryUrl, email, auth)
}`, registryURL, email, auth)

var err error
gceProductNameFile, err = createProductNameFile()
Expand All @@ -143,7 +143,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, sampleDockerConfig)
} else if strings.HasSuffix(dockerConfigUrlKey, r.URL.Path) {
} else if strings.HasSuffix(dockerConfigURLKey, r.URL.Path) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/text")
fmt.Fprint(w, "http://foo.bar.com"+valueEndpoint)
Expand All @@ -161,7 +161,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {
})

keyring := &credentialprovider.BasicDockerKeyring{}
provider := &dockerConfigUrlKeyProvider{
provider := &dockerConfigURLKeyProvider{
metadataProvider{Client: &http.Client{Transport: transport}},
}

Expand All @@ -171,9 +171,9 @@ func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {

keyring.Add(provider.Provide(""))

creds, ok := keyring.Lookup(registryUrl)
creds, ok := keyring.Lookup(registryURL)
if !ok {
t.Errorf("Didn't find expected URL: %s", registryUrl)
t.Errorf("Didn't find expected URL: %s", registryURL)
return
}
if len(creds) > 1 {
Expand All @@ -193,7 +193,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {
}

func TestContainerRegistryBasics(t *testing.T) {
registryUrl := "container.cloud.google.com"
registryURL := "container.cloud.google.com"
email := "1234@project.gserviceaccount.com"
token := &tokenBlob{AccessToken: "ya26.lots-of-indiscernible-garbage"}

Expand Down Expand Up @@ -255,9 +255,9 @@ func TestContainerRegistryBasics(t *testing.T) {

keyring.Add(provider.Provide(""))

creds, ok := keyring.Lookup(registryUrl)
creds, ok := keyring.Lookup(registryURL)
if !ok {
t.Errorf("Didn't find expected URL: %s", registryUrl)
t.Errorf("Didn't find expected URL: %s", registryURL)
return
}
if len(creds) > 1 {
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestAllProvidersNoMetadata(t *testing.T) {
&dockerConfigKeyProvider{
metadataProvider{Client: &http.Client{Transport: transport}},
},
&dockerConfigUrlKeyProvider{
&dockerConfigURLKeyProvider{
metadataProvider{Client: &http.Client{Transport: transport}},
},
&containerRegistryProvider{
Expand Down

0 comments on commit 5e468a4

Please sign in to comment.