Search in sources :

Example 1 with Arguments

use of io.cdap.common.cli.Arguments in project cdap by caskdata.

the class ListPrivilegesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String principalType = arguments.get(ArgumentName.PRINCIPAL_TYPE.toString());
    String principalName = arguments.get(ArgumentName.PRINCIPAL_NAME.toString());
    Table table = Table.builder().setHeader("Authorizable", "Action").setRows(Lists.newArrayList(client.listGrants(new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())))), grantedPermission -> Lists.newArrayList(grantedPermission.getAuthorizable().toString(), grantedPermission.getPermission().name())).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : PrintStream(java.io.PrintStream) Principal(io.cdap.cdap.proto.security.Principal) Lists(com.google.common.collect.Lists) ArgumentName(io.cdap.cdap.cli.ArgumentName) Table(io.cdap.cdap.cli.util.table.Table) Inject(com.google.inject.Inject) CLIConfig(io.cdap.cdap.cli.CLIConfig) AuthorizationClient(io.cdap.cdap.client.AuthorizationClient) Privilege(io.cdap.cdap.proto.security.Privilege) AbstractAuthCommand(io.cdap.cdap.cli.util.AbstractAuthCommand) Arguments(io.cdap.common.cli.Arguments) Table(io.cdap.cdap.cli.util.table.Table) Principal(io.cdap.cdap.proto.security.Principal)

Example 2 with Arguments

use of io.cdap.common.cli.Arguments in project cdap by caskdata.

the class GetMetadataCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
    String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
    Set<MetadataRecord> metadata = scope == null ? client.getMetadata(metadataEntity) : client.getMetadata(metadataEntity, MetadataScope.valueOf(scope.toUpperCase()));
    Table table = getTableBuilder().setRows(metadata.stream().map(record -> Lists.newArrayList(record.toString(), Joiner.on("\n").join(record.getTags()), Joiner.on("\n").withKeyValueSeparator(":").join(record.getProperties()), record.getScope().name())).collect(Collectors.toList())).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : MetadataRecord(io.cdap.cdap.common.metadata.MetadataRecord) PrintStream(java.io.PrintStream) Table(io.cdap.cdap.cli.util.table.Table) Inject(com.google.inject.Inject) Set(java.util.Set) Collectors(java.util.stream.Collectors) MetadataClient(io.cdap.cdap.client.MetadataClient) Lists(com.google.common.collect.Lists) ArgumentName(io.cdap.cdap.cli.ArgumentName) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) CLIConfig(io.cdap.cdap.cli.CLIConfig) AbstractCommand(io.cdap.cdap.cli.util.AbstractCommand) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Arguments(io.cdap.common.cli.Arguments) Joiner(com.google.common.base.Joiner) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Table(io.cdap.cdap.cli.util.table.Table) MetadataRecord(io.cdap.cdap.common.metadata.MetadataRecord)

Example 3 with Arguments

use of io.cdap.common.cli.Arguments in project cdap by caskdata.

the class SearchMetadataCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String searchQuery = arguments.get(ArgumentName.SEARCH_QUERY.toString());
    String type = arguments.getOptional(ArgumentName.TARGET_TYPE.toString());
    MetadataSearchResponse metadataSearchResponse = metadataClient.searchMetadata(cliConfig.getCurrentNamespace(), searchQuery, parseTargetType(type), null, 0, Integer.MAX_VALUE, 0, null, false);
    Set<MetadataSearchResultRecord> searchResults = metadataSearchResponse.getResults();
    Table table = Table.builder().setHeader("Entity").setRows(Lists.newArrayList(searchResults), searchResult -> Lists.newArrayList(searchResult.getEntityId().toString())).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : MetadataSearchResponse(io.cdap.cdap.proto.metadata.MetadataSearchResponse) PrintStream(java.io.PrintStream) ImmutableSet(com.google.common.collect.ImmutableSet) Table(io.cdap.cdap.cli.util.table.Table) Inject(com.google.inject.Inject) Set(java.util.Set) MetadataClient(io.cdap.cdap.client.MetadataClient) Lists(com.google.common.collect.Lists) ArgumentName(io.cdap.cdap.cli.ArgumentName) MetadataSearchResultRecord(io.cdap.cdap.proto.metadata.MetadataSearchResultRecord) CLIConfig(io.cdap.cdap.cli.CLIConfig) AbstractCommand(io.cdap.cdap.cli.util.AbstractCommand) Splitter(com.google.common.base.Splitter) Arguments(io.cdap.common.cli.Arguments) Table(io.cdap.cdap.cli.util.table.Table) MetadataSearchResultRecord(io.cdap.cdap.proto.metadata.MetadataSearchResultRecord) MetadataSearchResponse(io.cdap.cdap.proto.metadata.MetadataSearchResponse)

Aggregations

Lists (com.google.common.collect.Lists)3 Inject (com.google.inject.Inject)3 ArgumentName (io.cdap.cdap.cli.ArgumentName)3 CLIConfig (io.cdap.cdap.cli.CLIConfig)3 Table (io.cdap.cdap.cli.util.table.Table)3 Arguments (io.cdap.common.cli.Arguments)3 PrintStream (java.io.PrintStream)3 AbstractCommand (io.cdap.cdap.cli.util.AbstractCommand)2 MetadataClient (io.cdap.cdap.client.MetadataClient)2 Set (java.util.Set)2 Joiner (com.google.common.base.Joiner)1 Splitter (com.google.common.base.Splitter)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)1 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)1 AbstractAuthCommand (io.cdap.cdap.cli.util.AbstractAuthCommand)1 AuthorizationClient (io.cdap.cdap.client.AuthorizationClient)1 MetadataRecord (io.cdap.cdap.common.metadata.MetadataRecord)1 MetadataSearchResponse (io.cdap.cdap.proto.metadata.MetadataSearchResponse)1 MetadataSearchResultRecord (io.cdap.cdap.proto.metadata.MetadataSearchResultRecord)1