From 3e031e29c143d1a870c43423ec0183e7abe07b37 Mon Sep 17 00:00:00 2001 From: Jeremy Gustie Date: Tue, 20 Apr 2021 14:35:58 -0400 Subject: [PATCH] Change environment variable names --- pkg/config/env.go | 20 ++++++++++---------- pkg/config/migration.go | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/pkg/config/env.go b/pkg/config/env.go index 4866ff4..01f53b5 100644 --- a/pkg/config/env.go +++ b/pkg/config/env.go @@ -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 } @@ -40,8 +40,8 @@ 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) @@ -49,8 +49,8 @@ func EnvironmentMapping(r Reader, includeController bool) (map[string][]byte, er 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 @@ -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()) } } diff --git a/pkg/config/migration.go b/pkg/config/migration.go index 07a4116..500db68 100644 --- a/pkg/config/migration.go +++ b/pkg/config/migration.go @@ -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 } @@ -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 +}