Package org.forgerock.secrets.gcp.sm
Class GoogleSecretManagerSecretStore.Builder
- java.lang.Object
-
- org.forgerock.secrets.gcp.sm.GoogleSecretManagerSecretStore.Builder
-
- Enclosing class:
- GoogleSecretManagerSecretStore
public static class GoogleSecretManagerSecretStore.Builder extends Object
A builder class for configuring an instance of theGoogleSecretManagerSecretStore
. The project name and clock must be specified.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GoogleSecretManagerSecretStore
build()
Builds theGoogleSecretManagerSecretStore
based on the current configuration of the builder.GoogleSecretManagerSecretStore.Builder
clock(Clock clock)
Specifies the clock to use to determine when secrets will expire.GoogleSecretManagerSecretStore.Builder
credentials(com.google.auth.Credentials credentials)
Sets the fixed credentials to use for the connection to GCP.GoogleSecretManagerSecretStore.Builder
credentialsProvider(com.google.api.gax.core.CredentialsProvider credentialsProvider)
Set the provider for credentials for the connection to GCP.GoogleSecretManagerSecretStore.Builder
expiryDuration(Duration duration)
Specifies how long secrets retrieved from Secrets Manager can be cached by clients for.GoogleSecretManagerSecretStore.Builder
formatMapping(Function<Purpose<?>,Optional<SecretDecoder>> formatMapping)
Specifies aSecretDecoder
to use to decode data returned by Secret Manager.GoogleSecretManagerSecretStore.Builder
project(String projectName)
Specifies the GCP project name that contains the secrets.GoogleSecretManagerSecretStore.Builder
purposeMapping(Function<Purpose<?>,String> purposeMapping)
Specifies the GCP secret name to use for the given purpose.GoogleSecretManagerSecretStore.Builder
purposeMapping(Map<Purpose<?>,String> purposeMapping)
Specifies the GCP secret name to use for the given purpose.
-
-
-
Method Detail
-
credentialsProvider
public GoogleSecretManagerSecretStore.Builder credentialsProvider(com.google.api.gax.core.CredentialsProvider credentialsProvider)
Set the provider for credentials for the connection to GCP. See javadoc oncredentials(Credentials)
for details on the available options.- Parameters:
credentialsProvider
- the credentials provider.- Returns:
- this builder.
-
credentials
public GoogleSecretManagerSecretStore.Builder credentials(com.google.auth.Credentials credentials)
Sets the fixed credentials to use for the connection to GCP. In most cases, usingGoogleCredentials.getApplicationDefault()
(orGoogleCredentials.getApplicationDefault(com.google.auth.http.HttpTransportFactory)
making use ofChfHttpTransport
from the secrets-backend-gcpkms maven module) is the right option as this will automatically pick up GCP credentials in many cases. If you need to manually specify credentials you can obtain these from the GCP Console and then either useServiceAccountCredentials
or else the Secrets API can also be used to obtain credentials by using theSecretsApiBearerTokenCredentials
(the latter, from secrets-backend-gcpkms, allows the credentials to be rotated without recreating the secret store).- Parameters:
credentials
- the credentials.- Returns:
- this builder.
-
project
public GoogleSecretManagerSecretStore.Builder project(String projectName)
Specifies the GCP project name that contains the secrets.- Parameters:
projectName
- the name of the GCP project.- Returns:
- this builder object.
-
clock
public GoogleSecretManagerSecretStore.Builder clock(Clock clock)
Specifies the clock to use to determine when secrets will expire.- Parameters:
clock
- the clock.- Returns:
- this builder object.
-
expiryDuration
public GoogleSecretManagerSecretStore.Builder expiryDuration(Duration duration)
Specifies how long secrets retrieved from Secrets Manager can be cached by clients for. Defaults to 30 minutes.- Parameters:
duration
- the maximum amount of time that clients can cache secrets for.- Returns:
- this builder object.
-
purposeMapping
public GoogleSecretManagerSecretStore.Builder purposeMapping(Function<Purpose<?>,String> purposeMapping)
Specifies the GCP secret name to use for the given purpose. The default mapping uses the label of the purpose as the secret name, with all periods replaced with hyphens.Note: the secret names returned by the mapping must conform to the allowed syntax for GCP secret names. (At the time of writing, this is
[0-9a-zA-Z_-]{1,255}
).- Parameters:
purposeMapping
- the purpose mapping function.- Returns:
- this builder object.
-
purposeMapping
public GoogleSecretManagerSecretStore.Builder purposeMapping(Map<Purpose<?>,String> purposeMapping)
Specifies the GCP secret name to use for the given purpose. The default mapping uses the label of the purpose as the secret name, with all periods replaced with hyphens.Note: the secret names returned by the mapping must conform to the allowed syntax for GCP secret names. (At the time of writing, this is
[0-9a-zA-Z_-]{1,255}
).- Parameters:
purposeMapping
- the purpose mapping.- Returns:
- this builder object.
-
formatMapping
public GoogleSecretManagerSecretStore.Builder formatMapping(Function<Purpose<?>,Optional<SecretDecoder>> formatMapping)
Specifies aSecretDecoder
to use to decode data returned by Secret Manager. By default the bytes returned from Secret Manager are used as the raw data of the secret. When a property format is specified for a given purpose then the data returned by Secret Manager is decoded with the given decoder. ReturnOptional.empty()
to indicate that the default (raw) processing should be used.- Parameters:
formatMapping
- a mapping that determines the format of secret data.- Returns:
- this builder object.
-
build
public GoogleSecretManagerSecretStore build()
Builds theGoogleSecretManagerSecretStore
based on the current configuration of the builder.- Returns:
- the constructed secret store.
- Throws:
IllegalArgumentException
- if any configuration options are missing or incorrect.
-
-