Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport to branch(3) : Add name to NamespacePolicy and TablePolicy #2470

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions core/src/main/java/com/scalar/db/api/AbacAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,51 +339,48 @@ default Optional<UserTagInfo> getUserTagInfo(String policyName, String username)
}

/**
* Applies the given policy to the given namespace.
* Creates a namespace policy with the given policy and the given namespace.
*
* @param namespacePolicyName the namespace policy name
* @param policyName the policy name
* @param namespaceName the namespace name
* @throws ExecutionException if the operation fails
*/
default void applyPolicyToNamespace(String policyName, String namespaceName)
default void createNamespacePolicy(
String namespacePolicyName, String policyName, String namespaceName)
throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

/**
* Enables the given policy for the given namespace.
* Enables a namespace policy that has the given name.
*
* @param policyName the policy name
* @param namespaceName the namespace name
* @param namespacePolicyName the namespace policy name
* @throws ExecutionException if the operation fails
*/
default void enableNamespacePolicy(String policyName, String namespaceName)
throws ExecutionException {
default void enableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

/**
* Disables the given policy for the given namespace.
* Disables a namespace policy that has the given name.
*
* @param policyName the policy name
* @param namespaceName the namespace name
* @param namespacePolicyName the namespace policy name
* @throws ExecutionException if the operation fails
*/
default void disableNamespacePolicy(String policyName, String namespaceName)
throws ExecutionException {
default void disableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

/**
* Retrieves the namespace policy for the given namespace.
* Retrieves a namespace policy that has the given name.
*
* @param policyName the policy name
* @param namespaceName the namespace name
* @param namespacePolicyName the namespace policy name
* @return the namespace policy. If the policy is not applied to the namespace, returns an empty
* optional
* @throws ExecutionException if the operation fails
*/
default Optional<NamespacePolicy> getNamespacePolicy(String policyName, String namespaceName)
default Optional<NamespacePolicy> getNamespacePolicy(String namespacePolicyName)
throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}
Expand All @@ -399,55 +396,48 @@ default List<NamespacePolicy> getNamespacePolicies() throws ExecutionException {
}

/**
* Applies the given policy to the given table of the given namespace.
* Creates a table policy with the given policy and the given table.
*
* @param tablePolicyName the table policy name
* @param policyName the policy name
* @param namespaceName the namespace name
* @param tableName the table name
* @throws ExecutionException if the operation fails
*/
default void applyPolicyToTable(String policyName, String namespaceName, String tableName)
default void createTablePolicy(
String tablePolicyName, String policyName, String namespaceName, String tableName)
throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

/**
* Enables the given policy of the given table of the given namespace.
* Enables a table policy that has the given name.
*
* @param policyName the policy name
* @param namespaceName the namespace name
* @param tableName the table name
* @param tablePolicyName the table policy name
* @throws ExecutionException if the operation fails
*/
default void enableTablePolicy(String policyName, String namespaceName, String tableName)
throws ExecutionException {
default void enableTablePolicy(String tablePolicyName) throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

/**
* Disables the given policy of the given table of the given namespace.
* Disables a table policy that has the given name.
*
* @param policyName the policy name
* @param namespaceName the namespace name
* @param tableName the table name
* @param tablePolicyName the table policy name
* @throws ExecutionException if the operation fails
*/
default void disableTablePolicy(String policyName, String namespaceName, String tableName)
throws ExecutionException {
default void disableTablePolicy(String tablePolicyName) throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

/**
* Retrieves the table policy for the given table of the given namespace.
* Retrieves a table policy that has the given name.
*
* @param policyName the policy name
* @param namespaceName the namespace name
* @param tableName the table name
* @param tablePolicyName the table policy name
* @return the table policy. If the policy is not applied to the table, returns an empty optional
* @throws ExecutionException if the operation fails
*/
default Optional<TablePolicy> getTablePolicy(
String policyName, String namespaceName, String tableName) throws ExecutionException {
default Optional<TablePolicy> getTablePolicy(String tablePolicyName) throws ExecutionException {
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
}

Expand Down Expand Up @@ -731,6 +721,13 @@ interface GroupInfo {

/** The namespace policy. */
interface NamespacePolicy {
/**
* Returns the namespace policy name.
*
* @return the namespace policy name
*/
String getName();

/**
* Returns the policy name.
*
Expand All @@ -755,6 +752,13 @@ interface NamespacePolicy {

/** The table policy. */
interface TablePolicy {
/**
* Returns the table policy name.
*
* @return the table policy name
*/
String getName();

/**
* Returns the policy name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,27 +481,27 @@ public Optional<UserTagInfo> getUserTagInfo(String policyName, String username)
}

@Override
public void applyPolicyToNamespace(String policyName, String namespaceName)
public void createNamespacePolicy(
String namespacePolicyName, String policyName, String namespaceName)
throws ExecutionException {
distributedTransactionAdmin.applyPolicyToNamespace(policyName, namespaceName);
distributedTransactionAdmin.createNamespacePolicy(
namespacePolicyName, policyName, namespaceName);
}

@Override
public void enableNamespacePolicy(String policyName, String namespaceName)
throws ExecutionException {
distributedTransactionAdmin.enableNamespacePolicy(policyName, namespaceName);
public void enableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
distributedTransactionAdmin.enableNamespacePolicy(namespacePolicyName);
}

@Override
public void disableNamespacePolicy(String policyName, String namespaceName)
throws ExecutionException {
distributedTransactionAdmin.disableNamespacePolicy(policyName, namespaceName);
public void disableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
distributedTransactionAdmin.disableNamespacePolicy(namespacePolicyName);
}

@Override
public Optional<NamespacePolicy> getNamespacePolicy(String policyName, String namespaceName)
public Optional<NamespacePolicy> getNamespacePolicy(String namespacePolicyName)
throws ExecutionException {
return distributedTransactionAdmin.getNamespacePolicy(policyName, namespaceName);
return distributedTransactionAdmin.getNamespacePolicy(namespacePolicyName);
}

@Override
Expand All @@ -510,27 +510,26 @@ public List<NamespacePolicy> getNamespacePolicies() throws ExecutionException {
}

@Override
public void applyPolicyToTable(String policyName, String namespaceName, String tableName)
public void createTablePolicy(
String tablePolicyName, String policyName, String namespaceName, String tableName)
throws ExecutionException {
distributedTransactionAdmin.applyPolicyToTable(policyName, namespaceName, tableName);
distributedTransactionAdmin.createTablePolicy(
tablePolicyName, policyName, namespaceName, tableName);
}

@Override
public void enableTablePolicy(String policyName, String namespaceName, String tableName)
throws ExecutionException {
distributedTransactionAdmin.enableTablePolicy(policyName, namespaceName, tableName);
public void enableTablePolicy(String tablePolicyName) throws ExecutionException {
distributedTransactionAdmin.enableTablePolicy(tablePolicyName);
}

@Override
public void disableTablePolicy(String policyName, String namespaceName, String tableName)
throws ExecutionException {
distributedTransactionAdmin.disableTablePolicy(policyName, namespaceName, tableName);
public void disableTablePolicy(String tablePolicyName) throws ExecutionException {
distributedTransactionAdmin.disableTablePolicy(tablePolicyName);
}

@Override
public Optional<TablePolicy> getTablePolicy(
String policyName, String namespaceName, String tableName) throws ExecutionException {
return distributedTransactionAdmin.getTablePolicy(policyName, namespaceName, tableName);
public Optional<TablePolicy> getTablePolicy(String tablePolicyName) throws ExecutionException {
return distributedTransactionAdmin.getTablePolicy(tablePolicyName);
}

@Override
Expand Down
Loading