Skip to content

Commit

Permalink
Add username/password options for web service w/ auth enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesname committed Oct 25, 2021
1 parent b11f875 commit 3b070da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.URI;
import java.util.Base64;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -114,8 +115,7 @@ public static List<URI> urlsFromSpecs(String serviceUrl, String... specs) {
}


@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException, ParseException {
public static void main(String[] args) throws ParseException {

// Long opts
final String PRINT = "print";
Expand All @@ -130,6 +130,8 @@ public static void main(String[] args) throws IOException, ParseException {
final String SOLR_URL = "solr";
final String INDEX = "index";
final String NO_CONVERT = "noconvert";
final String USERNAME = "username";
final String PASSWORD = "password";
final String VERBOSE = "verbose";
final String VERSION = "version";
final String STATS = "stats";
Expand Down Expand Up @@ -173,6 +175,10 @@ public static void main(String[] args) throws IOException, ParseException {
options.addOption(Option.builder().longOpt(VERSION)
.desc("Print the version number and exit.")
.build());
options.addOption("U", USERNAME, true,
"Data service basic authentication username");
options.addOption("p", PASSWORD, true,
"Data service basic authentication password");
options.addOption("S", STATS, false, "Print indexing stats.");
options.addOption("h", HELP, false, "Print this message.");

Expand Down Expand Up @@ -206,6 +212,11 @@ public static void main(String[] args) throws IOException, ParseException {
String ehriUrl = cmd.getOptionValue(REST_URL, DEFAULT_EHRI_URL);
String solrUrl = cmd.getOptionValue(SOLR_URL, DEFAULT_SOLR_URL);
Properties restHeaders = cmd.getOptionProperties(HEADERS);
if (cmd.hasOption(USERNAME) && cmd.hasOption(PASSWORD)) {
String credentials = Base64.getEncoder()
.encodeToString((cmd.getOptionValue(USERNAME) + ":" + cmd.getOptionValue(PASSWORD)).getBytes());
restHeaders.setProperty("Authorization", "Basic " + credentials);
}

Pipeline.Builder<JsonNode, JsonNode> builder = new Pipeline.Builder<>();

Expand All @@ -219,18 +230,13 @@ public static void main(String[] args) throws IOException, ParseException {

// Determine if we need to actually index the data...
if (cmd.hasOption(INDEX)) {
builder.addSink(new IndexJsonSink(index, new IndexJsonSink.EventHandler() {
@Override
public void handleEvent(Object event) {
System.err.println(event);
}
}));
builder.addSink(new IndexJsonSink(index, System.err::println));
}

// Determine if we want to convert the data or print the incoming
// JSON as-is...
builder.addConverter(cmd.hasOption(NO_CONVERT)
? new NoopConverter<JsonNode>()
? new NoopConverter<>()
: new JsonConverter());

// See if we want to print stats... if so create a callback sink
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<groupId>ehri-project</groupId>
<artifactId>search-tools</artifactId>
<packaging>pom</packaging>
<version>1.1.10</version>
<version>1.1.11</version>
<modules>
<module>solr-config</module>
<module>index-data-converter</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<solr.version>6.6.5</solr.version>
<solr.version>6.6.6</solr.version>
</properties>

<issueManagement>
Expand Down

0 comments on commit 3b070da

Please sign in to comment.