Secrets/Config
Configuration
Configuration values are named, typed values. They are managed by the ftl config
command-line.
To declare a configuration value use the following syntax:
var defaultUser = ftl.Config[Username]("defaultUser")
Then to retrieve a configuration value:
username = defaultUser.Get(ctx)
Configuration values can be injected into FTL methods, such as @Verb
, HTTP ingress, Cron etc. To inject a configuration value, use the following syntax:
@Export
@Verb
fun hello(helloRequest: HelloRequest, @Config("defaultUser") defaultUser: String): HelloResponse {
return HelloResponse("Hello, $defaultUser")
}
Configuration values can be injected into FTL methods, such as @Verb
, HTTP ingress, Cron etc. To inject a configuration value, use the following syntax:
@Export
@Verb
HelloResponse hello(HelloRequest helloRequest, @Config("defaultUser") String defaultUser) {
return new HelloResponse("Hello, " + defaultUser);
}
Secrets
Secrets are encrypted, named, typed values. They are managed by the ftl secret
command-line.
Declare a secret with the following:
var apiKey = ftl.Secret[Credentials]("apiKey")
Then to retrieve a secret value:
key = apiKey.Get(ctx)
Configuration values can be injected into FTL methods, such as @Verb
, HTTP ingress, Cron etc. To inject a configuration value, use the following syntax:
@Export
@Verb
fun hello(helloRequest: HelloRequest, @Secret("apiKey") apiKey: String): HelloResponse {
return HelloResponse("Hello, ${api.call(apiKey)}")
}
Configuration values can be injected into FTL methods, such as @Verb
, HTTP ingress, Cron etc. To inject a configuration value, use the following syntax:
@Export
@Verb
HelloResponse hello(HelloRequest helloRequest, @Secret("apiKey") String apiKey) {
return new HelloResponse("Hello, " + api.call(apiKey));
}
Transforming secrets/configuration
Often, raw secret/configuration values aren't directly useful. For example, raw credentials might be used to create an API client. For those situations ftl.Map()
can be used to transform a configuration or secret value into another type:
var client = ftl.Map(ftl.Secret[Credentials]("credentials"),
func(ctx context.Context, creds Credentials) (*api.Client, error) {
return api.NewClient(creds)
})
This is not currently supported in Kotlin or Java.