Skip to content

Commit

Permalink
added simpler form of sigv4()
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentyn Kahamlyk authored and Valentyn Kahamlyk committed May 21, 2024
1 parent 687ab22 commit 94fdda3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@

import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.auth.Auth;
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin;
import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer;
import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -38,12 +41,17 @@ public class RemoteGremlinPlugin extends AbstractGremlinPlugin {
private static final ImportCustomizer imports = DefaultImportCustomizer.build()
.addClassImports(Cluster.class,
Client.class,
DriverRemoteConnection.class)
.addMethodImports(
Stream.of(ConnectionHelper.class.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).collect(Collectors.toList()))
DriverRemoteConnection.class,
Auth.class)
.addMethodImports(allStaticMethods(ConnectionHelper.class))
.addMethodImports(allStaticMethods(Auth.class))
.create();

public RemoteGremlinPlugin() {
super(NAME, new HashSet<>(Collections.singletonList("gremlin-groovy")), imports);
}

private static List<Method> allStaticMethods(final Class<?> clazz) {
return Stream.of(clazz.getMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ static Auth basic(final String username, final String password) {
return new Basic(username, password);
}

static Auth sigv4(final String regionName) {
return new Sigv4(regionName);
}

static Auth sigv4(final String regionName, final AWSCredentialsProvider awsCredentialsProvider) {
return new Sigv4(regionName, awsCredentialsProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.http.HttpMethodName;
import com.amazonaws.util.SdkHttpUtils;
import com.amazonaws.util.StringUtils;
Expand Down Expand Up @@ -53,6 +54,11 @@ public class Sigv4 implements Auth {
private final AWSCredentialsProvider awsCredentialsProvider;
private final AWS4Signer aws4Signer;


public Sigv4(final String regionName) {
this(regionName, new DefaultAWSCredentialsProviderChain(), NEPTUNE_SERVICE_NAME);
}

public Sigv4(final String regionName, final AWSCredentialsProvider awsCredentialsProvider) {
this(regionName, awsCredentialsProvider, NEPTUNE_SERVICE_NAME);
}
Expand Down

0 comments on commit 94fdda3

Please sign in to comment.