Skip to content

Commit d7042ab

Browse files
Backport to branch(3) : Add name to NamespacePolicy and TablePolicy (#2470)
Co-authored-by: Toshihiro Suzuki <[email protected]>
1 parent 9dbea1a commit d7042ab

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed

core/src/main/java/com/scalar/db/api/AbacAdmin.java

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -339,51 +339,48 @@ default Optional<UserTagInfo> getUserTagInfo(String policyName, String username)
339339
}
340340

341341
/**
342-
* Applies the given policy to the given namespace.
342+
* Creates a namespace policy with the given policy and the given namespace.
343343
*
344+
* @param namespacePolicyName the namespace policy name
344345
* @param policyName the policy name
345346
* @param namespaceName the namespace name
346347
* @throws ExecutionException if the operation fails
347348
*/
348-
default void applyPolicyToNamespace(String policyName, String namespaceName)
349+
default void createNamespacePolicy(
350+
String namespacePolicyName, String policyName, String namespaceName)
349351
throws ExecutionException {
350352
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
351353
}
352354

353355
/**
354-
* Enables the given policy for the given namespace.
356+
* Enables a namespace policy that has the given name.
355357
*
356-
* @param policyName the policy name
357-
* @param namespaceName the namespace name
358+
* @param namespacePolicyName the namespace policy name
358359
* @throws ExecutionException if the operation fails
359360
*/
360-
default void enableNamespacePolicy(String policyName, String namespaceName)
361-
throws ExecutionException {
361+
default void enableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
362362
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
363363
}
364364

365365
/**
366-
* Disables the given policy for the given namespace.
366+
* Disables a namespace policy that has the given name.
367367
*
368-
* @param policyName the policy name
369-
* @param namespaceName the namespace name
368+
* @param namespacePolicyName the namespace policy name
370369
* @throws ExecutionException if the operation fails
371370
*/
372-
default void disableNamespacePolicy(String policyName, String namespaceName)
373-
throws ExecutionException {
371+
default void disableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
374372
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
375373
}
376374

377375
/**
378-
* Retrieves the namespace policy for the given namespace.
376+
* Retrieves a namespace policy that has the given name.
379377
*
380-
* @param policyName the policy name
381-
* @param namespaceName the namespace name
378+
* @param namespacePolicyName the namespace policy name
382379
* @return the namespace policy. If the policy is not applied to the namespace, returns an empty
383380
* optional
384381
* @throws ExecutionException if the operation fails
385382
*/
386-
default Optional<NamespacePolicy> getNamespacePolicy(String policyName, String namespaceName)
383+
default Optional<NamespacePolicy> getNamespacePolicy(String namespacePolicyName)
387384
throws ExecutionException {
388385
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
389386
}
@@ -399,55 +396,48 @@ default List<NamespacePolicy> getNamespacePolicies() throws ExecutionException {
399396
}
400397

401398
/**
402-
* Applies the given policy to the given table of the given namespace.
399+
* Creates a table policy with the given policy and the given table.
403400
*
401+
* @param tablePolicyName the table policy name
404402
* @param policyName the policy name
405403
* @param namespaceName the namespace name
406404
* @param tableName the table name
407405
* @throws ExecutionException if the operation fails
408406
*/
409-
default void applyPolicyToTable(String policyName, String namespaceName, String tableName)
407+
default void createTablePolicy(
408+
String tablePolicyName, String policyName, String namespaceName, String tableName)
410409
throws ExecutionException {
411410
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
412411
}
413412

