Skip to content

Commit c021b26

Browse files
authored
Add name to NamespacePolicy and TablePolicy (#2466)
1 parent 8c96c1a commit c021b26

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
@@ -492,27 +492,27 @@ public Optional<UserTagInfo> getUserTagInfo(String policyName, String username)
492492
}
493493

494494
@Override
495-
public void applyPolicyToNamespace(String policyName, String namespaceName)
495+
public void createNamespacePolicy(
496+
String namespacePolicyName, String policyName, String namespaceName)
496497
throws ExecutionException {
497-
distributedTransactionAdmin.applyPolicyToNamespace(policyName, namespaceName);
498+
distributedTransactionAdmin.createNamespacePolicy(
499+
namespacePolicyName, policyName, namespaceName);
498500
}
499501

500502
@Override
501-
public void enableNamespacePolicy(String policyName, String namespaceName)
502-
throws ExecutionException {
503-
distributedTransactionAdmin.enableNamespacePolicy(policyName, namespaceName);
503+
public void enableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
504+
distributedTransactionAdmin.enableNamespacePolicy(namespacePolicyName);
504505
}
505506

506507
@Override
507-
public void disableNamespacePolicy(String policyName, String namespaceName)
508-
throws ExecutionException {
509-
distributedTransactionAdmin.disableNamespacePolicy(policyName, namespaceName);
508+
public void disableNamespacePolicy(String namespacePolicyName) throws ExecutionException {
509+
distributedTransactionAdmin.disableNamespacePolicy(namespacePolicyName);
510510
}
511511

512512
@Override
513-
public Optional<NamespacePolicy> getNamespacePolicy(String policyName, String namespaceName)
513+
public Optional<NamespacePolicy> getNamespacePolicy(String namespacePolicyName)
514514
throws ExecutionException {
515-
return distributedTransactionAdmin.getNamespacePolicy(policyName, namespaceName);
515+
return distributedTransactionAdmin.getNamespacePolicy(namespacePolicyName);
516516
}
517517

518518
@Override
@@ -521,27 +521,26 @@ public List<NamespacePolicy> getNamespacePolicies() throws ExecutionException {
521521
}
522522

523523
@Override
524-
public void applyPolicyToTable(String policyName, String namespaceName, String tableName)
524+
public void createTablePolicy(
525+
String tablePolicyName, String policyName, String namespaceName, String tableName)
525526
throws ExecutionException {
526-
distributedTransactionAdmin.applyPolicyToTable(policyName, namespaceName, tableName);
527+
distributedTransactionAdmin.createTablePolicy(
528+
tablePolicyName, policyName, namespaceName, tableName);
527529
}
528530

529531
@Override
530-
public void enableTablePolicy(String policyName, String namespaceName, String tableName)
531-
throws ExecutionException {
532-
distributedTransactionAdmin.enableTablePolicy(policyName, namespaceName, tableName);
532+
public void enableTablePolicy(String tablePolicyName) throws ExecutionException {
533+
distributedTransactionAdmin.enableTablePolicy(tablePolicyName);
533534
}
534535

535536
@Override
536-
public void disableTablePolicy(String policyName, String namespaceName, String tableName)
537-
throws ExecutionException {
538-
distributedTransactionAdmin.disableTablePolicy(policyName, namespaceName, tableName);
537+
public void disableTablePolicy(String tablePolicyName) throws ExecutionException {
538+
distributedTransactionAdmin.disableTablePolicy(tablePolicyName);
539539
}
540540

541541
@Override
542-
public Optional<TablePolicy> getTablePolicy(
543-
String policyName, String namespaceName, String tableName) throws ExecutionException {
544-
return distributedTransactionAdmin.getTablePolicy(policyName, namespaceName, tableName);
542+
public Optional<TablePolicy> getTablePolicy(String tablePolicyName) throws ExecutionException {
543+
return distributedTransactionAdmin.getTablePolicy(tablePolicyName);
545544
}
546545

547546
@Override

0 commit comments

Comments
 (0)