From 471e2e5d5c5dacd0f3816423c64ff2861c419fff Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Fri, 12 Feb 2021 10:37:03 +0200 Subject: [PATCH] Fix up. Signed-off-by: Oleksandr Andriienko --- pkg/controller/che/che_controller.go | 2 +- .../che/oauth_initial_htpasswd_provider.go | 47 +++++++++---------- .../oauth_initial_htpasswd_provider_test.go | 6 +-- pkg/deploy/deployment_test.go | 4 +- pkg/util/util.go | 4 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/pkg/controller/che/che_controller.go b/pkg/controller/che/che_controller.go index 4ab0d69e7..6c005de88 100644 --- a/pkg/controller/che/che_controller.go +++ b/pkg/controller/che/che_controller.go @@ -1148,7 +1148,7 @@ func (r *ReconcileChe) autoEnableOAuth(deployContext *deploy.DeployContext, requ if len(openshitOAuth.Spec.IdentityProviders) > 0 { oauth = true } else if util.IsInitialOpenShiftOAuthUserEnabled(cr) { - provisioned, err := r.userHandler.SyncOAuthInitialUser(openshitOAuth, deployContext); + provisioned, err := r.userHandler.SyncOAuthInitialUser(openshitOAuth, deployContext) if err != nil { message = warningNoIdentityProvidersMessage + " Operator tried to create initial OpenShift OAuth user for HTPasswd identity provider, but failed. Cause: " + err.Error() logrus.Error(message) diff --git a/pkg/controller/che/oauth_initial_htpasswd_provider.go b/pkg/controller/che/oauth_initial_htpasswd_provider.go index f5efad208..d7313904d 100644 --- a/pkg/controller/che/oauth_initial_htpasswd_provider.go +++ b/pkg/controller/che/oauth_initial_htpasswd_provider.go @@ -37,7 +37,7 @@ const ( ) var ( - password = util.GeneratePasswd(6) + password = util.GeneratePasswd(6) htpasswdFileContent string ) @@ -84,7 +84,6 @@ func (iuh *OpenShiftOAuthUserOperatorHandler) SyncOAuthInitialUser(openshiftOAut return false, err } - storedPassword := string(credentionalSecret.Data["password"]) if password != storedPassword { password = storedPassword @@ -92,8 +91,8 @@ func (iuh *OpenShiftOAuthUserOperatorHandler) SyncOAuthInitialUser(openshiftOAut htpasswdFileSecretData := map[string][]byte{"htpasswd": []byte(htpasswdFileContent)} secret, err := deploy.SyncSecret(deployContext, htpasswdSecretName, ocConfigNamespace, htpasswdFileSecretData) - if sercet == nil { - return false, err + if secret == nil { + return false, err } if err := appendIdentityProvider(openshiftOAuth, iuh.runtimeClient); err != nil { @@ -110,27 +109,27 @@ func (iuh *OpenShiftOAuthUserOperatorHandler) DeleteOAuthInitialUser(deployConte return err } - cr := deployContext.CheCluster - userName := deploy.DefaultCheFlavor(cr) - if err := deleteUser(iuh.runtimeClient, userName); err != nil { - return err - } - - if err := deleteUserIdentity(iuh.runtimeClient, userName); err != nil { - return err - } + cr := deployContext.CheCluster + userName := deploy.DefaultCheFlavor(cr) + if err := deleteUser(iuh.runtimeClient, userName); err != nil { + return err + } - if err := deleteIdentityProvider(oAuth, iuh.runtimeClient); err != nil { - return err - } - - if err := deploy.DeleteSecret(htpasswdSecretName, ocConfigNamespace, iuh.runtimeClient); err != nil { - return err - } + if err := deleteUserIdentity(iuh.runtimeClient, userName); err != nil { + return err + } - if err := deploy.DeleteSecret(openShiftOAuthUserCredentialsSecret, cr.Namespace, iuh.runtimeClient); err != nil { - return err - } + if err := deleteIdentityProvider(oAuth, iuh.runtimeClient); err != nil { + return err + } + + if err := deploy.DeleteSecret(htpasswdSecretName, ocConfigNamespace, iuh.runtimeClient); err != nil { + return err + } + + if err := deploy.DeleteSecret(openShiftOAuthUserCredentialsSecret, cr.Namespace, iuh.runtimeClient); err != nil { + return err + } return nil } @@ -178,7 +177,7 @@ func appendIdentityProvider(oAuth *oauthv1.OAuth, runtimeClient client.Client) e oauthPatch := client.MergeFrom(oAuth.DeepCopy()) oAuth.Spec.IdentityProviders = append(oAuth.Spec.IdentityProviders, *htpasswdProvider) - + if err := runtimeClient.Patch(context.TODO(), oAuth, oauthPatch); err != nil { return err } diff --git a/pkg/controller/che/oauth_initial_htpasswd_provider_test.go b/pkg/controller/che/oauth_initial_htpasswd_provider_test.go index 2255793d1..6fd396214 100644 --- a/pkg/controller/che/oauth_initial_htpasswd_provider_test.go +++ b/pkg/controller/che/oauth_initial_htpasswd_provider_test.go @@ -90,7 +90,7 @@ func TestCreateInitialUser(t *testing.T) { } dc := &deploy.DeployContext{ CheCluster: testCR, - ClusterAPI: deploy.ClusterAPI{Client: runtimeClient, NonCachedClient: runtimeClient, DiscoveryClient: nil, Scheme: scheme}, + ClusterAPI: deploy.ClusterAPI{Client: runtimeClient, NonCachedClient: runtimeClient, DiscoveryClient: nil, Scheme: scheme}, } provisined, err := initialUserHandler.SyncOAuthInitialUser(oAuth, dc) if err != nil { @@ -176,8 +176,8 @@ func TestDeleteInitialUser(t *testing.T) { } dc := &deploy.DeployContext{ - CheCluster: testCR, - ClusterAPI: deploy.ClusterAPI{Client: runtimeClient, NonCachedClient: runtimeClient, DiscoveryClient: nil, Scheme: scheme}, + CheCluster: testCR, + ClusterAPI: deploy.ClusterAPI{Client: runtimeClient, NonCachedClient: runtimeClient, DiscoveryClient: nil, Scheme: scheme}, } if err := initialUserHandler.DeleteOAuthInitialUser(dc); err != nil { t.Errorf("Unable to delete initial user: %s", err.Error()) diff --git a/pkg/deploy/deployment_test.go b/pkg/deploy/deployment_test.go index 0771bdf9d..9f4e1d775 100644 --- a/pkg/deploy/deployment_test.go +++ b/pkg/deploy/deployment_test.go @@ -282,9 +282,9 @@ func TestMountSecret(t *testing.T) { }, }, ClusterAPI: ClusterAPI{ - Client: cli, + Client: cli, NonCachedClient: cli, - Scheme: scheme.Scheme, + Scheme: scheme.Scheme, }, } diff --git a/pkg/util/util.go b/pkg/util/util.go index c7e20eaee..fc48a1628 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -391,9 +391,9 @@ func CompareBoolPointers(a *bool, b *bool) bool { return true } if a == nil && b != nil { - return false + return false } - if b == nil && a != nil{ + if b == nil && a != nil { return false } return *a == *b