Package overit.geocall.secrets
Class CachedSecretsManager
java.lang.Object
overit.geocall.secrets.CachedSecretsManager
- All Implemented Interfaces:
SecretsManager
SecretsManager implementation that get secrets from a remote secret manager, storing them in a local
cache and in a Redis cache, to optimize subsequent secret calls.-
Field Summary
Fields inherited from interface overit.geocall.secrets.SecretsManager
CURRENT_SUFFIX, LOG, NAME_CANNOT_BE_NULL, PREVIOUS_SUFFIX, THE_SECRET_HAS_NOT_BEEN_FOUND_FOR_THE_VERSION, VERSION_ID_CANNOT_BE_NULL -
Constructor Summary
ConstructorsConstructorDescriptionCachedSecretsManager(Long companyId, SecretsManagerClient client) Returns a newCachedSecretsManagerusing the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all the secrets saved in a local cache.Fetches aSecretby its name, returning it if found, otherwise aSecretsManagerExceptionis thrown.Fetches aSecretby its name and versionId, returning it if found, otherwise aSecretsManagerExceptionis thrown.getPrevious(@NotNull String name) Retrieves the previous value of theSecretif found, otherwise aSecretsManagerExceptionis thrown.optionalGet(@NotNull String name) optionalGet(String name, @NotNull String versionId) Fetches the previous value of aSecretby its name returning anOptional(Optional.empty()if not found).voidremoveFromCache(@NotNull String name) Removes aSecretfrom the local cache if present.voidremoveFromCache(@NotNull String name, @NotNull String versionId) Removes aSecretfrom the local cache if present.
-
Constructor Details
-
CachedSecretsManager
Returns a newCachedSecretsManagerusing the provided parameters.- Parameters:
companyId-Longabout the company ID. Usenullvalue if the secret doesn't belong to any company but is shared across all of themclient-SecretsManagerClientabout the secrets manager client.
-
-
Method Details
-
get
Description copied from interface:SecretsManagerFetches aSecretby its name, returning it if found, otherwise aSecretsManagerExceptionis thrown.- Specified by:
getin interfaceSecretsManager- Parameters:
name- the unique name of the secret- Returns:
- the secret if found, otherwise a
SecretsManagerExceptionis thrown. - Throws:
SecretsManagerException- in case of errors while communicating with the secret manager or in case the requested secret has not been found.
-
get
public Secret get(@NotNull @NotNull String name, @NotNull @NotNull String versionId) throws SecretsManagerException Description copied from interface:SecretsManagerFetches aSecretby its name and versionId, returning it if found, otherwise aSecretsManagerExceptionis thrown.- Specified by:
getin interfaceSecretsManager- Parameters:
name- the unique name of the secretversionId- the version identifier of the secret- Returns:
- the secret if found, otherwise a
SecretsManagerExceptionis thrown. - Throws:
SecretsManagerException- in case of errors while communicating with the secret manager or in case the requested secret has not been found.
-
getPrevious
Description copied from interface:SecretsManagerRetrieves the previous value of theSecretif found, otherwise aSecretsManagerExceptionis thrown.- Specified by:
getPreviousin interfaceSecretsManager- Parameters:
name- the unique name of the secret- Returns:
- the previous value of the secret if found, otherwise a
SecretsManagerExceptionis thrown. - Throws:
SecretsManagerException- in case of errors while communicating with the secret manager or in case the requested secret has not been found.
-
optionalGet
Description copied from interface:SecretsManager- Specified by:
optionalGetin interfaceSecretsManager- Parameters:
name- the unique name of the secret- Returns:
- the Optional of the secret (
Optional.empty()if not found) - Throws:
SecretsManagerException- in case of errors while communicating with the secret manager.
-
optionalGet
public Optional<Secret> optionalGet(String name, @NotNull @NotNull String versionId) throws SecretsManagerException Description copied from interface:SecretsManager- Specified by:
optionalGetin interfaceSecretsManager- Parameters:
name- the unique name of the secretversionId- the version identifier of the secret- Returns:
- the Optional of the secret (
Optional.empty()if not found) - Throws:
SecretsManagerException- in case of errors while communicating with the secret manager.
-
optionalGetPrevious
public Optional<Secret> optionalGetPrevious(@NotNull @NotNull String name) throws SecretsManagerException Description copied from interface:SecretsManagerFetches the previous value of aSecretby its name returning anOptional(Optional.empty()if not found).- Specified by:
optionalGetPreviousin interfaceSecretsManager- Parameters:
name- the unique name of the secret- Returns:
- the Optional of the secret (
Optional.empty()if not found) - Throws:
SecretsManagerException- in case of errors while communicating with the secret manager.
-
clearCache
public void clearCache()Description copied from interface:SecretsManagerClears all the secrets saved in a local cache.- Specified by:
clearCachein interfaceSecretsManager
-
removeFromCache
Description copied from interface:SecretsManagerRemoves aSecretfrom the local cache if present.- Specified by:
removeFromCachein interfaceSecretsManager- Parameters:
name- the unique name of the secret.- Throws:
SecretsManagerException- in case of errors while communicating with the secret manager.
-
removeFromCache
Description copied from interface:SecretsManagerRemoves aSecretfrom the local cache if present.- Specified by:
removeFromCachein interfaceSecretsManager- Parameters:
name- the unique name of the secretversionId- the version identifier of the secret
-