Skip to content

Commit

Permalink
Add AwsProductSender urls for CLIProductBuilder, update ProductResend…
Browse files Browse the repository at this point in the history
…er to resign if key provided
  • Loading branch information
jmfee-usgs committed Feb 20, 2021
1 parent fbbcaa1 commit f758822
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gov/usgs/earthquake/aws/AwsProductSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public class AwsProductSender extends DefaultConfigurable implements ProductSend

public AwsProductSender() {}

public AwsProductSender(URL url) {
this.hubUrl = url;
}

@Override
public void configure(Config config) throws Exception {
super.configure(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package gov.usgs.earthquake.distribution;

import gov.usgs.earthquake.aws.AwsProductSender;
import gov.usgs.earthquake.product.ByteContent;
import gov.usgs.earthquake.product.FileContent;
import gov.usgs.earthquake.product.InputStreamContent;
Expand Down Expand Up @@ -427,18 +428,23 @@ public Product buildProduct() throws Exception {

public static List<ProductSender> parseServers(final String servers,
final Integer connectTimeout, final boolean binaryFormat,
final boolean enableDeflate) {
final boolean enableDeflate) throws Exception {
List<ProductSender> senders = new ArrayList<ProductSender>();

Iterator<String> iter = StringUtils.split(servers, ",").iterator();
while (iter.hasNext()) {
String server = iter.next();
String[] parts = server.split(":");
SocketProductSender sender = new SocketProductSender(parts[0],
Integer.parseInt(parts[1]), connectTimeout);
sender.setBinaryFormat(binaryFormat);
sender.setEnableDeflate(enableDeflate);
senders.add(sender);
if (server.startsWith("https://")) {
AwsProductSender sender = new AwsProductSender(new URL(server));
senders.add(sender);
} else {
String[] parts = server.split(":");
SocketProductSender sender = new SocketProductSender(parts[0],
Integer.parseInt(parts[1]), connectTimeout);
sender.setBinaryFormat(binaryFormat);
sender.setEnableDeflate(enableDeflate);
senders.add(sender);
}
}

return senders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.security.PrivateKey;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import gov.usgs.earthquake.aws.AwsProductSender;
import gov.usgs.earthquake.product.Product;
import gov.usgs.earthquake.product.io.IOUtil;
import gov.usgs.earthquake.product.io.ObjectProductHandler;
import gov.usgs.earthquake.product.io.ProductSource;
import gov.usgs.util.CryptoUtils;
import gov.usgs.util.FileUtils;

/**
* A utility class to (re)send an existing product to pdl hubs.
*
*
* Mainly used when one server has not received a product, in order to
* redistribute the product.
*/
Expand All @@ -26,6 +30,7 @@ public class ProductResender {

public static final String SERVERS_ARGUMENT = "--servers=";
public static final String BATCH_ARGUMENT = "--batch";
public static final String PRIVATE_KEY_ARGUMENT = "--privateKey=";

public static void main(final String[] args) throws Exception {
// disable tracker
Expand All @@ -37,6 +42,7 @@ public static void main(final String[] args) throws Exception {
boolean binaryFormat = false;
boolean enableDeflate = true;
boolean batchMode = false;
PrivateKey privateKey = null;

for (String arg : args) {
if (arg.startsWith(IOUtil.INFILE_ARGUMENT)) {
Expand All @@ -51,6 +57,14 @@ public static void main(final String[] args) throws Exception {
enableDeflate = false;
} else if (arg.equals(BATCH_ARGUMENT)) {
batchMode = true;
} else if (arg.startsWith(PRIVATE_KEY_ARGUMENT)) {
privateKey = CryptoUtils.readOpenSSHPrivateKey(
FileUtils.readFile(new File(arg.replace(PRIVATE_KEY_ARGUMENT, ""))),
null);
if (privateKey == null) {
LOGGER.warning("Unable to parse private key " + arg);
System.exit(1);
}
}
}

Expand All @@ -67,6 +81,16 @@ public static void main(final String[] args) throws Exception {
builder.getProductSenders().addAll(
CLIProductBuilder.parseServers(servers, 15000, binaryFormat,
enableDeflate));
if (privateKey != null) {
// resign products
for (ProductSender sender : builder.getProductSenders()) {
if (sender instanceof AwsProductSender) {
AwsProductSender awsSender = (AwsProductSender) sender;
awsSender.setPrivateKey(privateKey);
awsSender.setSignProducts(true);;
}
}
}

if ((!batchMode && product == null) || builder.getProductSenders().size() == 0) {
System.err.println("Usage: ProductResender --servers=SERVERLIST"
Expand Down

0 comments on commit f758822

Please sign in to comment.