414413
/**
415-
* Enables the given policy of the given table of the given namespace.
414+
* Enables a table policy that has the given name.
416415
*
417-
* @param policyName the policy name
418-
* @param namespaceName the namespace name
419-
* @param tableName the table name
416+
* @param tablePolicyName the table policy name
420417
* @throws ExecutionException if the operation fails
421418
*/
422-
default void enableTablePolicy(String policyName, String namespaceName, String tableName)
423-
throws ExecutionException {
419+
default void enableTablePolicy(String tablePolicyName) throws ExecutionException {
424420
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
425421
}
426422

427423
/**
428-
* Disables the given policy of the given table of the given namespace.
424+
* Disables a table policy that has the given name.
429425
*
430-
* @param policyName the policy name
431-
* @param namespaceName the namespace name
432-
* @param tableName the table name
426+
* @param tablePolicyName the table policy name
433427
* @throws ExecutionException if the operation fails
434428
*/
435-
default void disableTablePolicy(String policyName, String namespaceName, String tableName)
436-
throws ExecutionException {
429+
default void disableTablePolicy(String tablePolicyName) throws ExecutionException {
437430
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
438431
}
439432

440433
/**
441-
* Retrieves the table policy for the given table of the given namespace.
434+
* Retrieves a table policy that has the given name.
442435
*
443-
* @param policyName the policy name
444-
* @param namespaceName the namespace name
445-
* @param tableName the table name
436+
* @param tablePolicyName the table policy name
446437
* @return the table policy. If the policy is not applied to the table, returns an empty optional
447438
* @throws ExecutionException if the operation fails
448439
*/
449-
default Optional<TablePolicy> getTablePolicy(
450-
String policyName, String namespaceName, String tableName) throws ExecutionException {
440+
default Optional<TablePolicy> getTablePolicy(String tablePolicyName) throws ExecutionException {
451441
throw new UnsupportedOperationException(CoreError.ABAC_NOT_ENABLED.buildMessage());
452442
}
453443

@@ -731,6 +721,13 @@ interface GroupInfo {
731721

732722
/** The namespace policy. */
733723
interface NamespacePolicy {
724+
/**
725+
* Returns the namespace policy name.
726+
*
727+
* @return the namespace policy name
728+
*/
729+
String getName();
730+
734731
/**
735732
* Returns the policy name.
736733
*
@@ -755,6 +752,13 @@ interface NamespacePolicy {
755752

756753
/** The table policy. */
757754
interface TablePolicy {
755+
/**
756+
* Returns the table policy name.
757+
*
758+
* @return the table policy name
759+
*/
760+
String getName();
761+
758762
/**
759763
* Returns the policy name.
760764
*

core/src/main/java/com/scalar/db/common/DecoratedDistributedTransactionAdmin.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -481,27 +481,27 @@ public Optional<UserTagInfo> getUserTagInfo(String policyName, String username)
481481
}
482482

483483
@Override
484-
public void applyPolicyToNamespace(String policyName, String namespaceName)
484+
public void createNamespacePolicy(
485+
String namespacePolicyName, String policyName, String namespaceName)
485486
throws ExecutionException {
486-
distributedTransactionAdmin.applyPolicyToNamespace(policyName, namespaceName);
487+
distributedTransactionAdmin.createNamespacePolicy(
488+
namespacePolicyName, policyName, namespaceName);
487489
}
488490

489491
@Override
490-
public void enableNamespacePolicy(String policyName, String namespaceName)
491-
throws ExecutionException {
492-
distributedTransactionAdmin.enableNamespacePolicy(policyName, namespaceName);
492+
public void enableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
493+
distributedTransactionAdmin.enableNamespacePolicy(namespacePolicyName);
493494
}
494495

495496
@Override
496-
public void disableNamespacePolicy(String policyName, String namespaceName)
497-
throws ExecutionException {
498-
distributedTransactionAdmin.disableNamespacePolicy(policyName, namespaceName);
497+
public void disableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
498+
distributedTransactionAdmin.disableNamespacePolicy(namespacePolicyName);
499499
}
500500

501501
@Override
502-
public Optional<NamespacePolicy> getNamespacePolicy(String policyName, String namespaceName)
502+
public Optional<NamespacePolicy> getNamespacePolicy(String namespacePolicyName)
503503
throws ExecutionException {
504-
return distributedTransactionAdmin.getNamespacePolicy(policyName, namespaceName);
504+
return distributedTransactionAdmin.getNamespacePolicy(namespacePolicyName);
505505
}
506506

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

512512
@Override
513-
public void applyPolicyToTable(String policyName, String namespaceName, String tableName)
513+
public void createTablePolicy(
514+
String tablePolicyName, String policyName, String namespaceName, String tableName)
514515
throws ExecutionException {
515-
distributedTransactionAdmin.applyPolicyToTable(policyName, namespaceName, tableName);
516+
distributedTransactionAdmin.createTablePolicy(
517+
tablePolicyName, policyName, namespaceName, tableName);
516518
}
517519

518520
@Override
519-
public void enableTablePolicy(String policyName, String namespaceName, String tableName)
520-
throws ExecutionException {
521-
distributedTransactionAdmin.enableTablePolicy(policyName, namespaceName, tableName);
521+
public void enableTablePolicy(String tablePolicyName) throws ExecutionException {
522+
distributedTransactionAdmin.enableTablePolicy(tablePolicyName);
522523
}
523524

524525
@Override
525-
public void disableTablePolicy(String policyName, String namespaceName, String tableName)
526-
throws ExecutionException {
527-
distributedTransactionAdmin.disableTablePolicy(policyName, namespaceName, tableName);
526+
public void disableTablePolicy(String tablePolicyName) throws ExecutionException {
527+
distributedTransactionAdmin.disableTablePolicy(tablePolicyName);
528528
}
529529

530530
@Override
531-
public Optional<TablePolicy> getTablePolicy(
532-
String policyName, String namespaceName, String tableName) throws ExecutionException {
533-
return distributedTransactionAdmin.getTablePolicy(policyName, namespaceName, tableName);
531+
public Optional<TablePolicy> getTablePolicy(String tablePolicyName) throws ExecutionException {
532+
return distributedTransactionAdmin.getTablePolicy(tablePolicyName);
534533
}
535534

536535
@Override

0 commit comments

Comments
 (0)