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 (#1013)
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!"} ``` I also refactored the `configuration` package such that managers and providers are tied to their role by a type parameter. Finally, I 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. - TODO: Figure out how put maven builds into offline mode
- Loading branch information
1 parent
ab09744
commit a76730c
Showing
33 changed files
with
495 additions
and
281 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
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[Secrets]) 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[Secrets] { | ||
s, ok := ctx.Value(contextKeySecrets{}).(*Manager[Secrets]) | ||
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[Configuration]) 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[Configuration] { | ||
m, ok := ctx.Value(contextKeyConfig{}).(*Manager[Configuration]) | ||
if !ok { | ||
panic("no configuration manager in context") | ||
} | ||
return m | ||
} |
Oops, something went wrong.