- java.lang.Object
-
- net.morimekta.config.SecretsManager
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class SecretsManager extends Object implements Closeable
A class managing secrets as read from files in a single directory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSecretsManager.SecretManagerDeserializerA deserializer for secrets manager to make it easy to include the manager in a standard jackson-parsed config file (JSON or YAML).static classSecretsManager.SecretsConfigSimple configuration of the secrets manager as an object.
-
Constructor Summary
Constructors Constructor Description SecretsManager(Path secretsDir)Create a secrets manager getting secrets from the specified directory.SecretsManager(Path secretsDir, net.morimekta.file.FileWatcher fileWatcher)Create a secrets manager getting secrets from the specified directory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanexists(String name)Check if secret with given name exists.Secretget(String name)Get a named secret from the secret store.net.morimekta.collect.util.BinarygetAsBinary(String name)Get a named secret from the secret store as a binary.byte[]getAsBytes(String name)Get a named secret from the secret store as a byte array.PathgetAsPath(String name)Get the path to a named secret from the secret store.StringgetAsString(String name)Get a named secret from the secret store as a string.Set<String>getKnownSecrets()PathgetSecretsPath()StringtoString()
-
-
-
Constructor Detail
-
SecretsManager
public SecretsManager(Path secretsDir) throws IOException
Create a secrets manager getting secrets from the specified directory.- Parameters:
secretsDir- The secrets directory. All non-hidden files in the- Throws:
IOException- If the path does not point to an existing directory.
-
SecretsManager
public SecretsManager(Path secretsDir, net.morimekta.file.FileWatcher fileWatcher) throws IOException
Create a secrets manager getting secrets from the specified directory.- Parameters:
secretsDir- The secrets' directory. All non-hidden files in thefileWatcher- File watcher used to get file events.- Throws:
IOException- If the path does not point to an existing directory.
-
-
Method Detail
-
getSecretsPath
public Path getSecretsPath()
- Returns:
- Get the configured secrets directory path.
-
exists
public boolean exists(String name)
Check if secret with given name exists.- Parameters:
name- The secret name.- Returns:
- If the secret exists.
-
getKnownSecrets
public Set<String> getKnownSecrets()
- Returns:
- Get a list a set of known secret names.
-
getAsPath
public Path getAsPath(String name)
Get the path to a named secret from the secret store.- Parameters:
name- The secret name.- Returns:
- The secret file path.
-
getAsString
public String getAsString(String name)
Get a named secret from the secret store as a string.- Parameters:
name- The secret name.- Returns:
- The secret value as a string.
-
getAsBytes
public byte[] getAsBytes(String name)
Get a named secret from the secret store as a byte array.- Parameters:
name- The secret name.- Returns:
- The secret value as a string.
-
getAsBinary
public net.morimekta.collect.util.Binary getAsBinary(String name)
Get a named secret from the secret store as a binary.- Parameters:
name- The secret name.- Returns:
- The secret value as a binary.
-
get
public Secret get(String name)
Get a named secret from the secret store.- Parameters:
name- The secret name.- Returns:
- The loaded secret.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-