Skip to content

Commit

Permalink
Change environment variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
jgustie committed Apr 20, 2021
1 parent a02f993 commit 3e031e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (

// envLoader adds environment variable overrides to the configuration
func envLoader(cfg *RedSkyConfig) error {
defaultString(&cfg.Overrides.Environment, os.Getenv("REDSKY_ENV"))
defaultString(&cfg.Overrides.ServerIdentifier, os.Getenv("REDSKY_SERVER_IDENTIFIER"))
defaultString(&cfg.Overrides.ServerIssuer, os.Getenv("REDSKY_SERVER_ISSUER"))
defaultString(&cfg.Overrides.Credential.ClientID, os.Getenv("REDSKY_AUTHORIZATION_CLIENT_ID"))
defaultString(&cfg.Overrides.Credential.ClientSecret, os.Getenv("REDSKY_AUTHORIZATION_CLIENT_SECRET"))
defaultString(&cfg.Overrides.Environment, os.Getenv("STORMFORGE_ENV"))
defaultString(&cfg.Overrides.ServerIdentifier, os.Getenv("STORMFORGE_SERVER_IDENTIFIER"))
defaultString(&cfg.Overrides.ServerIssuer, os.Getenv("STORMFORGE_SERVER_ISSUER"))
defaultString(&cfg.Overrides.Credential.ClientID, os.Getenv("STORMFORGE_AUTHORIZATION_CLIENT_ID"))
defaultString(&cfg.Overrides.Credential.ClientSecret, os.Getenv("STORMFORGE_AUTHORIZATION_CLIENT_SECRET"))
return nil
}

Expand All @@ -40,17 +40,17 @@ func EnvironmentMapping(r Reader, includeController bool) (map[string][]byte, er
if err != nil {
return nil, err
}
env["REDSKY_SERVER_IDENTIFIER"] = []byte(srv.Identifier)
env["REDSKY_SERVER_ISSUER"] = []byte(srv.Authorization.Issuer)
env["STORMFORGE_SERVER_IDENTIFIER"] = []byte(srv.Identifier)
env["STORMFORGE_SERVER_ISSUER"] = []byte(srv.Authorization.Issuer)

// Record the authorization information
az, err := CurrentAuthorization(r)
if err != nil {
return nil, err
}
if az.Credential.ClientCredential != nil {
env["REDSKY_AUTHORIZATION_CLIENT_ID"] = []byte(az.Credential.ClientID)
env["REDSKY_AUTHORIZATION_CLIENT_SECRET"] = []byte(az.Credential.ClientSecret)
env["STORMFORGE_AUTHORIZATION_CLIENT_ID"] = []byte(az.Credential.ClientID)
env["STORMFORGE_AUTHORIZATION_CLIENT_SECRET"] = []byte(az.Credential.ClientSecret)
}

// Optionally record environment variables from the controller configuration
Expand All @@ -67,7 +67,7 @@ func EnvironmentMapping(r Reader, includeController bool) (map[string][]byte, er
// The controller needs it's issuer to match the registration host
if u, err := url.Parse(srv.Authorization.RegistrationEndpoint); err == nil {
u.Path = "/"
env["REDSKY_SERVER_ISSUER"] = []byte(u.String())
env["STORMFORGE_SERVER_ISSUER"] = []byte(u.String())
}
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/config/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func migrationLoader(cfg *RedSkyConfig) error {
return err
}

// Migrate the old environment variables
if err := migrateRedSkyEnv(cfg); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -137,3 +142,15 @@ func migrateXDGRedSky(cfg *RedSkyConfig) error {

return nil
}

// migrateRedSkyEnv migrates the old environment variables.
func migrateRedSkyEnv(cfg *RedSkyConfig) error {
// This should be consistent with the expected behavior because migrations
// run after environment loading and we are only applying defaults to overrides
defaultString(&cfg.Overrides.Environment, os.Getenv("REDSKY_ENV"))
defaultString(&cfg.Overrides.ServerIdentifier, os.Getenv("REDSKY_SERVER_IDENTIFIER"))
defaultString(&cfg.Overrides.ServerIssuer, os.Getenv("REDSKY_SERVER_ISSUER"))
defaultString(&cfg.Overrides.Credential.ClientID, os.Getenv("REDSKY_AUTHORIZATION_CLIENT_ID"))
defaultString(&cfg.Overrides.Credential.ClientSecret, os.Getenv("REDSKY_AUTHORIZATION_CLIENT_SECRET"))
return nil
}

0 comments on commit 3e031e2

Please sign in to comment.