Skip to content

Commit

Permalink
Merge branch 'main' into feat-table-output
Browse files Browse the repository at this point in the history
  • Loading branch information
Abyss-lord authored Feb 15, 2025
2 parents 176eeff + 74435c9 commit 8d8ed0a
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CatalogCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);
List<String> missingEntities = Lists.newArrayList();

if (CommandActions.LIST.equals(command)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ColumnCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

List<String> missingEntities = Lists.newArrayList();
if (catalog == null) missingEntities.add(CommandEntities.CATALOG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ public class CommandContext {
private final CommandLine line;
// TODO make it final
private int outputLimit;
private final String auth;


private String ignoreEnv;
private boolean ignoreSet = false;
private String urlEnv;
private boolean urlSet = false;
private String authEnv;
private boolean authSet = false;
// Can add more "global" command flags here without any major changes e.g. a guiet flag

/**
Expand All @@ -54,11 +58,12 @@ public CommandContext(CommandLine line) {
? line.getOptionValue(GravitinoOptions.OUTPUT)
: Command.OUTPUT_FORMAT_PLAIN;
this.quiet = line.hasOption(GravitinoOptions.QUIET);
// TODO add limit option to CLI
this.outputLimit = -1;

this.url = getUrl();
this.ignoreVersions = getIgnore();
// TODO add limit option to CLI
this.outputLimit = -1;
this.auth = this.getAuth();
}

/**
Expand Down Expand Up @@ -107,6 +112,7 @@ public boolean quiet() {
}

/**
* Returns the output limit.
*
* @return The output limit.
Expand All @@ -115,6 +121,14 @@ public int outputLimit() {
return outputLimit;
}

* Returns the authentication type.
*
* @return The authentication type.
*/
public String auth() {
return auth;
}

/**
* Retrieves the Gravitino URL from the command line options or the GRAVITINO_URL environment
* variable or the Gravitino config file.
Expand Down Expand Up @@ -179,4 +193,34 @@ private boolean getIgnore() {

return ignore;
}

private String getAuth() {
// If specified on the command line use that
if (line.hasOption(GravitinoOptions.SIMPLE)) {
return GravitinoOptions.SIMPLE;
}

// Cache the Gravitino authentication type environment variable
if (authEnv == null && !authSet) {
authEnv = System.getenv("GRAVITINO_AUTH");
authSet = true;
}

// If set return the Gravitino authentication type environment variable
if (authEnv != null) {
return authEnv;
}

// Check if the authentication type is specified in the configuration file
GravitinoConfig config = new GravitinoConfig(null);
if (config.fileExists()) {
config.read();
String configAuthType = config.getGravitinoAuthType();
if (configAuthType != null) {
return configAuthType;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,9 @@

import com.google.common.base.Joiner;
import java.util.List;
import org.apache.commons.cli.CommandLine;

public abstract class CommandHandler {
public static final Joiner COMMA_JOINER = Joiner.on(", ").skipNulls();
private String authEnv;
private boolean authSet = false;

/**
* Retrieves the Gravitino authentication from the command line options or the GRAVITINO_AUTH
* environment variable or the Gravitino config file.
*
* @param line The command line instance.
* @return The Gravitino authentication, or null if not found.
*/
public String getAuth(CommandLine line) {
// If specified on the command line use that
if (line.hasOption(GravitinoOptions.SIMPLE)) {
return GravitinoOptions.SIMPLE;
}

// Cache the Gravitino authentication type environment variable
if (authEnv == null && !authSet) {
authEnv = System.getenv("GRAVITINO_AUTH");
authSet = true;
}

// If set return the Gravitino authentication type environment variable
if (authEnv != null) {
return authEnv;
}

// Check if the authentication type is specified in the configuration file
GravitinoConfig config = new GravitinoConfig(null);
if (config.fileExists()) {
config.read();
String configAuthType = config.getGravitinoAuthType();
if (configAuthType != null) {
return configAuthType;
}
}

return null;
}

protected abstract void handle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public FilesetCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

List<String> missingEntities = Lists.newArrayList();
if (catalog == null) missingEntities.add(CommandEntities.CATALOG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public GroupCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

if (CommandActions.LIST.equals(command)) {
handleListCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public MetalakeCommandHandler(
public void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
FullName name = new FullName(line);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

if (CommandActions.LIST.equals(command)) {
handleListCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ModelCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

List<String> missingEntities = Lists.newArrayList();
if (catalog == null) missingEntities.add(CommandEntities.CATALOG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public OwnerCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

if (entityName == null && !CommandEntities.METALAKE.equals(entity)) {
System.err.println(ErrorMessages.MISSING_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public RoleCommandHandler(

/** Handles the command execution logic based on the provided command. */
public void handle() {
String auth = getAuth(line);
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(auth, userName);
Command.setAuthenticationMode(context.auth(), userName);

metalake = new FullName(line).getMetalakeName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SchemaCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

List<String> missingEntities = Lists.newArrayList();
if (metalake == null) missingEntities.add(CommandEntities.METALAKE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public TableCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

List<String> missingEntities = Lists.newArrayList();
if (catalog == null) missingEntities.add(CommandEntities.CATALOG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public TagCommandHandler(
public void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
FullName name = new FullName(line);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

metalake = name.getMetalakeName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public TopicCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

List<String> missingEntities = Lists.newArrayList();
if (catalog == null) missingEntities.add(CommandEntities.CATALOG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public UserCommandHandler(
@Override
protected void handle() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
Command.setAuthenticationMode(getAuth(line), userName);
Command.setAuthenticationMode(context.auth(), userName);

user = line.getOptionValue(GravitinoOptions.USER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const CreateCatalogDialog = props => {
jdbcUser && (properties['jdbc-user'] = jdbcUser)
jdbcPwd && (properties['jdbc-password'] = jdbcPwd)
}
authType && (properties['authType'] = authType)
authType && (properties['authentication.type'] = authType)
kerberosPrincipal && (properties['authentication.kerberos.principal'] = kerberosPrincipal)
kerberosKeytabUri && (properties['authentication.kerberos.keytab-uri'] = kerberosKeytabUri)

Expand Down

0 comments on commit 8d8ed0a

Please sign in to comment.