Skip to content

Commit

Permalink
Adding username and password as a cli parameter (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameleeck authored and pjagielski committed Jul 29, 2016
1 parent 2dd9fbf commit 6d4435f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/java/pl/touk/sputnik/configuration/CliOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum CliOption implements ConfigurationOption {
API_KEY("cli.apiKey", "Optional API key for using Sputnik as a service", null),
BUILD_ID("cli.buildId", "Optional build id for using Sputnik as a service", null),
PROVIDER("cli.provider", "Optional SCM provider (GitHub, GitLab) for using Sputnik as a service", null),
FILE_REGEX("cli.fileRegex", "Review only file paths that fulfill provided regex", null);
FILE_REGEX("cli.fileRegex", "Review only file paths that fulfill provided regex", null),
USERNAME("cli.username", "Passes username into connector", null),
PASSWORD("cli.password", "Pass password into connector", null);

private String key;
private String description;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pl/touk/sputnik/configuration/CliWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ private Options createOptions() {
localOptions.addOption(buildOption(CliOption.BUILD_ID, true, false));
localOptions.addOption(buildOption(CliOption.PROVIDER, true, false));
localOptions.addOption(buildOption(CliOption.FILE_REGEX, true, false));
localOptions.addOption(buildOption(CliOption.USERNAME, true, false));
localOptions.addOption(buildOption(CliOption.PASSWORD, true, false));

return localOptions;
}

@NotNull
public CommandLine parse(@NotNull String[] args) throws ParseException {
CommandLineParser parser = new BasicParser();
CommandLineParser parser = new DefaultParser();
return parser.parse(options, args);
}

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/pl/touk/sputnik/connector/ConnectorDetails.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.touk.sputnik.connector;

import lombok.Getter;
import pl.touk.sputnik.configuration.CliOption;
import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;

Expand All @@ -27,13 +28,23 @@ private void buildFromConfiguration(Configuration configuration) {
host = configuration.getProperty(GeneralOption.HOST);
port = Integer.valueOf(configuration.getProperty(GeneralOption.PORT));
path = configuration.getProperty(GeneralOption.PATH);
username = configuration.getProperty(GeneralOption.USERNAME);
password = configuration.getProperty(GeneralOption.PASSWORD);
username = getUsername(configuration);
password = getPassword(configuration);
useHttps = configuration.getProperty(GeneralOption.USE_HTTPS);
isHttps = Boolean.parseBoolean(useHttps);
verifySsl = Boolean.parseBoolean(configuration.getProperty(GeneralOption.VERIFY_SSL));
}

private String getUsername(Configuration configuration) {
return configuration.getProperty(CliOption.USERNAME) != null ? configuration.getProperty(
CliOption.USERNAME) : configuration.getProperty(GeneralOption.USERNAME);
}

private String getPassword(Configuration configuration) {
return configuration.getProperty(CliOption.PASSWORD) != null ? configuration.getProperty(
CliOption.PASSWORD) : configuration.getProperty(GeneralOption.PASSWORD);
}

private void validate() {
notBlank(host, "You must provide non blank connector host");
notBlank(username, "You must provide non blank connector username");
Expand Down

0 comments on commit 6d4435f

Please sign in to comment.