Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#5061] Basic user and group CLI (#5133)

Justin Mclean3a21ce46c1bc
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java
index 66e6793046..a7703b157c 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java
@@ -31,6 +31,8 @@ public class CommandEntities {
public static final String SCHEMA = "schema";
public static final String TABLE = "table";
public static final String COLUMN = "column";
+ public static final String USER = "user";
+ public static final String GROUP = "group";
private static final HashSet<String> VALID_ENTITIES = new HashSet<>();
@@ -40,6 +42,8 @@ public class CommandEntities {
VALID_ENTITIES.add(SCHEMA);
VALID_ENTITIES.add(TABLE);
VALID_ENTITIES.add(COLUMN);
+ VALID_ENTITIES.add(USER);
+ VALID_ENTITIES.add(GROUP);
}
/**
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
index 0e7816ae43..c3da72ce87 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java
@@ -33,4 +33,8 @@ public class ErrorMessages {
public static final String METALAKE_EXISTS = "Metalake already exists.";
public static final String CATALOG_EXISTS = "Catalog already exists.";
public static final String SCHEMA_EXISTS = "Schema already exists.";
+ public static final String UNKNOWN_USER = "Unknown user.";
+ public static final String USER_EXISTS = "User already exists.";
+ public static final String UNKNOWN_GROUP = "Unknown group.";
+ public static final String GROUP_EXISTS = "Group already exists.";
}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
index 3569563874..566ff88e94 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
@@ -26,20 +26,27 @@ import org.apache.commons.cli.Options;
import org.apache.gravitino.cli.commands.CatalogDetails;
import org.apache.gravitino.cli.commands.ClientVersion;
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.CreateSchema;
+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.DeleteSchema;
import org.apache.gravitino.cli.commands.DeleteTable;
+import org.apache.gravitino.cli.commands.DeleteUser;
+import org.apache.gravitino.cli.commands.GroupDetails;
import org.apache.gravitino.cli.commands.ListCatalogProperties;
import org.apache.gravitino.cli.commands.ListCatalogs;
import org.apache.gravitino.cli.commands.ListColumns;
+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.ListSchema;
import org.apache.gravitino.cli.commands.ListSchemaProperties;
import org.apache.gravitino.cli.commands.ListTables;
+import org.apache.gravitino.cli.commands.ListUsers;
import org.apache.gravitino.cli.commands.MetalakeAuditInfo;
import org.apache.gravitino.cli.commands.MetalakeDetails;
import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
@@ -55,6 +62,7 @@ import org.apache.gravitino.cli.commands.UpdateCatalogComment;
import org.apache.gravitino.cli.commands.UpdateCatalogName;
import org.apache.gravitino.cli.commands.UpdateMetalakeComment;
import org.apache.gravitino.cli.commands.UpdateMetalakeName;
+import org.apache.gravitino.cli.commands.UserDetails;
/* Gravitino Command line */
public class GravitinoCommandLine {
@@ -152,6 +160,10 @@ public class GravitinoCommandLine {
handleCatalogCommand();
} else if (entity.equals(CommandEntities.METALAKE)) {
handleMetalakeCommand();
+ } else if (entity.equals(CommandEntities.USER)) {
+ handleUserCommand();
+ } else if (entity.equals(CommandEntities.GROUP)) {
+ handleGroupCommand();
}
}
@@ -217,7 +229,7 @@ public class GravitinoCommandLine {
} else if (CommandActions.CREATE.equals(command)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
String provider = line.getOptionValue(GravitinoOptions.PROVIDER);
- String properties = line.getOptionValue(GravitinoOptions.PROPERTIES);
+ String[] properties = line.getOptionValues(GravitinoOptions.PROPERTIES);
Map<String, String> propertyMap = new Properties().parse(properties);
new CreateCatalog(url, ignore, metalake, catalog, provider, comment, propertyMap).handle();
} else if (CommandActions.DELETE.equals(command)) {
@@ -304,6 +316,42 @@ public class GravitinoCommandLine {
}
}
+ /** Handles the command execution for Users based on command type and the command line options. */
+ protected void handleUserCommand() {
+ String url = getUrl();
+ FullName name = new FullName(line);
+ String metalake = name.getMetalakeName();
+ String user = line.getOptionValue(GravitinoOptions.USER);
+
+ if (CommandActions.DETAILS.equals(command)) {
+ new UserDetails(url, ignore, metalake, user).handle();
+ } else if (CommandActions.LIST.equals(command)) {
+ new ListUsers(url, ignore, metalake).handle();
+ } else if (CommandActions.CREATE.equals(command)) {
+ new CreateUser(url, ignore, metalake, user).handle();
+ } else if (CommandActions.DELETE.equals(command)) {
+ new DeleteUser(url, ignore, metalake, user).handle();
+ }
+ }
+
+ /** Handles the command execution for Group based on command type and the command line options. */
+ protected void handleGroupCommand() {
+ String url = getUrl();
+ FullName name = new FullName(line);
+ String metalake = name.getMetalakeName();
+ String group = line.getOptionValue(GravitinoOptions.GROUP);
+
+ if (CommandActions.DETAILS.equals(command)) {
+ new GroupDetails(url, ignore, metalake, group).handle();
+ } else if (CommandActions.LIST.equals(command)) {
+ new ListGroups(url, ignore, metalake).handle();
+ } else if (CommandActions.CREATE.equals(command)) {
+ new CreateGroup(url, ignore, metalake, group).handle();
+ } else if (CommandActions.DELETE.equals(command)) {
+ new DeleteGroup(url, ignore, metalake, group).handle();
+ }
+ }
+
/**
* Handles the command execution for Columns based on command type and the command line options.
*/
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
index 53b9fa2ebc..d9ccbb4ad4 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
@@ -37,6 +37,8 @@ public class GravitinoOptions {
public static final String VALUE = "value";
public static final String PROVIDER = "provider";
public static final String PROPERTIES = "properties";
+ public static final String USER = "user";
+ public static final String GROUP = "group";
public static final String AUDIT = "audit";
/**
@@ -64,12 +66,13 @@ public class GravitinoOptions {
options.addOption(createArgOption("V", VALUE, "property value"));
options.addOption(
createArgOption(
- "g", PROVIDER, "provider one of hadoop, hive, mysql, postgres, iceberg, kafka"));
+ "t", PROVIDER, "provider one of hadoop, hive, mysql, postgres, iceberg, kafka"));
+ options.addOption(createArgOption("l", USER, "user name"));
+ options.addOption(createArgOption("g", GROUP, "group name"));
// Properties option can have multiple values
Option properties =
- createArgOption("p", PROPERTIES, "comma separated property name/value pairs");
- properties.hasArgs();
+ Option.builder("p").longOpt(PROPERTIES).desc("property name/value pairs").hasArgs().build();
options.addOption(properties);
return options;
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Properties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Properties.java
index f9985f2353..1c166102fc 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/Properties.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Properties.java
@@ -55,19 +55,21 @@ public class Properties {
* <p>Each pair in the input string is split by the specified delimiter, and then each pair is
* further split by the key-value separator.
*
- * @param input The input string containing name-value pairs.
+ * @param inputs An arrays of input strings containing name-value pairs.
* @return A map of entries, where each entry represents a key-value pair from the input string.
*/
- public Map<String, String> parse(String input) {
+ public Map<String, String> parse(String[] inputs) {
HashMap<String, String> map = new HashMap<>();
- // Split the input by the delimiter into key-value pairs
- String[] pairs = input.split(delimiter);
- for (String pair : pairs) {
- // Split each key-value pair by the separator
- String[] keyValue = pair.split(keyValueSeparator, 2);
- if (keyValue.length == 2) {
- map.put(keyValue[0].trim(), keyValue[1].trim());
+ for (String input : inputs) {
+ // Split the input by the delimiter into key-value pairs
+ String[] pairs = input.split(delimiter);
+ for (String pair : pairs) {
+ // Split each key-value pair by the separator
+ String[] keyValue = pair.split(keyValueSeparator, 2);
+ if (keyValue.length == 2) {
+ map.put(keyValue[0].trim(), keyValue[1].trim());
+ }
}
}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java
new file mode 100644
index 0000000000..8f9fa985d6
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java
@@ -0,0 +1,64 @@
+/*
+ * 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.GroupAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+
+public class CreateGroup extends Command {
+ protected final String metalake;
+ protected final String group;
+
+ /**
+ * Create a new group.
+ *
+ * @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 group The name of the group.
+ */
+ public CreateGroup(String url, boolean ignoreVersions, String metalake, String group) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.group = group;
+ }
+
+ /** Create a new group. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ client.addGroup(group);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (GroupAlreadyExistsException err) {
+ System.err.println(ErrorMessages.GROUP_EXISTS);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(group + " created");
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java
new file mode 100644
index 0000000000..150bf64ce0
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+import org.apache.gravitino.exceptions.UserAlreadyExistsException;
+
+public class CreateUser extends Command {
+ protected final String metalake;
+ protected final String user;
+
+ /**
+ * Create a new User.
+ *
+ * @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 user The name of the user.
+ */
+ public CreateUser(String url, boolean ignoreVersions, String metalake, String user) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.user = user;
+ }
+
+ /** Create a new user. */
+ @Override
+ public void handle() {
+ try {
+ GravitinoClient client = buildClient(metalake);
+ client.addUser(user);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (UserAlreadyExistsException err) {
+ System.err.println(ErrorMessages.USER_EXISTS);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ System.out.println(user + " created");
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java
new file mode 100644
index 0000000000..e137137522
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java
@@ -0,0 +1,71 @@
+/*
+ * 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.NoSuchGroupException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+
+public class DeleteGroup extends Command {
+
+ protected final String metalake;
+ protected final String group;
+
+ /**
+ * Delete a group.
+ *
+ * @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 group The name of the group.
+ */
+ public DeleteGroup(String url, boolean ignoreVersions, String metalake, String group) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.group = group;
+ }
+
+ /** Delete a group. */
+ @Override
+ public void handle() {
+ boolean deleted = false;
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+ deleted = client.removeGroup(group);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchGroupException err) {
+ System.err.println(ErrorMessages.UNKNOWN_GROUP);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ if (deleted) {
+ System.out.println(group + " deleted.");
+ } else {
+ System.out.println(group + " not deleted.");
+ }
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
new file mode 100644
index 0000000000..ae43866a13
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
@@ -0,0 +1,71 @@
+/*
+ * 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;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+
+public class DeleteUser extends Command {
+
+ protected final String metalake;
+ protected final String user;
+
+ /**
+ * Deletes a user.
+ *
+ * @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 user The name of the user.
+ */
+ public DeleteUser(String url, boolean ignoreVersions, String metalake, String user) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.user = user;
+ }
+
+ /** Delete a user. */
+ @Override
+ public void handle() {
+ boolean deleted = false;
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+ deleted = client.removeUser(user);
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchUserException err) {
+ System.err.println(ErrorMessages.UNKNOWN_USER);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ if (deleted) {
+ System.out.println(user + " deleted.");
+ } else {
+ System.out.println(user + " not deleted.");
+ }
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java
new file mode 100644
index 0000000000..d21806ef29
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java
@@ -0,0 +1,70 @@
+/*
+ * 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 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 GroupDetails extends Command {
+
+ protected final String metalake;
+ protected final String group;
+
+ /**
+ * Displays the roles in a group.
+ *
+ * @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 group The name of the group.
+ */
+ public GroupDetails(String url, boolean ignoreVersions, String metalake, String group) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.group = group;
+ }
+
+ /** Displays the roles of a specified group. */
+ @Override
+ public void handle() {
+ List<String> roles = null;
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+ roles = client.getGroup(group).roles();
+ } 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;
+ }
+
+ String all = String.join(",", roles);
+
+ System.out.println(all.toString());
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java
new file mode 100644
index 0000000000..d529b51479
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java
@@ -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 groups in a metalake. */
+public class ListGroups extends Command {
+
+ protected final 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 ListGroups(String url, boolean ignoreVersions, String metalake) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ }
+
+ /** Lists all groups in a metalake. */
+ @Override
+ public void handle() {
+ String[] groups = new String[0];
+ try {
+ GravitinoClient client = buildClient(metalake);
+ groups = client.listGroupNames();
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", groups);
+
+ System.out.println(all.toString());
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java
new file mode 100644
index 0000000000..465075a978
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java
@@ -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 users in a metalake. */
+public class ListUsers extends Command {
+
+ protected final String metalake;
+
+ /**
+ * Lists all users 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 ListUsers(String url, boolean ignoreVersions, String metalake) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ }
+
+ /** Lists all users in a metalake. */
+ @Override
+ public void handle() {
+ String[] users = new String[0];
+ try {
+ GravitinoClient client = buildClient(metalake);
+ users = client.listUserNames();
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", users);
+
+ System.out.println(all.toString());
+ }
+}
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAuditInfo.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAuditInfo.java
index 6c1d49a203..de38078393 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAuditInfo.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAuditInfo.java
@@ -41,6 +41,7 @@ public class MetalakeAuditInfo extends Command {
}
/** Displays the audit information of a metalake. */
+ @Override
public void handle() {
Audit audit;
try (GravitinoClient client = buildClient(metalake)) {
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java
new file mode 100644
index 0000000000..43ebb65e8d
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java
@@ -0,0 +1,70 @@
+/*
+ * 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 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 UserDetails extends Command {
+
+ protected final String metalake;
+ protected final String user;
+
+ /**
+ * Displays the roles of a user.
+ *
+ * @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 user The name of the user.
+ */
+ public UserDetails(String url, boolean ignoreVersions, String metalake, String user) {
+ super(url, ignoreVersions);
+ this.metalake = metalake;
+ this.user = user;
+ }
+
+ /** Displays the roles of a specified user. */
+ @Override
+ public void handle() {
+ List<String> roles = null;
+
+ try {
+ GravitinoClient client = buildClient(metalake);
+ roles = client.getUser(user).roles();
+ } catch (NoSuchMetalakeException err) {
+ System.err.println(ErrorMessages.UNKNOWN_METALAKE);
+ return;
+ } catch (NoSuchUserException err) {
+ System.err.println(ErrorMessages.UNKNOWN_USER);
+ return;
+ } catch (Exception exp) {
+ System.err.println(exp.getMessage());
+ return;
+ }
+
+ String all = String.join(",", roles);
+
+ System.out.println(all.toString());
+ }
+}
diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/PropertiesTest.java b/clients/cli/src/test/java/org/apache/gravitino/cli/PropertiesTest.java
index cdf08a59d6..17af8c21a7 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/PropertiesTest.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/PropertiesTest.java
@@ -30,7 +30,20 @@ public class PropertiesTest {
@Test
public void testDefaultDelimiterAndSeparator() {
Properties properties = new Properties();
- String input = "key1=value1,key2=value2,key3=value3";
+ String[] input = {"key1=value1,key2=value2,key3=value3"};
+
+ Map<String, String> result = properties.parse(input);
+
+ assertEquals(3, result.size());
+ assertEquals("value1", result.get("key1"));
+ assertEquals("value2", result.get("key2"));
+ assertEquals("value3", result.get("key3"));
+ }
+
+ @Test
+ public void testDefaultDelimiterAndSeparatorArray() {
+ Properties properties = new Properties();
+ String[] input = {"key1=value1", "key2=value2", "key3=value3"};
Map<String, String> result = properties.parse(input);
@@ -43,7 +56,20 @@ public class PropertiesTest {
@Test
public void testCustomDelimiterAndSeparator() {
Properties properties = new Properties(";", ":");
- String input = "key1:value1;key2:value2;key3:value3";
+ String[] input = {"key1:value1;key2:value2;key3:value3"};
+
+ Map<String, String> result = properties.parse(input);
+
+ assertEquals(3, result.size());
+ assertEquals("value1", result.get("key1"));
+ assertEquals("value2", result.get("key2"));
+ assertEquals("value3", result.get("key3"));
+ }
+
+ @Test
+ public void testCustomDelimiterAndSeparatorArray() {
+ Properties properties = new Properties(";", ":");
+ String[] input = {"key1:value1;key2:value2", "key3:value3"};
Map<String, String> result = properties.parse(input);
@@ -56,17 +82,27 @@ public class PropertiesTest {
@Test
public void testEmptyInput() {
Properties properties = new Properties();
- String input = "";
+ String input[] = {""};
Map<String, String> result = properties.parse(input);
assertTrue(result.isEmpty(), "Result should be empty for empty input");
}
+ @Test
+ public void testEmptyArray() {
+ Properties properties = new Properties();
+ String input[] = {};
+
+ Map<String, String> result = properties.parse(input);
+
+ assertTrue(result.isEmpty(), "Result should be empty for empty array");
+ }
+
@Test
public void testSinglePair() {
Properties properties = new Properties();
- String input = "key1=value1";
+ String[] input = {"key1=value1"};
Map<String, String> result = properties.parse(input);
@@ -77,7 +113,19 @@ public class PropertiesTest {
@Test
public void testMalformedPair() {
Properties properties = new Properties();
- String input = "key1=value1,key2,key3=value3";
+ String[] input = {"key1=value1,key2,key3=value3"};
+
+ Map<String, String> result = properties.parse(input);
+
+ assertEquals(2, result.size());
+ assertEquals("value1", result.get("key1"));
+ assertEquals("value3", result.get("key3"));
+ }
+
+ @Test
+ public void testMalformedPairArray() {
+ Properties properties = new Properties();
+ String[] input = {"key1=value1", "key2", "key3=value3"};
Map<String, String> result = properties.parse(input);
@@ -89,7 +137,19 @@ public class PropertiesTest {
@Test
public void testWhitespaceHandling() {
Properties properties = new Properties();
- String input = " key1 = value1 , key2 = value2 ";
+ String[] input = {" key1 = value1 , key2 = value2 "};
+
+ Map<String, String> result = properties.parse(input);
+
+ assertEquals(2, result.size());
+ assertEquals("value1", result.get("key1"));
+ assertEquals("value2", result.get("key2"));
+ }
+
+ @Test
+ public void testWhitespaceHandlingArray() {
+ Properties properties = new Properties();
+ String[] input = {" key1 = value1 ", " key2 = value2 "};
Map<String, String> result = properties.parse(input);
@@ -101,7 +161,19 @@ public class PropertiesTest {
@Test
public void testDuplicateKeys() {
Properties properties = new Properties();
- String input = "key1=value1,key1=value2,key2=value3";
+ String[] input = {"key1=value1,key1=value2,key2=value3"};
+
+ Map<String, String> result = properties.parse(input);
+
+ assertEquals(2, result.size());
+ assertEquals("value2", result.get("key1"), "Last value should overwrite previous ones");
+ assertEquals("value3", result.get("key2"));
+ }
+
+ @Test
+ public void testDuplicateKeysArray() {
+ Properties properties = new Properties();
+ String[] input = {"key1=value1", "key1=value2", "key2=value3"};
Map<String, String> result = properties.parse(input);
diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java
index 49ee9770b2..2ca43d0603 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java
@@ -37,8 +37,6 @@ public class TestCommandEntities {
CommandEntities.isValidEntity(CommandEntities.SCHEMA), "SCHEMA should be a valid entity");
assertTrue(
CommandEntities.isValidEntity(CommandEntities.TABLE), "TABLE should be a valid entity");
- assertTrue(
- CommandEntities.isValidEntity(CommandEntities.COLUMN), "COLUMN should be a valid entity");
}
@Test
diff --git a/docs/cli.md b/docs/cli.md
index 5891298155..d54ba2c337 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -30,16 +30,18 @@ The general structure for running commands with the Gravitino CLI is `gcli entit
usage: gcli [metalake|catalog|schema|table|column] [list|details|create|delete|update|set|remove|properties] [options]
Options
-c,--comment <arg> entity comment
- -g,--provider <arg> provider one of hadoop, hive, mysql, postgres,
- iceberg, kafka
+ -g,--group <arg> group name
-h,--help command help information
-i,--ignore Ignore client/sever version check
+ -l,--user <arg> user name
-m,--metalake <arg> Metalake name
-n,--name <arg> full entity name (dot separated)
-P,--property <arg> property name
- -p,--properties <arg> comma separated property name/value pairs
+ -p,--properties <arg> property name/value pairs
-r,--rename <arg> new entity name
-s,--server Gravitino server version
+ -t,--provider <arg> provider one of hadoop, hive, mysql, postgres,
+ iceberg, kafka
-u,--url <arg> Gravitino URL (default: http://localhost:8090)
-v,--version Gravitino client version
-V,--value <arg> property value
@@ -134,6 +136,16 @@ If the client and server are running different versions of the Gravitino softwar
2. Set via the `GRAVITINO_IGNORE` environment variable.
3. Stored in the Gravitino CLI configuration file.
+### Multiple properties
+
+For commands that accept multiple properties they can be specified in a couple of different ways:
+
+1. gcli --properties n1=v1,n2=v2,n3=v3
+
+2. gcli --properties n1=v1 n2=v2 n3=v3
+
+3. gcli --properties n1=v1 --properties n2=v2 --properties n3=v3
+
### Metalake commands
#### Show all metalakes
@@ -190,7 +202,7 @@ gcli metalake set --metalake metalake_demo --property test --value value
gcli metalake remove --metalake metalake_demo --property test
```
-### Catalog
+### Catalog commands
#### Show all catalogs in a metalake
@@ -274,7 +286,7 @@ gcli catalog set --metalake metalake_demo --name catalog_mysql --property test -
gcli catalog remove --metalake metalake_demo --name catalog_mysql --property test
```
-### Schema
+### Schema commands
#### Show all schemas in a catalog
@@ -302,7 +314,7 @@ gcli schema properties --metalake metalake_demo --name catalog_postgres.hr -i
Setting and removing schema properties is not currently supported by the Java API or the Gravitino CLI.
-### Table
+### Table commands
#### Show all tables
@@ -321,3 +333,55 @@ gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments
```bash
gcli table delete --metalake metalake_demo --name catalog_postgres.hr.salaries
```
+
+### User commands
+
+#### Create a user
+
+```bash
+gcli user create --metalake metalake_demo --user new_user
+```
+
+#### Show a user's details
+
+```bash
+gcli user details --metalake metalake_demo --user new_user
+```
+
+#### List all users
+
+```bash
+gcli user list --metalake metalake_demo
+```
+
+#### Delete a user
+
+```bash
+gcli user delete --metalake metalake_demo --user new_user
+```
+
+### Group commands
+
+#### Create a group
+
+```bash
+gcli group create --metalake metalake_demo --group new_group
+```
+
+#### Display a group's details
+
+```bash
+gcli group details --metalake metalake_demo --group new_group
+```
+
+#### List all groups
+
+```bash
+gcli group list --metalake metalake_demo
+```
+
+#### Delete a group
+
+```bash
+gcli group delete --metalake metalake_demo --group new_group
+```