lasdf1234 commented on code in PR #14954:
URL: https://github.com/apache/gravitino/pull/14954#discussion_r4560919720
##########
common/src/main/java/org/apache/gravitino/secret/SecretProvider.java:
##########
@@ -68,12 +70,88 @@ public interface SecretProvider {
String readSecret(SecretUrn urn);
/**
- * Deletes a secret by URN.
+ * Deletes a secret by URN, including every version of it.
*
* @param urn the secret URN
*/
void deleteSecret(SecretUrn urn);
+ /**
+ * Writes {@code plaintext} as a new version of the write-through secret
{@code urn}.
+ *
+ * <p>The new version becomes the value {@link #readSecret} returns only
when {@code urn} has no
+ * current version. Otherwise the current version stays readable until {@link
+ * #promoteSecretVersion} is called, so a failed entity alter can discard
the new version and keep
+ * the value the entity still references.
+ *
+ * <p>Providers that support write-through must implement this method and
the other version
+ * methods; altering a write-through secret uses them. Providers that only
build external
+ * references can keep the defaults, which throw.
+ *
+ * <p>Version ids are non-blank and are not reused for the same URN until
{@link #deleteSecret}
+ * removes it, because Gravitino deletes replaced versions by id. Gravitino
passes to the other
+ * version methods only ids this provider returned.
+ *
+ * @param urn the write-through secret URN
+ * @param plaintext the secret plaintext
+ * @return the id of the new version
+ * @throws UnsupportedOperationException if this provider does not support
versions
+ */
+ default String writeSecretVersion(SecretUrn urn, String plaintext) {
+ throw new UnsupportedOperationException(type() + " does not support secret
versions");
+ }
+
+ /**
+ * Makes {@code version} the value {@link #readSecret} returns for {@code
urn}.
+ *
+ * <p>Write-through providers must implement this method; see {@link
#writeSecretVersion}.
+ *
+ * <p>If this method throws, the promote must not take effect afterwards,
and {@link
+ * #currentSecretVersion} must already report whether it did: after a failed
promote Gravitino
+ * deletes the previous version if {@code version} is current and {@code
version} otherwise, and
+ * deletes neither if {@code currentSecretVersion} throws. Settle an unknown
outcome before
+ * throwing, for example with a conditional update, and read the current
version with
+ * read-after-write consistency.
+ *
+ * @param urn the write-through secret URN
+ * @param version a version id returned by {@link #writeSecretVersion}
+ * @throws IllegalArgumentException if {@code urn} has no such version
+ * @throws UnsupportedOperationException if this provider does not support
versions
+ */
+ default void promoteSecretVersion(SecretUrn urn, String version) {
+ throw new UnsupportedOperationException(type() + " does not support secret
versions");
Review Comment:
Could u rename to setCurrentSecretVersion?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]