Skip to content

Commit

Permalink
Add version into legacy secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
psav committed Jun 6, 2022
1 parent c7d39a3 commit 16e66a2
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions controllers/cloud.redhat.com/providers/web/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ type localWebProvider struct {
config backendConfig
}

func setSecretVersion(cache *rc.ObjectCache, nn types.NamespacedName) error {
sec := &core.Secret{}
if err := cache.Get(WebKeycloakSecret, sec, nn); err != nil {
return errors.Wrap("couldn't get secret from cache", err)
}

if v, ok := sec.Data["version"]; !ok || string(v) != KEYCLOAK_VERSION {
if sec.StringData == nil {
sec.StringData = map[string]string{}
}
sec.StringData["version"] = KEYCLOAK_VERSION
}

if err := cache.Update(WebKeycloakSecret, sec); err != nil {
return errors.Wrap("couldn't get secret from cache", err)
}
return nil
}

func NewLocalWebProvider(p *providers.Provider) (providers.ClowderProvider, error) {

if p.Env.Status.Hostname == "" {
Expand All @@ -67,22 +86,24 @@ func NewLocalWebProvider(p *providers.Provider) (providers.ClowderProvider, erro
password = utils.RandString(8)
}

version := KEYCLOAK_VERSION

defaultPassword := utils.RandString(8)

return map[string]string{
"username": username,
"password": password,
"defaultUsername": "jdoe",
"defaultPassword": defaultPassword,
"version": version,
"version": KEYCLOAK_VERSION,
}
}

dataMap, err := providers.MakeOrGetSecret(wp.Ctx, p.Env, wp.Cache, WebKeycloakSecret, nn, dataInit)
if err != nil {
return nil, errors.Wrap("Couldn't set/get secret", err)
return nil, errors.Wrap("couldn't set/get secret", err)
}

if err := setSecretVersion(p.Cache, nn); err != nil {
return nil, errors.Wrap("couldn't set secret version", err)
}

wp.config.KeycloakConfig.Username = (*dataMap)["username"]
Expand Down

0 comments on commit 16e66a2

Please sign in to comment.