Skip to content

Commit

Permalink
Define an util const: StaticPassword
Browse files Browse the repository at this point in the history
Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Dec 13, 2024
1 parent d029f62 commit 570ca30
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions api/v1alpha1/gitrepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/gitrepository/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/controllers/localbuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,15 +678,15 @@ func (r *LocalbuildReconciler) updateGiteaDevPassword(ctx context.Context, admin

opts := gitea.EditUserOption{
LoginName: "giteaAdmin",
Password: "developer",
Password: util.StaticPassword,
}

resp, err := client.AdminEditUser("giteaAdmin", opts)
if err != nil {
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"
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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"
}
Expand Down
1 change: 0 additions & 1 deletion pkg/util/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

const (
ArgocdDevModePassword = "developer"
ArgocdInitialAdminSecretName = "argocd-initial-admin-secret"
ArgocdAdminName = "admin"
ArgocdNamespace = "argocd"
Expand Down
1 change: 1 addition & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
passwordLength = 40
numSpecialChars = 3
numDigits = 3
StaticPassword = "developer"
)

func GetCLIStartTimeAnnotationValue(annotations map[string]string) (string, error) {
Expand Down

0 comments on commit 570ca30

Please sign in to comment.