Search in sources :

Example 1 with SetAclPOptions

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

the class FileSystemOptionsTest method setAclOptionsDefaults.

@Test
public void setAclOptionsDefaults() {
    SetAclPOptions options = FileSystemOptions.setAclDefaults(mConf);
    assertNotNull(options);
    assertFalse(options.getRecursive());
}
Also used : SetAclPOptions(alluxio.grpc.SetAclPOptions) Test(org.junit.Test)

Example 2 with SetAclPOptions

use of alluxio.grpc.SetAclPOptions 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)

Example 3 with SetAclPOptions

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

the class DelegatingFileSystemTest method setAcl.

@Test
public void setAcl() throws Exception {
    FileSystem fileSystem = new DelegatingFileSystem(mMockFileSystem);
    AlluxioURI alluxioPath = new AlluxioURI("/t");
    List<AclEntry> entries = Arrays.asList(AclEntry.fromCliString("user:nameduser:rwx"));
    SetAclPOptions setAclPOptions = SetAclPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(5L).build()).setRecursive(true).build();
    fileSystem.setAcl(alluxioPath, SetAclAction.MODIFY, entries, setAclPOptions);
    Mockito.verify(mMockFileSystem, atLeastOnce()).setAcl(eq(alluxioPath), eq(SetAclAction.MODIFY), eq(entries), eq(setAclPOptions));
}
Also used : AclEntry(alluxio.security.authorization.AclEntry) SetAclPOptions(alluxio.grpc.SetAclPOptions) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 4 with SetAclPOptions

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

the class SetAclContext method mergeFrom.

/**
 * Merges and embeds the given {@link SetAclPOptions} with the corresponding master options.
 *
 * @param optionsBuilder Builder for proto {@link SetAclPOptions} to merge with defaults
 * @return the instance of {@link SetAclContext} with default values for master
 */
public static SetAclContext mergeFrom(SetAclPOptions.Builder optionsBuilder) {
    SetAclPOptions masterOptions = FileSystemOptions.setAclDefaults(ServerConfiguration.global());
    SetAclPOptions.Builder mergedOptionsBuilder = masterOptions.toBuilder().mergeFrom(optionsBuilder.build());
    return create(mergedOptionsBuilder);
}
Also used : SetAclPOptions(alluxio.grpc.SetAclPOptions)

Example 5 with SetAclPOptions

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

the class BaseFileSystem method setAcl.

@Override
public void setAcl(AlluxioURI path, SetAclAction action, List<AclEntry> entries, SetAclPOptions options) throws FileDoesNotExistException, IOException, AlluxioException {
    checkUri(path);
    rpc(client -> {
        SetAclPOptions mergedOptions = FileSystemOptions.setAclDefaults(mFsContext.getPathConf(path)).toBuilder().mergeFrom(options).build();
        client.setAcl(path, action, entries, mergedOptions);
        LOG.debug("Set ACL for {}, entries: {} options: {}", path.getPath(), entries, mergedOptions);
        return null;
    });
}
Also used : SetAclPOptions(alluxio.grpc.SetAclPOptions)

Aggregations

SetAclPOptions (alluxio.grpc.SetAclPOptions)5 AclEntry (alluxio.security.authorization.AclEntry)2 Test (org.junit.Test)2 AlluxioURI (alluxio.AlluxioURI)1 SetAclAction (alluxio.grpc.SetAclAction)1 ArrayList (java.util.ArrayList)1