Skip to content

Type Method

secret(key:fileIO:on:)

Reads a file’s content for a secret. The secret key is the name of the environment variable that is expected to specify the path of the file containing the secret.
static func secret(key: String, fileIO: NonBlockingFileIO, on eventLoop: any EventLoop) -> EventLoopFuture<String?>

Parameters

key

The environment variable name

fileIO

NonBlockingFileIO handler provided by NIO

eventLoop

EventLoop for NIO to use for working with the file

Discussion

Example usage:

func configure(_ app: Application) {
    // ...

    let databasePassword = try Environment.secret(
        key: "DATABASE_PASSWORD_FILE",
        fileIO: app.fileio,
        on: app.eventLoopGroup.next()
    ).wait()

Important

Do not use .wait() if loading a secret at any time after the app has booted, such as while handling a Request. Chain the result as you would any other future instead.