Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-such-code committed Sep 26, 2024
1 parent cb3933d commit 4d28df9
Show file tree
Hide file tree
Showing 14 changed files with 1,785 additions and 45 deletions.
85 changes: 73 additions & 12 deletions src/main/java/life/qbic/io/commandline/AuthenticationOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class AuthenticationOptions {
description = "openBIS user name")
private String openbisUser;
@ArgGroup(multiplicity = "1") // ensures the password is provided once with at least one of the possible options.
PasswordOptions openbisPasswordOptions;
OpenbisPasswordOptions openbisPasswordOptions;
@ArgGroup(multiplicity = "1")
SeekPasswordOptions seekPasswordOptions;

@Option(
names = {"-as", "-as_url"},
Expand All @@ -32,17 +34,21 @@ public class AuthenticationOptions {
private String as_url;

@Option(
names = {"-dss", "-dss_url"},
names = {"-dss", "--dss_url"},
description = "DatastoreServer URL",
scope = CommandLine.ScopeType.INHERIT)
private String dss_url;

@Option(
names = {"-config", "-config_file"},
description = "Config file path to provide openbis server information.",
names = {"-config", "--config_file"},
description = "Config file path to provide server and user information.",
scope = CommandLine.ScopeType.INHERIT)
public String configPath;

@Option(
names = {"-su", "--seek-user"},
description = "Seek user name (email)",
scope = CommandLine.ScopeType.INHERIT)
private String seekUser;
@Option(
names = {"-seek-server", "-seek_url"},
description = "SEEK API URL",
Expand All @@ -52,13 +58,30 @@ public class AuthenticationOptions {
public String getOpenbisUser() {
if(openbisUser == null & configPath!=null && !configPath.isBlank()) {
openbisUser = ReadProperties.getProperties(configPath).get("user");
} else {
log.error("No openBIS user provided.");
System.exit(2);
}
return openbisUser;
}

public String getSeekUser() {
if(seekUser == null & configPath!=null && !configPath.isBlank()) {
seekUser = ReadProperties.getProperties(configPath).get("seek_user");
} else {
log.error("No SEEK user/email provided.");
System.exit(2);
}
return seekUser;
}

public String getSeekURL() {
log.error("No URL to the SEEK address provided.");
System.exit(2);
if(seek_url == null & configPath!=null && !configPath.isBlank()) {
seek_url = ReadProperties.getProperties(configPath).get("seek_url");
} else {
log.error("No URL to the SEEK address provided.");
System.exit(2);
}
return seek_url;
}

Expand All @@ -76,21 +99,25 @@ public String getAS() {
return as_url;
}

public char[] getSeekPassword() {
return seekPasswordOptions.getPassword();
}

public char[] getOpenbisPassword() {
return openbisPasswordOptions.getPassword();
}

/**
* <a href="https://picocli.info/#_optionally_interactive">official picocli documentation example</a>
*/
static class PasswordOptions {
@Option(names = "--password:env", arity = "1", paramLabel = "<environment-variable>", description = "provide the name of an environment variable to read in your password from")
static class OpenbisPasswordOptions {
@Option(names = "--openbis-pw:env", arity = "1", paramLabel = "<environment-variable>", description = "provide the name of an environment variable to read in your password from")
protected String passwordEnvironmentVariable = "";

@Option(names = "--password:prop", arity = "1", paramLabel = "<system-property>", description = "provide the name of a system property to read in your password from")
@Option(names = "--openbis-pw:prop", arity = "1", paramLabel = "<system-property>", description = "provide the name of a system property to read in your password from")
protected String passwordProperty = "";

@Option(names = "--password", arity = "0", description = "please provide your password", interactive = true)
@Option(names = "--openbis-pw", arity = "0", description = "please provide your openBIS password", interactive = true)
protected char[] password = null;

/**
Expand All @@ -116,9 +143,43 @@ char[] getPassword() {
System.exit(2);
return null; // not reachable due to System.exit in previous line
}

}

static class SeekPasswordOptions {
@Option(names = "--seek-pw:env", arity = "1", paramLabel = "<environment-variable>", description = "provide the name of an environment variable to read in your password from")
protected String passwordEnvironmentVariable = "";

@Option(names = "--seek-pw:prop", arity = "1", paramLabel = "<system-property>", description = "provide the name of a system property to read in your password from")
protected String passwordProperty = "";

@Option(names = "--seek-pw", arity = "0", description = "please provide your SEEK password", interactive = true)
protected char[] password = null;

/**
* Gets the password. If no password is provided, the program exits.
* @return the password provided by the user.
*/
char[] getPassword() {
if (nonNull(password)) {
return password;
}
// System.getProperty(String key) does not work for empty or blank keys.
if (!passwordProperty.isBlank()) {
String systemProperty = System.getProperty(passwordProperty);
if (nonNull(systemProperty)) {
return systemProperty.toCharArray();
}
}
String environmentVariable = System.getenv(passwordEnvironmentVariable);
if (nonNull(environmentVariable) && !environmentVariable.isBlank()) {
return environmentVariable.toCharArray();
}
log.error("No password provided. Please provide your password.");
System.exit(2);
return null; // not reachable due to System.exit in previous line
}

}
@Override
public String toString() {
return new StringJoiner(", ", AuthenticationOptions.class.getSimpleName() + "[", "]")
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/life/qbic/io/commandline/CommandLineOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

// main command with format specifiers for the usage help message
@Command(name = "openbis-scripts",
subcommands = { SampleHierarchyCommand.class, FindDatasetsCommand.class, DownloadPetabCommand.class,
UploadPetabResultCommand.class, UploadDatasetCommand.class, SpaceStatisticsCommand.class },
description = "A client software for querying openBIS.",
mixinStandardHelpOptions = true, versionProvider = ManifestVersionProvider.class)
subcommands = {SampleHierarchyCommand.class, FindDatasetsCommand.class,
DownloadPetabCommand.class, UploadPetabResultCommand.class, UploadDatasetCommand.class,
SpaceStatisticsCommand.class, TransferDataToSeekCommand.class},
description = "A client software for querying openBIS.",
mixinStandardHelpOptions = true, versionProvider = ManifestVersionProvider.class)
public class CommandLineOptions {

private static final Logger LOG = LogManager.getLogger(CommandLineOptions.class);

@Option(names = {"-V", "--version"},
Expand Down
Loading

0 comments on commit 4d28df9

Please sign in to comment.