Class SecretsManager

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.
  • Constructor Details

    • 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 the
      fileWatcher - File watcher used to get file events.
      Throws:
      IOException - If the path does not point to an existing directory.
  • Method Details

    • 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • toString

      public String toString()
      Overrides:
      toString in class Object