feat: support auth in graph computing
now support 2 ways include token & basic auth
TODO:
1. consider only support token in future
2. refact hugeclient & adopt in computer
3. after server k8s api adopt, add test case
diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java
index 1159a58..21f4e4d 100644
--- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java
+++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java
@@ -760,4 +760,30 @@
positiveInt(),
Bytes.GB
);
+
+ public static final ConfigOption<String> AUTH_TOKEN =
+ new ConfigOption<>(
+ "auth.token",
+ "The auth value for compute job to certificate," +
+ " should only used for HugeGraph server now",
+ ""
+ );
+
+ public static final ConfigOption<String> AUTH_USRNAME =
+ new ConfigOption<>(
+ "auth.usrname",
+ "The usrname for compute job to certificate with " +
+ "basic auth, should only used in test environment, " +
+ "consider ban it in future.",
+ ""
+ );
+
+ public static final ConfigOption<String> AUTH_PASSWD =
+ new ConfigOption<>(
+ "auth.passwd",
+ "The password for compute job to certificate with " +
+ "basic auth, should only used in test environment, " +
+ "consider ban it in future.",
+ ""
+ );
}
diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeGraphFetcher.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
index 73f18bc..a4e1afb 100644
--- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
+++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeGraphFetcher.java
@@ -39,7 +39,21 @@
public HugeGraphFetcher(Config config, InputSplitRpcService rpcService) {
String url = config.get(ComputerOptions.HUGEGRAPH_URL);
String graph = config.get(ComputerOptions.HUGEGRAPH_GRAPH_NAME);
- this.client = new HugeClientBuilder(url, graph).build();
+ String token = config.get(ComputerOptions.AUTH_TOKEN);
+ String usrname = config.get(ComputerOptions.AUTH_USRNAME);
+ String passwd = config.get(ComputerOptions.AUTH_PASSWD);
+ // TODO: need refact after HugeClient upgrade..
+ HugeClientBuilder clientBuilder = new HugeClientBuilder(url, graph);
+
+ if (token != null && token.length() != 0) {
+ this.client = clientBuilder.build();
+ this.client.setAuthContext(token);
+ } else if (usrname != null && usrname.length() != 0){
+ this.client = clientBuilder.configUser(usrname, passwd).build();
+ } else {
+ this.client = clientBuilder.build();
+ }
+
this.vertexFetcher = new HugeVertexFetcher(config, this.client);
this.edgeFetcher = new HugeEdgeFetcher(config, this.client);
this.rpcService = rpcService;
diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
index e2d4319..c566a34 100644
--- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
+++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/hg/HugeInputSplitFetcher.java
@@ -40,7 +40,20 @@
this.config = config;
String url = config.get(ComputerOptions.HUGEGRAPH_URL);
String graph = config.get(ComputerOptions.HUGEGRAPH_GRAPH_NAME);
- this.client = new HugeClientBuilder(url, graph).build();
+ String token = config.get(ComputerOptions.AUTH_TOKEN);
+ String usrname = config.get(ComputerOptions.AUTH_USRNAME);
+ String passwd = config.get(ComputerOptions.AUTH_PASSWD);
+ // TODO: need refact after HugeClient upgrade..
+ HugeClientBuilder clientBuilder = new HugeClientBuilder(url, graph);
+
+ if (token != null && token.length() != 0) {
+ this.client = clientBuilder.build();
+ this.client.setAuthContext(token);
+ } else if (usrname != null && usrname.length() != 0){
+ this.client = clientBuilder.configUser(usrname, passwd).build();
+ } else {
+ this.client = clientBuilder.build();
+ }
}
@Override