Record Class WebhookKeys

java.lang.Object
java.lang.Record
com.fortemate.dicechess.runtime.WebhookKeys
Record Components:
active - the currently active webhook secret, or null if pending-only
pending - the candidate/pending webhook secret, or null if active-only

public record WebhookKeys(String active, String pending) extends Record
Immutable configuration for active and pending webhook secrets.

Supports three valid states:

  • Active only: normal steady-state operation.
  • Active and pending: zero-downtime rotation cutover during which verification challenges are verified against the pending key, while gameplay deliveries accept either key.
  • Pending only: initial registration of a new bot before promotion to active.

Secrets are held in their issued representation (e.g. 64 lowercase hex characters) and used directly as UTF-8 bytes for HMAC-SHA256 operations without hex decoding.

To prevent credential leakage, toString() never renders secret key values.

  • Field Details

    • ENV_ACTIVE_SECRET

      public static final String ENV_ACTIVE_SECRET
      Standard environment variable name for the active webhook secret.
      See Also:
    • ENV_PENDING_SECRET

      public static final String ENV_PENDING_SECRET
      Standard environment variable name for the pending/candidate webhook secret.
      See Also:
  • Constructor Details

    • WebhookKeys

      public WebhookKeys(String active, String pending)
      Creates and validates an immutable webhook key configuration.
      Parameters:
      active - the currently active webhook secret, or null
      pending - the candidate/pending webhook secret, or null
      Throws:
      IllegalArgumentException - if neither key is configured, or if any configured key is blank
  • Method Details

    • activeOnly

      public static WebhookKeys activeOnly(String active)
      Creates a configuration containing only an active key.
      Parameters:
      active - the active webhook secret
      Returns:
      the key configuration
      Throws:
      NullPointerException - if active is null
      IllegalArgumentException - if active is blank
    • pendingOnly

      public static WebhookKeys pendingOnly(String pending)
      Creates a configuration containing only a pending key.
      Parameters:
      pending - the pending webhook secret
      Returns:
      the key configuration
      Throws:
      NullPointerException - if pending is null
      IllegalArgumentException - if pending is blank
    • activeAndPending

      public static WebhookKeys activeAndPending(String active, String pending)
      Creates a configuration containing both an active and a pending key.
      Parameters:
      active - the active webhook secret
      pending - the pending webhook secret
      Returns:
      the key configuration
      Throws:
      NullPointerException - if either key is null
      IllegalArgumentException - if either key is blank
    • of

      public static WebhookKeys of(String active, String pending)
      Convenience factory for creating a configuration with optional active and pending keys.
      Parameters:
      active - the active secret, or null
      pending - the pending secret, or null
      Returns:
      the key configuration
      Throws:
      IllegalArgumentException - if neither key is configured, or if any configured key is blank
    • fromEnvironment

      public static WebhookKeys fromEnvironment()
      Creates a key configuration from the default system environment variables ("DICECHESS_WEBHOOK_SECRET" and "DICECHESS_WEBHOOK_NEXT_SECRET").
      Returns:
      the key configuration resolved from environment variables
      Throws:
      IllegalArgumentException - if neither environment variable is configured or non-blank
    • fromEnvironment

      public static WebhookKeys fromEnvironment(Map<String,String> env)
      Creates a key configuration from a specified environment map.
      Parameters:
      env - the environment mapping to read keys from
      Returns:
      the key configuration
      Throws:
      NullPointerException - if env is null
      IllegalArgumentException - if neither environment variable is configured or non-blank
    • hasActive

      public boolean hasActive()
      Returns whether an active key is configured.
      Returns:
      true if active key is present
    • hasPending

      public boolean hasPending()
      Returns whether a pending key is configured.
      Returns:
      true if pending key is present
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • active

      public String active()
      Returns the value of the active record component.
      Returns:
      the value of the active record component
    • pending

      public String pending()
      Returns the value of the pending record component.
      Returns:
      the value of the pending record component