java.lang.Object
codes.grow.packages.awssecretsmanager.secrets.SecretValue

public final class SecretValue extends Object
A secret value that never prints itself (SPEC section 3). toString() returns SecretValue([REDACTED]) and JSON serialisation "[REDACTED]".
  • Method Details

    • of

      public static SecretValue of(String value)
      Wraps UTF-8 text.
      Parameters:
      value - text
      Returns:
      a new value without version
    • of

      public static SecretValue of(String value, String version)
      Wraps UTF-8 text with a version.
      Parameters:
      value - text
      version - opaque version, may be null
      Returns:
      a new value
    • ofBytes

      public static SecretValue ofBytes(byte[] value, String version)
      Wraps a copy of raw bytes.
      Parameters:
      value - bytes
      version - opaque version, may be null
      Returns:
      a new value
    • reveal

      public String reveal()
      Returns the value as UTF-8 text.
      Returns:
      the text
      Throws:
      ValidationException - when the bytes are not valid UTF-8
    • revealBytes

      public byte[] revealBytes()
      Returns a copy of the raw bytes.
      Returns:
      the bytes
    • json

      public <T> T json(Class<T> type)
      Decodes the value as JSON.
      Type Parameters:
      T - target type
      Parameters:
      type - target class (JsonNode.class or Object.class for any JSON)
      Returns:
      the decoded value
      Throws:
      ValidationException - when the value is not JSON
    • json

      public <T> T json(com.fasterxml.jackson.core.type.TypeReference<T> type)
      Decodes the value as JSON into a generic type.
      Type Parameters:
      T - target type
      Parameters:
      type - target type reference
      Returns:
      the decoded value
      Throws:
      ValidationException - when the value is not JSON
    • jsonNode

      public com.fasterxml.jackson.databind.JsonNode jsonNode()
      Parses the value as a JSON tree.
      Returns:
      the tree
      Throws:
      ValidationException - when the value is not JSON
    • version

      public Optional<String> version()
      Returns the opaque version (KV version, AWS VersionId, ...).
      Returns:
      the version, or empty
    • sha256

      public String sha256()
      Returns the SHA-256 of the value (hex), used to detect changes without a version.
      Returns:
      lower-case hex digest
    • sameAs

      public boolean sameAs(SecretValue other)
      Returns whether both hold the same bytes and version (constant-time byte comparison).
      Parameters:
      other - another value
      Returns:
      true when equal
    • clear

      public void clear()
      Overwrites the bytes with zeros; the value is unusable afterwards.
    • toString

      public String toString()
      Overrides:
      toString in class Object