Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5162] Add basic role commands to Gravitino CLI #5291

Merged
merged 160 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
b5e08c0
Added firest part of CLI code.
justinmclean Oct 2, 2024
655d133
update CLI option with output
justinmclean Oct 2, 2024
4a29c8b
Add missing license header
justinmclean Oct 2, 2024
1b12eff
Add default
justinmclean Oct 2, 2024
75de71e
Spotless on Java 11
justinmclean Oct 2, 2024
5172afa
Ignore warnings in test with Java 11
justinmclean Oct 2, 2024
0dc8856
Disable two tests on JAVA 17
justinmclean Oct 2, 2024
24dee9e
disabling two tests for now
justinmclean Oct 2, 2024
0ddbb7d
fix disabled tests
justinmclean Oct 2, 2024
4b95dd3
Still having issues on Java 17
justinmclean Oct 2, 2024
f76fa16
remove two tests as Java 17 is still giving issues
justinmclean Oct 2, 2024
8cbc605
No need to copy CLI for IT tests
justinmclean Oct 2, 2024
0ec7ecb
create catalogs and other entities
justinmclean Oct 9, 2024
fa2cdaf
remove unneeded call
justinmclean Oct 9, 2024
1e05853
Merge branch 'CLI' into CLI_II
justinmclean Oct 10, 2024
3df9f11
add more tests
justinmclean Oct 11, 2024
5e611be
add more tests
justinmclean Oct 11, 2024
68f7fa2
change version command into client and server version commands
justinmclean Oct 11, 2024
e2ebb7a
list entities and commands
justinmclean Oct 11, 2024
0e82c8f
Cache the metalake environment variable
justinmclean Oct 11, 2024
7b97750
use libs
justinmclean Oct 11, 2024
a562ed7
Merge branch 'main' into CLI
justinmclean Oct 11, 2024
47364fd
Merge branch 'CLI' into CLI_II
justinmclean Oct 12, 2024
d678b99
Trino Connector uses old deprecated CLI
justinmclean Oct 12, 2024
c201ef5
Merge branch 'CLI' into CLI_II
justinmclean Oct 12, 2024
253a2b4
fix test
justinmclean Oct 12, 2024
0ef4695
add basic user and group commands
justinmclean Oct 14, 2024
9320324
basic CLI for tags
justinmclean Oct 14, 2024
b3f081a
complete tag CLI
justinmclean Oct 15, 2024
29c9222
update docs
justinmclean Oct 15, 2024
f90a086
fix spelling error
justinmclean Oct 16, 2024
3c87c3d
add examples not using metalake
justinmclean Oct 16, 2024
10af3d2
remove duplication and clarify
justinmclean Oct 16, 2024
f955db2
use client shadow jar
justinmclean Oct 16, 2024
80aef91
wrong file
justinmclean Oct 16, 2024
f31fb31
basic role operations
justinmclean Oct 16, 2024
2a31d65
basic role operations
justinmclean Oct 17, 2024
6d897c0
new -> 19
justinmclean Oct 17, 2024
76aa1fe
fix example command
justinmclean Oct 17, 2024
affd6ad
revert as the suggested name is not value
justinmclean Oct 17, 2024
abc2da8
simplify command options
justinmclean Oct 17, 2024
a7c2a88
Merge branch 'CLI' into CLI_II
justinmclean Oct 17, 2024
055678b
fix merge issue and tests
justinmclean Oct 17, 2024
9808022
update command options
justinmclean Oct 17, 2024
464a74b
fix imports
justinmclean Oct 17, 2024
05bc9ed
update command options
justinmclean Oct 17, 2024
d27c59a
Merge branch 'CLI_II' into CLI_III
justinmclean Oct 17, 2024
423219c
Merge branch 'main' into CLI
justinmclean Oct 17, 2024
a405bfd
Merge branch 'CLI_IV' of https://github.com/justinmclean/gravitino in…
justinmclean Oct 17, 2024
c60495d
Merge branch 'CLI_V' into CLI_Va
justinmclean Oct 17, 2024
5cf23ed
update readme to new syntax
justinmclean Oct 17, 2024
7479b67
Merge branch 'CLI_V' into CLI_Va
justinmclean Oct 17, 2024
954b351
Make executable and runnable from bin directory. update command format.
justinmclean Oct 22, 2024
808fffc
revert back to using two args and fix command format
justinmclean Oct 22, 2024
848a381
remove meatlake form name and add back metalake option
justinmclean Oct 22, 2024
2fe9a80
add Gravitino URL as an environment variable
justinmclean Oct 22, 2024
526d305
update README to mention environment variables
justinmclean Oct 22, 2024
d2ded4c
improved description of met lake name and add to options docs
justinmclean Oct 22, 2024
cb5a5d7
remove version number from alias
justinmclean Oct 22, 2024
71107fd
order in alphabetical order
justinmclean Oct 22, 2024
a6aeb42
add final where needed
justinmclean Oct 22, 2024
ce3ddc1
made private
justinmclean Oct 22, 2024
70aaaf9
use Joiner instead of StringBuilder
justinmclean Oct 22, 2024
22ca191
update commands
justinmclean Oct 23, 2024
ab52cf2
improve command line error handling
justinmclean Oct 23, 2024
bd57944
add executable shell script
justinmclean Oct 23, 2024
445cd41
put back README and make it developer focused
justinmclean Oct 23, 2024
7ea7125
support ignore option to ignore client/server version mismatch
justinmclean Oct 23, 2024
0a8844e
move list commands up one entity
justinmclean Oct 23, 2024
c342d7e
add comment
justinmclean Oct 23, 2024
d2b28af
no need for class
justinmclean Oct 23, 2024
038e1f6
fix command error handling and unwanted output
justinmclean Oct 23, 2024
ce5fa18
remove example scripts
justinmclean Oct 23, 2024
069f425
add CLI documentation
justinmclean Oct 23, 2024
5ed49fa
Merge branch 'CLI' into CLI_II
justinmclean Oct 23, 2024
4d68055
update tests
justinmclean Oct 23, 2024
f8c1f9b
update commands to use ignore parameter
justinmclean Oct 23, 2024
33efd6e
made variables final
justinmclean Oct 23, 2024
82ba035
remove user-facing content
justinmclean Oct 23, 2024
a4ac180
add URL to config file
justinmclean Oct 24, 2024
1ea9e12
list commands need to run first or warning in output occurs
justinmclean Oct 24, 2024
c3fc55c
add javadocs
justinmclean Oct 24, 2024
451a92f
Merge branch 'CLI_II' into CLI_III
justinmclean Oct 24, 2024
50edda6
add ignore to commands
justinmclean Oct 24, 2024
cb31019
make fields final
justinmclean Oct 24, 2024
dd97d26
simplify output
justinmclean Oct 24, 2024
b47ac45
Merge branch 'CLI_III' into CLI_IV
justinmclean Oct 24, 2024
43546f8
add final
justinmclean Oct 24, 2024
2d268a6
missed one
justinmclean Oct 24, 2024
6ad0af5
simplify output
justinmclean Oct 24, 2024
4b60ea4
Merge branch 'main' into CLI_II
justinmclean Oct 24, 2024
20e550f
reset files
justinmclean Oct 24, 2024
eeefccc
restore test files
justinmclean Oct 24, 2024
9f073ac
add ignore to the config file
justinmclean Oct 24, 2024
64f18ef
update documentation
justinmclean Oct 24, 2024
74452c9
minor English updates
justinmclean Oct 25, 2024
c79c6e3
Merge branch 'CLI_II' into CLI_III
justinmclean Oct 25, 2024
d521410
Merge branch 'CLI_III' into CLI_IV
justinmclean Oct 25, 2024
d6fda74
Merge branch 'CLI_IV' into CLI_V
justinmclean Oct 25, 2024
a919793
Merge branch 'CLI_V' into CLI_Va
justinmclean Oct 27, 2024
f4115c1
add ignore to commands
justinmclean Oct 27, 2024
e751df9
fix README
justinmclean Oct 27, 2024
9e675d4
add missing files
justinmclean Oct 28, 2024
d8c111f
add override annotation
justinmclean Oct 31, 2024
09a5d55
add expections
justinmclean Oct 31, 2024
3a64a1d
add @Override
justinmclean Oct 31, 2024
ccb5e01
update tests
justinmclean Oct 31, 2024
7ab5666
update documentation
justinmclean Oct 31, 2024
8472692
Merge branch 'CLI_II' into CLI_III
justinmclean Oct 31, 2024
ddc0711
add user and group examples
justinmclean Oct 31, 2024
366de9e
Remove different catalog options and classes and add the ability to s…
justinmclean Nov 4, 2024
e133aff
update documentation
justinmclean Nov 4, 2024
6ce9a37
Merge branch 'CLI_II' into CLI_III
justinmclean Nov 5, 2024
36596ef
fix import order
justinmclean Nov 5, 2024
8b65598
add back user and group options
justinmclean Nov 5, 2024
41fc424
update doc and option description
justinmclean Nov 5, 2024
6d5275c
Improved property support
justinmclean Nov 5, 2024
6255901
Merge branch 'main' into CLI_III
justinmclean Nov 6, 2024
145d870
Merge branch 'main' into CLI_IV
justinmclean Nov 6, 2024
2b22e09
Merge branch 'main' into CLI_III
justinmclean Nov 6, 2024
18af138
Delete clients/cli/examples.sh
justinmclean Nov 6, 2024
601c320
Delete clients/cli/src/main/java/org/apache/gravitino/cli/ParseTableC…
justinmclean Nov 6, 2024
ffea521
Update GroupDetails.java
justinmclean Nov 6, 2024
cdbad31
fix documentation
justinmclean Nov 6, 2024
033c04d
fix documentation
justinmclean Nov 6, 2024
f244010
Merge branch 'CLI_III' of https://github.com/justinmclean/gravitino i…
justinmclean Nov 6, 2024
8b826eb
Merge branch 'CLI_III' into CLI_IV
justinmclean Nov 6, 2024
1dcb715
Merge branch 'CLI_IV' into CLI_V
justinmclean Nov 6, 2024
35b862b
remove "--metalake option" from example commands
justinmclean Nov 7, 2024
0ef9947
group, user, and tags commands should be called (merge issue)
justinmclean Nov 7, 2024
112f339
Add are you sure to delete operation and rename metlake
justinmclean Nov 7, 2024
1afc055
forgot to add file
justinmclean Nov 7, 2024
87bd4fa
Merge branch 'main' into CLI_V
justinmclean Nov 11, 2024
2060938
fix merge issues
justinmclean Nov 11, 2024
e72e4b7
Delete clients/cli/docs/README.md
justinmclean Nov 11, 2024
bcc284f
fix merge issue with doc
justinmclean Nov 11, 2024
d6a8c34
Merge branch 'CLI_V' of https://github.com/justinmclean/gravitino int…
justinmclean Nov 11, 2024
bcf9e65
fix again
justinmclean Nov 11, 2024
fa46838
and again
justinmclean Nov 11, 2024
664c832
fix spelling
justinmclean Nov 11, 2024
b4cee89
Merge branch 'CLI_V' into CLI_Va
justinmclean Nov 11, 2024
3b0d628
not needed
justinmclean Nov 11, 2024
2fa3981
removed leading spaces
justinmclean Nov 11, 2024
4eb444b
Merge branch 'CLI_V' into CLI_Va
justinmclean Nov 11, 2024
14cc1e6
fix role description
justinmclean Nov 11, 2024
9315bf7
remove duplicate comment
justinmclean Nov 11, 2024
42334e6
Ask are you sure when deleting roles
justinmclean Nov 11, 2024
c94be3d
Most likely specify metalake on command line when creating a new one …
justinmclean Nov 11, 2024
0b65e68
Merge branch 'CLI_V' into CLI_Va
justinmclean Nov 11, 2024
4dd7b72
fix merge issues
justinmclean Nov 11, 2024
d8d4ac4
Merge branch 'CLI_V' into CLI_Va
justinmclean Nov 11, 2024
5b18949
Merge branch 'main' into CLI_Va
justinmclean Nov 12, 2024
dede58d
Merge branch 'main' into CLI_Va
justinmclean Nov 12, 2024
45b99c1
add back column commands
justinmclean Nov 12, 2024
22bea1f
add missing overrides
justinmclean Nov 12, 2024
82f4b06
only one "-r" flag
justinmclean Nov 12, 2024
78e3d80
simplify and add TODO to role details command
justinmclean Nov 12, 2024
8c344fc
files should be in next PR
justinmclean Nov 12, 2024
8c75cc9
update documentation
justinmclean Nov 12, 2024
94d16e3
simplify code
justinmclean Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CommandEntities {
public static final String USER = "user";
public static final String GROUP = "group";
public static final String TAG = "tag";
public static final String ROLE = "role";

private static final HashSet<String> VALID_ENTITIES = new HashSet<>();

Expand All @@ -46,6 +47,7 @@ public class CommandEntities {
VALID_ENTITIES.add(USER);
VALID_ENTITIES.add(GROUP);
VALID_ENTITIES.add(TAG);
VALID_ENTITIES.add(ROLE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class ErrorMessages {
public static final String GROUP_EXISTS = "Group already exists.";
public static final String UNKNOWN_TAG = "Unknown tag.";
public static final String TAG_EXISTS = "Tag already exists.";
public static final String UNKNOWN_ROLE = "Unknown role.";
public static final String ROLE_EXISTS = "Role already exists.";
public static final String INVALID_SET_COMMAND =
"Unsupported combination of options either use --name or --property and --value.";
public static final String INVALID_REMOVE_COMMAND =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import org.apache.gravitino.cli.commands.CreateCatalog;
import org.apache.gravitino.cli.commands.CreateGroup;
import org.apache.gravitino.cli.commands.CreateMetalake;
import org.apache.gravitino.cli.commands.CreateRole;
import org.apache.gravitino.cli.commands.CreateSchema;
import org.apache.gravitino.cli.commands.CreateTag;
import org.apache.gravitino.cli.commands.CreateUser;
import org.apache.gravitino.cli.commands.DeleteCatalog;
import org.apache.gravitino.cli.commands.DeleteGroup;
import org.apache.gravitino.cli.commands.DeleteMetalake;
import org.apache.gravitino.cli.commands.DeleteRole;
import org.apache.gravitino.cli.commands.DeleteSchema;
import org.apache.gravitino.cli.commands.DeleteTable;
import org.apache.gravitino.cli.commands.DeleteTag;
Expand All @@ -48,6 +50,7 @@
import org.apache.gravitino.cli.commands.ListGroups;
import org.apache.gravitino.cli.commands.ListMetalakeProperties;
import org.apache.gravitino.cli.commands.ListMetalakes;
import org.apache.gravitino.cli.commands.ListRoles;
import org.apache.gravitino.cli.commands.ListSchema;
import org.apache.gravitino.cli.commands.ListSchemaProperties;
import org.apache.gravitino.cli.commands.ListTables;
Expand All @@ -59,6 +62,7 @@
import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
import org.apache.gravitino.cli.commands.RemoveSchemaProperty;
import org.apache.gravitino.cli.commands.RemoveTagProperty;
import org.apache.gravitino.cli.commands.RoleDetails;
import org.apache.gravitino.cli.commands.SchemaAudit;
import org.apache.gravitino.cli.commands.SchemaDetails;
import org.apache.gravitino.cli.commands.ServerVersion;
Expand Down Expand Up @@ -181,6 +185,8 @@ private void executeCommand() {
handleGroupCommand();
} else if (entity.equals(CommandEntities.TAG)) {
handleTagCommand();
} else if (entity.equals(CommandEntities.ROLE)) {
handleRoleCommand();
}
}

Expand Down Expand Up @@ -443,6 +449,25 @@ protected void handleTagCommand() {
}
}

/** Handles the command execution for Roles based on command type and the command line options. */
protected void handleRoleCommand() {
String url = getUrl();
FullName name = new FullName(line);
String metalake = name.getMetalakeName();
String role = line.getOptionValue(GravitinoOptions.ROLE);

if (CommandActions.DETAILS.equals(command)) {
new RoleDetails(url, ignore, metalake, role).handle();
} else if (CommandActions.LIST.equals(command)) {
new ListRoles(url, ignore, metalake).handle();
} else if (CommandActions.CREATE.equals(command)) {
new CreateRole(url, ignore, metalake, role).handle();
} else if (CommandActions.DELETE.equals(command)) {
boolean force = line.hasOption(GravitinoOptions.FORCE);
new DeleteRole(url, ignore, force, metalake, role).handle();
}
}

/**
* Handles the command execution for Columns based on command type and the command line options.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class GravitinoOptions {
public static final String USER = "user";
public static final String GROUP = "group";
public static final String TAG = "tag";
public static final String ROLE = "role";
public static final String AUDIT = "audit";
public static final String FORCE = "force";

Expand All @@ -62,7 +63,7 @@ public Options options() {
options.addOption(createSimpleOption("a", AUDIT, "display audit information"));

// Create/update options
options.addOption(createArgOption("r", RENAME, "new entity name"));
options.addOption(createArgOption(null, RENAME, "new entity name"));
options.addOption(createArgOption("c", COMMENT, "entity comment"));
options.addOption(createArgOption("P", PROPERTY, "property name"));
options.addOption(createArgOption("V", VALUE, "property value"));
Expand All @@ -72,6 +73,7 @@ public Options options() {
options.addOption(createArgOption("l", USER, "user name"));
options.addOption(createArgOption("g", GROUP, "group name"));
options.addOption(createArgOption("t", TAG, "tag name"));
options.addOption(createArgOption("r", ROLE, "role name"));

// Properties option can have multiple values
Option properties =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.gravitino.cli.commands;

import java.util.Collections;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.exceptions.RoleAlreadyExistsException;

public class CreateRole extends Command {
protected String metalake;
protected String role;

/**
* Create a new role.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param metalake The name of the metalake.
* @param role The name of the role.
*/
public CreateRole(String url, boolean ignoreVersions, String metalake, String role) {
super(url, ignoreVersions);
this.metalake = metalake;
this.role = role;
}

/** Create a new role. */
@Override
public void handle() {
try {
GravitinoClient client = buildClient(metalake);
client.createRole(role, null, Collections.EMPTY_LIST);
} catch (NoSuchMetalakeException err) {
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
return;
} catch (RoleAlreadyExistsException err) {
System.err.println(ErrorMessages.ROLE_EXISTS);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

System.out.println(role + " created");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.gravitino.cli.commands;

import org.apache.gravitino.cli.AreYouSure;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.exceptions.NoSuchRoleException;

public class DeleteRole extends Command {

protected String metalake;
protected String role;
protected boolean force;

/**
* Delete a role.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param force Force operation.
* @param metalake The name of the metalake.
* @param role The name of the role.
*/
public DeleteRole(
String url, boolean ignoreVersions, boolean force, String metalake, String role) {
super(url, ignoreVersions);
this.metalake = metalake;
this.force = force;
this.role = role;
}

/** Delete a role. */
@Override
public void handle() {
boolean deleted = false;

if (!AreYouSure.really(force)) {
return;
}

try {
GravitinoClient client = buildClient(metalake);
deleted = client.deleteRole(role);
} catch (NoSuchMetalakeException err) {
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
return;
} catch (NoSuchRoleException err) {
System.err.println(ErrorMessages.UNKNOWN_ROLE);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

if (deleted) {
System.out.println(role + " deleted.");
} else {
System.out.println(role + " not deleted.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.gravitino.cli.commands;

import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;

/* Lists all roles in a metalake. */
public class ListRoles extends Command {

protected String metalake;

/**
* Lists all groups in a metalake.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param metalake The name of the metalake.
*/
public ListRoles(String url, boolean ignoreVersions, String metalake) {
super(url, ignoreVersions);
this.metalake = metalake;
}

/** Lists all roles in a metalake. */
@Override
public void handle() {
String[] roles = new String[0];
try {
GravitinoClient client = buildClient(metalake);
roles = client.listRoleNames();
} catch (NoSuchMetalakeException err) {
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

String all = String.join(",", roles);

System.out.println(all.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.gravitino.cli.commands;

import java.util.List;
import java.util.stream.Collectors;
import org.apache.gravitino.authorization.SecurableObject;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.exceptions.NoSuchUserException;

public class RoleDetails extends Command {

protected String metalake;
protected String role;

/**
* Displays the securable objects in a role.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param metalake The name of the metalake.
* @param role The name of the role.
*/
public RoleDetails(String url, boolean ignoreVersions, String metalake, String role) {
super(url, ignoreVersions);
this.metalake = metalake;
this.role = role;
}

/** Displays the securable objects of a specified role. */
@Override
public void handle() {
List<SecurableObject> objects = null;

try {
GravitinoClient client = buildClient(metalake);
objects = client.getRole(role).securableObjects();
} catch (NoSuchMetalakeException err) {
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
return;
} catch (NoSuchUserException err) {
System.err.println(ErrorMessages.UNKNOWN_GROUP);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

// TODO expand in securable objects PR
String all = objects.stream().map(SecurableObject::name).collect(Collectors.joining(","));

System.out.println(all.toString());
}
}
Loading
Loading