generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go-runtime): use new configuration/secret system
This allows secrets/config to be dynamically updated in most cases (the envar provider being a notable exception). ``` 🐚 ~/dev/ftl $ ftl config set echo.default --inline "anonymous" 🐚 ~/dev/ftl $ ftl config get echo.default "anonymous" 🐚 ~/dev/ftl $ ftl call echo.echo aat/configuration-go-runtime {"message":"Hello, anonymous!!! It is 2024-03-03 07:45:21.237088 +1000 AEST!"} 🐚 ~/dev/ftl $ ftl config set echo.default --inline "Anne" 🐚 ~/dev/ftl $ ftl config get echo.default "Anne" 🐚 ~/dev/ftl $ ftl call echo.echo {"message":"Hello, Anne!!! It is 2024-03-03 07:44:52.2176 +1000 AEST!"} ``` Also made a few tweaks to allow FTL to largely work offline: - Propagate `replace` directives from Go modules into the generated main and external-module `go.mod` files. - Add `--[no-]console` flag that allows building of the console to be skipped. - Put Bit maven builds into offline mode (does not work fully, I think there's another flag to force Maven to use the local repository that needs to be used, but I'm offline and there's nothing in `--help`).
- Loading branch information
1 parent
ab09744
commit f715921
Showing
26 changed files
with
322 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package configuration | ||
|
||
import "context" | ||
|
||
type contextKeySecrets struct{} | ||
|
||
type contextKeyConfig struct{} | ||
|
||
// ContextWithSecrets adds a secrets manager to the given context. | ||
func ContextWithSecrets(ctx context.Context, secretsManager *Manager) context.Context { | ||
return context.WithValue(ctx, contextKeySecrets{}, secretsManager) | ||
} | ||
|
||
// SecretsFromContext retrieves the secrets configuration.Manager previously | ||
// added to the context with [ContextWithConfig]. | ||
func SecretsFromContext(ctx context.Context) *Manager { | ||
s, ok := ctx.Value(contextKeySecrets{}).(*Manager) | ||
if !ok { | ||
panic("no secrets manager in context") | ||
} | ||
return s | ||
} | ||
|
||
// ContextWithConfig adds a configuration manager to the given context. | ||
func ContextWithConfig(ctx context.Context, configManager *Manager) context.Context { | ||
return context.WithValue(ctx, contextKeyConfig{}, configManager) | ||
} | ||
|
||
// ConfigFromContext retrieves the configuration.Manager previously added to the | ||
// context with [ContextWithConfig]. | ||
func ConfigFromContext(ctx context.Context) *Manager { | ||
m, ok := ctx.Value(contextKeyConfig{}).(*Manager) | ||
if !ok { | ||
panic("no configuration manager in context") | ||
} | ||
return m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package configuration | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/alecthomas/kong" | ||
) | ||
|
||
// NewConfigurationManager constructs a new [Manager] with the default providers for configuration. | ||
func NewConfigurationManager(ctx context.Context, configPath string) (*Manager, error) { | ||
conf := DefaultConfigMixin{ | ||
ProjectConfigResolver: ProjectConfigResolver[FromConfig]{ | ||
Config: configPath, | ||
}, | ||
} | ||
_ = kong.ApplyDefaults(&conf) | ||
return conf.NewConfigurationManager(ctx) | ||
} | ||
|
||
// DefaultConfigMixin is a Kong mixin that provides the default configuration manager. | ||
type DefaultConfigMixin struct { | ||
ProjectConfigResolver[FromConfig] | ||
InlineProvider | ||
EnvarProvider[EnvarTypeConfig] | ||
} | ||
|
||
// NewConfigurationManager creates a new configuration manager with the default configuration providers. | ||
func (d DefaultConfigMixin) NewConfigurationManager(ctx context.Context) (*Manager, error) { | ||
return New(ctx, &d.ProjectConfigResolver, []Provider{ | ||
d.InlineProvider, | ||
d.EnvarProvider, | ||
}) | ||
} | ||
|
||
// NewSecretsManager constructs a new [Manager] with the default providers for secrets. | ||
func NewSecretsManager(ctx context.Context, configPath string) (*Manager, error) { | ||
conf := DefaultSecretsMixin{ | ||
ProjectConfigResolver: ProjectConfigResolver[FromSecrets]{ | ||
Config: configPath, | ||
}, | ||
} | ||
_ = kong.ApplyDefaults(&conf) | ||
return conf.NewSecretsManager(ctx) | ||
} | ||
|
||
// DefaultSecretsMixin is a Kong mixin that provides the default secrets manager. | ||
type DefaultSecretsMixin struct { | ||
ProjectConfigResolver[FromSecrets] | ||
InlineProvider | ||
EnvarProvider[EnvarTypeSecrets] | ||
KeychainProvider | ||
OnePasswordProvider | ||
} | ||
|
||
// NewSecretsManager creates a new secrets manager with the default secret providers. | ||
func (d DefaultSecretsMixin) NewSecretsManager(ctx context.Context) (*Manager, error) { | ||
return New(ctx, &d.ProjectConfigResolver, []Provider{ | ||
d.InlineProvider, | ||
d.EnvarProvider, | ||
d.KeychainProvider, | ||
d.OnePasswordProvider, | ||
}) | ||
} |
Oops, something went wrong.