From 570ca30d1f4b40cc85dc6f56c26352c9367d7a98 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Fri, 13 Dec 2024 11:58:09 +0100 Subject: [PATCH] Define an util const: StaticPassword Signed-off-by: cmoulliard --- api/v1alpha1/gitrepository_types.go | 13 ++++++------- pkg/controllers/gitrepository/controller.go | 2 +- pkg/controllers/localbuild/controller.go | 10 +++++----- pkg/util/argocd.go | 1 - pkg/util/util.go | 1 + 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/api/v1alpha1/gitrepository_types.go b/api/v1alpha1/gitrepository_types.go index 978087c4..d3ac32af 100644 --- a/api/v1alpha1/gitrepository_types.go +++ b/api/v1alpha1/gitrepository_types.go @@ -5,13 +5,12 @@ import ( ) const ( - GitProviderGitea = "gitea" - GitProviderGitHub = "github" - GiteaAdminUserName = "giteaAdmin" - GiteaDeveloperUserName = "developer" - SourceTypeLocal = "local" - SourceTypeRemote = "remote" - SourceTypeEmbedded = "embedded" + GitProviderGitea = "gitea" + GitProviderGitHub = "github" + GiteaAdminUserName = "giteaAdmin" + SourceTypeLocal = "local" + SourceTypeRemote = "remote" + SourceTypeEmbedded = "embedded" ) type GitRepositorySpec struct { diff --git a/pkg/controllers/gitrepository/controller.go b/pkg/controllers/gitrepository/controller.go index 45ef84d2..93baedef 100644 --- a/pkg/controllers/gitrepository/controller.go +++ b/pkg/controllers/gitrepository/controller.go @@ -144,7 +144,7 @@ func (r *RepositoryReconciler) reconcileGitRepo(ctx context.Context, repo *v1alp } if r.Config.StaticPassword { - creds.password = "developer" + creds.password = util.StaticPassword } err = provider.setProviderCredentials(ctx, repo, creds) diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index a30faa31..f74a5b04 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -678,7 +678,7 @@ func (r *LocalbuildReconciler) updateGiteaDevPassword(ctx context.Context, admin opts := gitea.EditUserOption{ LoginName: "giteaAdmin", - Password: "developer", + Password: util.StaticPassword, } resp, err := client.AdminEditUser("giteaAdmin", opts) @@ -686,7 +686,7 @@ func (r *LocalbuildReconciler) updateGiteaDevPassword(ctx context.Context, admin return fmt.Errorf("cannot update gitea admin user. status: %d error : %w", resp.StatusCode, err), "failed" } - err = util.PatchPasswordSecret(ctx, r.Client, r.Config, util.GiteaNamespace, util.GiteaAdminSecret, util.GiteaAdminName, "developer") + err = util.PatchPasswordSecret(ctx, r.Client, r.Config, util.GiteaNamespace, util.GiteaAdminSecret, util.GiteaAdminName, util.StaticPassword) if err != nil { return fmt.Errorf("patching the gitea credentials failed : %w", err), "failed" } @@ -740,7 +740,7 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi payload := map[string]string{ "name": "admin", "currentPassword": adminPassword, - "newPassword": util.ArgocdDevModePassword, + "newPassword": util.StaticPassword, } payloadBytes, err := json.Marshal(payload) @@ -763,7 +763,7 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi // Lets checking the new admin password payload = map[string]string{ "username": "admin", - "password": util.ArgocdDevModePassword, + "password": util.StaticPassword, } payloadBytes, err = json.Marshal(payload) if err != nil { @@ -787,7 +787,7 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi // Password verification succeeded ! if resp.StatusCode == 200 { // Let's patch the existing secret now - err = util.PatchPasswordSecret(ctx, r.Client, r.Config, util.ArgocdNamespace, util.ArgocdInitialAdminSecretName, util.ArgocdAdminName, "developer") + err = util.PatchPasswordSecret(ctx, r.Client, r.Config, util.ArgocdNamespace, util.ArgocdInitialAdminSecretName, util.ArgocdAdminName, util.StaticPassword) if err != nil { return fmt.Errorf("patching the argocd initial secret failed : %w", err), "failed" } diff --git a/pkg/util/argocd.go b/pkg/util/argocd.go index 1ef8a13e..eb0e9dd2 100644 --- a/pkg/util/argocd.go +++ b/pkg/util/argocd.go @@ -6,7 +6,6 @@ import ( ) const ( - ArgocdDevModePassword = "developer" ArgocdInitialAdminSecretName = "argocd-initial-admin-secret" ArgocdAdminName = "admin" ArgocdNamespace = "argocd" diff --git a/pkg/util/util.go b/pkg/util/util.go index 86f4fad3..99b15cb0 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -28,6 +28,7 @@ const ( passwordLength = 40 numSpecialChars = 3 numDigits = 3 + StaticPassword = "developer" ) func GetCLIStartTimeAnnotationValue(annotations map[string]string) (string, error) {