Class Versioned<T>

java.lang.Object
org.springframework.vault.support.Versioned<T>

public class Versioned<T> extends Object
Value object representing versioned secrets along Versioned.Version metadata. A versioned object can hold various states to represent:

Versioned secrets follow a lifecycle that spans from creation to destruction:

  1. Creation of an unversioned secret: Secret is not yet persisted.
  2. Versioned secret: Secret is persisted.
  3. Superseded versioned secret: A newer secret version is stored.
  4. Deleted versioned secret: Version was deleted. Can be undeleted.
  5. Destroyed versioned secret: Version was destroyed.
Since:
2.1
Author:
Mark Paluch, Jeroen Willemsen
See Also:
  • Method Details

    • create

      public static <T> Versioned<T> create(T secret)
      Create a unversioned given secret.
      Parameters:
      secret - must not be null.
      Returns:
      the Versioned object for secret
    • create

      public static <T> Versioned<T> create(@Nullable T secret, Versioned.Version version)
      Create a versioned secret object given secret and Versioned.Version. Versioned secret may contain no actual data as they can be in a deleted/destroyed state.
      Parameters:
      secret - can be null.
      version - must not be null.
      Returns:
      the Versioned object for secret and Version.
    • create

      public static <T> Versioned<T> create(@Nullable T secret, Versioned.Metadata metadata)
      Create a versioned secret object given secret and Versioned.Metadata. Versioned secret may contain no actual data as they can be in a deleted/destroyed state.
      Parameters:
      secret - can be null.
      metadata - must not be null.
      Returns:
      the Versioned object for secret and Versioned.Metadata.
    • getVersion

      public Versioned.Version getVersion()
      Returns:
      the Versioned.Version associated with this Versioned object.
    • hasMetadata

      public boolean hasMetadata()
      Returns:
      true if this versioned object has Versioned.Metadata associated, otherwise false
    • getMetadata

      @Nullable public Versioned.Metadata getMetadata()
    • getRequiredMetadata

      public Versioned.Metadata getRequiredMetadata()
      Returns the required Versioned.Metadata for this versioned object. Throws IllegalStateException if no metadata is associated.
      Returns:
      the non-null Versioned.Metadata held by this for this versioned object.
      Throws:
      IllegalStateException - if no metadata is present.
    • hasData

      public boolean hasData()
      Returns:
      true if this versioned object has data associated, or false, of the version is deleted or destroyed.
    • getData

      @Nullable public T getData()
      Returns:
      the actual data for this versioned object. Can be null if the version is deleted or destroyed.
    • getRequiredData

      public T getRequiredData()
      Returns the required data for this versioned object. Throws IllegalStateException if no data is associated.
      Returns:
      the non-null value held by this for this versioned object.
      Throws:
      IllegalStateException - if no data is present.
    • toOptional

      public Optional<T> toOptional()
      Convert the data element of this versioned object to an Optional.
      Returns:
      Optional holding the actual value of this versioned object if data is present, Optional.empty() if no data is associated.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object