Record Class UsageLimitWarning

java.lang.Object
java.lang.Record
co.ankatech.ankasecure.sdk.model.warning.UsageLimitWarning
Record Components:
invocationsRemaining - number of operations remaining before limit (must be positive)
All Implemented Interfaces:
CryptoWarning

public record UsageLimitWarning(int invocationsRemaining) extends Record implements CryptoWarning
Warning indicating that a cryptographic key is approaching its usage limit.

Severity automatically escalates based on remaining operations, enabling applications to implement proactive key rotation strategies before hitting hard limits.

Severity escalation thresholds:

  • CRITICAL - 100 or fewer operations (rotate immediately)
  • WARNING - 101-500 operations (plan rotation soon)
  • NOTICE - 501-1000 operations (monitor and plan)
  • INFO - More than 1000 operations (awareness only)

Example - Operator rotation alert:


 EncryptResult result = sdk.encrypt("high-volume-key", data);

 for (CryptoWarning w : result.getWarnings()) {
     if (w instanceof UsageLimitWarning ulw) {
         if (ulw.invocationsRemaining() <= 50) {
             // Rotation is a control-plane operation — alert the operator to
             // rotate the key via ankasecure-cli-admin before the hard limit.
             logger.warn("Key {} near usage limit — rotate via ankasecure-cli-admin",
                 result.getKeyRequested());
         } else if (ulw.severity() == WarningSeverity.WARNING) {
             logger.warn("{} - {}", ulw.message(), ulw.recommendedAction());
         }
     }
 }
 

Example - Monitoring dashboard integration:


 switch (warning) {
     case UsageLimitWarning ulw when ulw.invocationsRemaining() <= 100 ->
         metrics.gauge("crypto.key.usage_remaining", ulw.invocationsRemaining());
     case UsageLimitWarning ulw ->
         logger.debug("Usage OK: {} operations remaining", ulw.invocationsRemaining());
 }
 
Since:
3.0.0
See Also:
  • Constructor Details

    • UsageLimitWarning

      public UsageLimitWarning(int invocationsRemaining)
      Creates an instance of a UsageLimitWarning record class.
      Parameters:
      invocationsRemaining - the value for the invocationsRemaining record component
  • Method Details

    • severity

      public WarningSeverity severity()
      Description copied from interface: CryptoWarning
      Returns the severity level of this warning.
      Specified by:
      severity in interface CryptoWarning
      Returns:
      warning severity (INFO, NOTICE, WARNING, or CRITICAL)
    • message

      public String message()
      Description copied from interface: CryptoWarning
      Returns a human-readable warning message.
      Specified by:
      message in interface CryptoWarning
      Returns:
      descriptive message
    • recommendedAction

      public String recommendedAction()
      Description copied from interface: CryptoWarning
      Returns the recommended action to address this warning.
      Specified by:
      recommendedAction in interface CryptoWarning
      Returns:
      actionable guidance for the user
    • toString

      public final 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 '=='.
      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.
    • invocationsRemaining

      public int invocationsRemaining()
      Returns the value of the invocationsRemaining record component.
      Returns:
      the value of the invocationsRemaining record component