Search in sources :

Example 1 with SetAclAction

use of alluxio.grpc.SetAclAction in project alluxio by Alluxio.

the class SetFaclCommand method runPlainPath.

@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    SetAclPOptions options = SetAclPOptions.newBuilder().setRecursive(cl.hasOption(RECURSIVE_OPTION.getOpt())).build();
    List<AclEntry> entries = Collections.emptyList();
    SetAclAction action = SetAclAction.REPLACE;
    List<String> specifiedActions = new ArrayList<>(1);
    if (cl.hasOption(SET_OPTION.getLongOpt())) {
        specifiedActions.add(SET_OPTION.getLongOpt());
        action = SetAclAction.REPLACE;
        String aclList = cl.getOptionValue(SET_OPTION.getLongOpt());
        if (cl.hasOption(DEFAULT_OPTION.getOpt())) {
            entries = Arrays.stream(aclList.split(",")).map(AclEntry::toDefault).map(AclEntry::fromCliString).collect(Collectors.toList());
        } else {
            entries = Arrays.stream(aclList.split(",")).map(AclEntry::fromCliString).collect(Collectors.toList());
        }
    }
    if (cl.hasOption(MODIFY_OPTION.getOpt())) {
        specifiedActions.add(MODIFY_OPTION.getOpt());
        action = SetAclAction.MODIFY;
        String aclList = cl.getOptionValue(MODIFY_OPTION.getOpt());
        if (cl.hasOption(DEFAULT_OPTION.getOpt())) {
            entries = Arrays.stream(aclList.split(",")).map(AclEntry::toDefault).map(AclEntry::fromCliString).collect(Collectors.toList());
        } else {
            entries = Arrays.stream(aclList.split(",")).map(AclEntry::fromCliString).collect(Collectors.toList());
        }
    }
    if (cl.hasOption(REMOVE_OPTION.getOpt())) {
        specifiedActions.add(REMOVE_OPTION.getOpt());
        action = SetAclAction.REMOVE;
        String aclList = cl.getOptionValue(REMOVE_OPTION.getOpt());
        if (cl.hasOption(DEFAULT_OPTION.getOpt())) {
            entries = Arrays.stream(aclList.split(",")).map(AclEntry::toDefault).map(AclEntry::fromCliStringWithoutPermissions).collect(Collectors.toList());
        } else {
            entries = Arrays.stream(aclList.split(",")).map(AclEntry::fromCliStringWithoutPermissions).collect(Collectors.toList());
        }
    }
    if (cl.hasOption(REMOVE_ALL_OPTION.getOpt())) {
        specifiedActions.add(REMOVE_ALL_OPTION.getOpt());
        action = SetAclAction.REMOVE_ALL;
    }
    if (cl.hasOption(REMOVE_DEFAULT_OPTION.getOpt())) {
        specifiedActions.add(REMOVE_DEFAULT_OPTION.getOpt());
        action = SetAclAction.REMOVE_DEFAULT;
    }
    if (specifiedActions.isEmpty()) {
        throw new IllegalArgumentException("No actions specified.");
    } else if (specifiedActions.size() > 1) {
        throw new IllegalArgumentException("Only 1 action can be specified: " + String.join(", ", specifiedActions));
    }
    mFileSystem.setAcl(path, action, entries, options);
}
Also used : AclEntry(alluxio.security.authorization.AclEntry) ArrayList(java.util.ArrayList) SetAclPOptions(alluxio.grpc.SetAclPOptions) SetAclAction(alluxio.grpc.SetAclAction)

Aggregations

SetAclAction (alluxio.grpc.SetAclAction)1 SetAclPOptions (alluxio.grpc.SetAclPOptions)1 AclEntry (alluxio.security.authorization.AclEntry)1 ArrayList (java.util.ArrayList)1