Skip to content

Commit

Permalink
fall back to API key if no OfflineAuth was saved
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-philippe-martin committed Aug 27, 2015
1 parent 27f1025 commit d7198c8
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.google.cloud.dataflow.sdk.runners.DirectPipelineRunner;
import com.google.cloud.dataflow.sdk.runners.PipelineRunner;
import com.google.cloud.genomics.dataflow.utils.GCSOptions;
import com.google.cloud.genomics.dataflow.utils.GenomicsOptions;
import com.google.cloud.genomics.utils.GenomicsFactory;
import com.google.common.annotations.VisibleForTesting;
import org.broadinstitute.hellbender.cmdline.Argument;
Expand All @@ -28,13 +29,16 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.GeneralSecurityException;


public abstract class DataflowCommandLineProgram extends CommandLineProgram implements Serializable {
private static final long serialVersionUID = 1l;

// We need authentication options from GCSOptions, and Dataflow options from DataflowPipelineOptions.
// Neither inherits from the other, so we have to put them together like this.
// This also includes code to save the OfflineAuth onto the pipelineoptions, so we can get to them later
// (even if they're via client-secrets.json, which workers otherwise wouldn't be able to load).
public interface HellbenderDataflowOptions extends GCSOptions, DataflowPipelineOptions {

static class Methods {
Expand All @@ -46,8 +50,15 @@ public static void setOfflineAuth(HellbenderDataflowOptions opts, GenomicsFactor
}
opts.setSerializedOfflineAuth(os.toByteArray());
}
public static GenomicsFactory.OfflineAuth getOfflineAuth(HellbenderDataflowOptions opts) throws IOException, ClassNotFoundException {
try (ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(opts.getSerializedOfflineAuth()))) {
public static GenomicsFactory.OfflineAuth getOfflineAuth(HellbenderDataflowOptions opts) throws IOException, ClassNotFoundException, GeneralSecurityException {
byte[] serialized = opts.getSerializedOfflineAuth();
if (null==serialized && opts.getApiKey()!=null) {
// fall back to using the API key only (even if a secrets file was also specified).
GenomicsFactory.Builder builder =
GenomicsFactory.builder(opts.getAppName()).setNumberOfRetries(opts.getNumberOfRetries());
return builder.build().getOfflineAuthFromApiKey(opts.getApiKey());
}
try (ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(serialized))) {
return (GenomicsFactory.OfflineAuth)(is.readObject());
}
}
Expand Down

0 comments on commit d7198c8

Please sign in to comment.