From 99076ce32a691374bd8033983045f52f9dcc11db Mon Sep 17 00:00:00 2001 From: Abrar Shivani Date: Tue, 15 May 2018 22:14:33 -0700 Subject: [PATCH] Add kubernetes license to credential manager --- .../providers/vsphere/credentialmanager.go | 16 +++++++++++++++ .../vsphere/credentialmanager_test.go | 20 +++++++++++++++++-- .../providers/vsphere/vclib/connection.go | 2 ++ .../providers/vsphere/vclib/utils.go | 1 + .../providers/vsphere/vsphere_test.go | 4 ++-- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/pkg/cloudprovider/providers/vsphere/credentialmanager.go b/pkg/cloudprovider/providers/vsphere/credentialmanager.go index 75a2afb075b..95862a8a5aa 100644 --- a/pkg/cloudprovider/providers/vsphere/credentialmanager.go +++ b/pkg/cloudprovider/providers/vsphere/credentialmanager.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 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 vsphere import ( diff --git a/pkg/cloudprovider/providers/vsphere/credentialmanager_test.go b/pkg/cloudprovider/providers/vsphere/credentialmanager_test.go index ef0f80b229a..4bef4001ff7 100644 --- a/pkg/cloudprovider/providers/vsphere/credentialmanager_test.go +++ b/pkg/cloudprovider/providers/vsphere/credentialmanager_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 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 vsphere import ( @@ -213,8 +229,8 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) { if expected.err == nil { if expected.username != credential.User || expected.password != credential.Password { - t.Fatalf("Recieved credentials %v "+ - "are diffrent than actual credential user:%s password:%s", credential, expected.username, + t.Fatalf("Received credentials %v "+ + "are different than actual credential user:%s password:%s", credential, expected.username, expected.password) } } diff --git a/pkg/cloudprovider/providers/vsphere/vclib/connection.go b/pkg/cloudprovider/providers/vsphere/vclib/connection.go index f5125f3d89c..91f0e8a963a 100644 --- a/pkg/cloudprovider/providers/vsphere/vclib/connection.go +++ b/pkg/cloudprovider/providers/vsphere/vclib/connection.go @@ -167,6 +167,8 @@ func (connection *VSphereConnection) NewClient(ctx context.Context) (*vim25.Clie return client, nil } +// UpdateCredentials updates username and password. +// Note: Updated username and password will be used when there is no session active func (connection *VSphereConnection) UpdateCredentials(username string, password string) { connection.credentialsLock.Lock() defer connection.credentialsLock.Unlock() diff --git a/pkg/cloudprovider/providers/vsphere/vclib/utils.go b/pkg/cloudprovider/providers/vsphere/vclib/utils.go index ac67f5150d0..36ea8d6c6ef 100644 --- a/pkg/cloudprovider/providers/vsphere/vclib/utils.go +++ b/pkg/cloudprovider/providers/vsphere/vclib/utils.go @@ -172,6 +172,7 @@ func IsManagedObjectNotFoundError(err error) bool { return isManagedObjectNotFoundError } +// IsInvalidCredentialsError returns true if error is of type InvalidLogin func IsInvalidCredentialsError(err error) bool { isInvalidCredentialsError := false if soap.IsSoapFault(err) { diff --git a/pkg/cloudprovider/providers/vsphere/vsphere_test.go b/pkg/cloudprovider/providers/vsphere/vsphere_test.go index b7cd29b2f49..0533405b190 100644 --- a/pkg/cloudprovider/providers/vsphere/vsphere_test.go +++ b/pkg/cloudprovider/providers/vsphere/vsphere_test.go @@ -557,11 +557,11 @@ func TestSecretVSphereConfig(t *testing.T) { if !testcase.expectedIsSecretProvided { for _, vsInstance := range vs.vsphereInstanceMap { if vsInstance.conn.Username != testcase.expectedUsername { - t.Fatalf("Expected username doesn't match actual username in config %s. error: %s", + t.Fatalf("Expected username %s doesn't match actual username %s in config %s. error: %s", testcase.expectedUsername, vsInstance.conn.Username, testcase.conf, err) } if vsInstance.conn.Password != testcase.expectedPassword { - t.Fatalf("Expected password doesn't match actual password in config %s. error: %s", + t.Fatalf("Expected password %s doesn't match actual password %s in config %s. error: %s", testcase.expectedPassword, vsInstance.conn.Password, testcase.conf, err) }