summaryrefslogtreecommitdiff
path: root/groot-common/src/main
diff options
context:
space:
mode:
authordoufenghu <[email protected]>2024-09-19 16:53:58 +0800
committerdoufenghu <[email protected]>2024-09-19 16:53:58 +0800
commit3fbdebc7cf9fb3f524623fc7e8dbe7217d55deeb (patch)
tree4946f96c8a5bf894e3e55fee3f2706284bff506e /groot-common/src/main
parentb2213266389975a4fa504022917b80f357c34f24 (diff)
[Feature][KMS] Support KMS configurations for developing ecnrypt functions.
Diffstat (limited to 'groot-common/src/main')
-rw-r--r--groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfig.java10
-rw-r--r--groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigDomProcessor.java43
-rw-r--r--groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigOptions.java45
-rw-r--r--groot-common/src/main/java/com/geedgenetworks/common/config/KmsConfig.java17
-rw-r--r--groot-common/src/main/java/com/geedgenetworks/common/config/KnowledgeBaseConfig.java19
5 files changed, 97 insertions, 37 deletions
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfig.java b/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfig.java
index 4fdf0c6..5212137 100644
--- a/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfig.java
+++ b/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfig.java
@@ -15,13 +15,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class CommonConfig implements Serializable {
private List<KnowledgeBaseConfig> knowledgeBaseConfig = CommonConfigOptions.KNOWLEDGE_BASE.defaultValue();
+
+ private Map<String,KmsConfig> kmsConfig = CommonConfigOptions.KMS.defaultValue();
+
private Map<String,String> propertiesConfig = CommonConfigOptions.PROPERTIES.defaultValue();
public void setKnowledgeBaseConfig(List<KnowledgeBaseConfig> knowledgeBaseConfig) {
- checkNotNull(knowledgeBaseConfig, CommonConfigOptions.KNOWLEDGE_BASE + "knowledgeConfig should not be null");
+ checkNotNull(knowledgeBaseConfig, CommonConfigOptions.KNOWLEDGE_BASE + " knowledgeConfig should not be null");
this.knowledgeBaseConfig = knowledgeBaseConfig;
}
+ public void setKmsConfig(Map<String,KmsConfig> kmsConfig) {
+ checkNotNull(kmsConfig, CommonConfigOptions.KMS + " kmsConfig should not be null");
+ this.kmsConfig = kmsConfig;
+ }
+
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigDomProcessor.java b/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigDomProcessor.java
index 785b4bb..4a3425d 100644
--- a/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigDomProcessor.java
+++ b/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigDomProcessor.java
@@ -28,10 +28,12 @@ public class CommonConfigDomProcessor extends AbstractDomConfigProcessor {
String name = cleanNodeName(node);
if (CommonConfigOptions.KNOWLEDGE_BASE.key().equals(name)) {
commonConfig.setKnowledgeBaseConfig(parseKnowledgeBaseConfig(node));
- } else if (CommonConfigOptions.PROPERTIES.key().equals(name)) {
+ } else if (CommonConfigOptions.KMS.key().equals(name)) {
+ commonConfig.setKmsConfig(parseKmsConfig(node));
+ } else if (CommonConfigOptions.PROPERTIES.key().equals(name)) {
commonConfig.setPropertiesConfig(parsePropertiesConfig(node));
} else {
- log.warn("Unrecognized configuration element: " + name);
+ log.warn("Unrecognized Groot Stream configuration element: {}", name);
}
}
@@ -57,11 +59,11 @@ public class CommonConfigDomProcessor extends AbstractDomConfigProcessor {
return knowledgeConfigList;
}
+
private KnowledgeBaseConfig parseKnowledgeBaseConfigAsObject(Node kbNode) {
KnowledgeBaseConfig knowledgeBaseConfig = new KnowledgeBaseConfig();
for (Node node : childElements(kbNode)) {
String name = cleanNodeName(node);
-
if (CommonConfigOptions.KNOWLEDGE_BASE_NAME.key().equals(name)) {
knowledgeBaseConfig.setName(getTextContent(node));
} else if (CommonConfigOptions.KNOWLEDGE_BASE_FS_TYPE.key().equals(name)) {
@@ -72,14 +74,43 @@ public class CommonConfigDomProcessor extends AbstractDomConfigProcessor {
knowledgeBaseConfig.setFiles(parseKnowledgeBaseFilesConfig(node));
} else if (CommonConfigOptions.KNOWLEDGE_BASE_PROPERTIES.key().equals(name)) {
knowledgeBaseConfig.setProperties(parseKnowledgeBasePropertiesConfig(node));
+ } else{
+ log.warn("Unrecognized KB configuration element: {}", name);
}
- else{
- log.warn("Unrecognized configuration element: " + name);
- }
+
}
return knowledgeBaseConfig;
}
+ private Map<String, KmsConfig> parseKmsConfig(Node kmsRootNode) {
+ Map<String, KmsConfig> kmsConfigMap = new HashMap<>();
+ for (Node node : childElements(kmsRootNode)) {
+ String name = cleanNodeName(node);
+ kmsConfigMap.put(name, parseKmsConfigAsObject(node));
+ }
+ return kmsConfigMap;
+ }
+
+ private KmsConfig parseKmsConfigAsObject(Node kmsNode) {
+ KmsConfig kmsConfig = new KmsConfig();
+ for (Node node : childElements(kmsNode)) {
+ String name = cleanNodeName(node);
+ if (CommonConfigOptions.KMS_TYPE.key().equals(name)) {
+ kmsConfig.setType(getTextContent(node));
+ } else if (CommonConfigOptions.KMS_URL.key().equals(name)) {
+ kmsConfig.setUrl(getTextContent(node));
+ } else if (CommonConfigOptions.KMS_TOKEN.key().equals(name)) {
+ kmsConfig.setToken(getTextContent(node));
+ } else if (CommonConfigOptions.KMS_KEY_PATH.key().equals(name)) {
+ kmsConfig.setKeyPath(getTextContent(node));
+ } else {
+ log.warn("Unrecognized KMS configuration element: {}", name);
+ }
+ }
+ return kmsConfig;
+ }
+
+
private Map<String, String> parseKnowledgeBasePropertiesConfig(Node properties) {
Map<String, String> propertiesMap = new HashMap<>();
for (Node node : childElements(properties)) {
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigOptions.java b/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigOptions.java
index a3f3468..701ffc3 100644
--- a/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigOptions.java
+++ b/groot-common/src/main/java/com/geedgenetworks/common/config/CommonConfigOptions.java
@@ -13,27 +13,27 @@ public class CommonConfigOptions {
Options.key("properties")
.mapType()
.defaultValue(new HashMap<String,String>())
- .withDescription("The properties of knowledgebase");
+ .withDescription("The properties of knowledge base");
public static final Option<String> KNOWLEDGE_BASE_NAME =
Options.key("name")
.stringType()
.defaultValue("")
- .withDescription("The name of knowledgebase.");
+ .withDescription("The name of knowledge base.");
public static final Option<String> KNOWLEDGE_BASE_FS_TYPE =
Options.key("fs_type")
.stringType()
.defaultValue("")
- .withDescription("The filesystem type of knowledgebase.");
+ .withDescription("The filesystem type of knowledge base.");
public static final Option<String> KNOWLEDGE_BASE_FS_PATH =
Options.key("fs_path")
.stringType()
.defaultValue("")
- .withDescription("The filesystem path of knowledgebase.");
+ .withDescription("The filesystem path of knowledge base.");
public static final Option<List<String>> KNOWLEDGE_BASE_FILES =
Options.key("files")
.listType()
.defaultValue(new ArrayList<String>())
- .withDescription("The files of knowledgebase.");
+ .withDescription("The files of knowledge base.");
public static final Option<String> KNOWLEDGE_BASE_STORAGE_FS_TYPE = Options.key("fs_type")
.stringType()
@@ -55,13 +55,36 @@ public class CommonConfigOptions {
Options.key("properties")
.mapType()
.noDefaultValue()
- .withDescription("The general properties of grootstream");
+ .withDescription("The general properties of groot stream");
+
+ public static final Option<Map<String, KmsConfig>> KMS =
+ Options.key("kms")
+ .type(new TypeReference<Map<String, KmsConfig>>() {})
+ .noDefaultValue()
+ .withDescription("The kms configuration.");
+
+ public static final Option<String> KMS_TYPE = Options.key("type")
+ .stringType()
+ .defaultValue("local")
+ .withDescription("The type of KMS.");
+
+ public static final Option<String> KMS_URL = Options.key("url")
+ .stringType()
+ .defaultValue("")
+ .withDescription("The access url of KMS.");
+
+ public static final Option<String> KMS_TOKEN = Options.key("token")
+ .stringType()
+ .defaultValue("")
+ .withDescription("The access token of KMS.");
+
+ public static final Option<String> KMS_KEY_PATH = Options.key("key_path")
+ .stringType()
+ .defaultValue("")
+ .withDescription("The key path of KMS.");
+
+
- public static final Option<String> ZOOKEEPER_QUORUM =
- Options.key("quorum")
- .stringType()
- .defaultValue("")
- .withDescription("The quorum of zookeeper.");
}
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/KmsConfig.java b/groot-common/src/main/java/com/geedgenetworks/common/config/KmsConfig.java
new file mode 100644
index 0000000..f26062c
--- /dev/null
+++ b/groot-common/src/main/java/com/geedgenetworks/common/config/KmsConfig.java
@@ -0,0 +1,17 @@
+package com.geedgenetworks.common.config;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class KmsConfig implements Serializable {
+
+ private String type = CommonConfigOptions.KMS_TYPE.defaultValue();
+ private String url = CommonConfigOptions.KMS_URL.defaultValue();
+ private String token = CommonConfigOptions.KMS_TOKEN.defaultValue();
+ private String keyPath = CommonConfigOptions.KMS_KEY_PATH.defaultValue();
+
+
+
+}
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/KnowledgeBaseConfig.java b/groot-common/src/main/java/com/geedgenetworks/common/config/KnowledgeBaseConfig.java
index b8e0160..baf4aee 100644
--- a/groot-common/src/main/java/com/geedgenetworks/common/config/KnowledgeBaseConfig.java
+++ b/groot-common/src/main/java/com/geedgenetworks/common/config/KnowledgeBaseConfig.java
@@ -1,15 +1,10 @@
package com.geedgenetworks.common.config;
-
-import com.geedgenetworks.utils.StringUtil;
import lombok.Data;
import java.io.Serializable;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import static com.google.common.base.Preconditions.checkArgument;
-
@Data
public class KnowledgeBaseConfig implements Serializable {
private String name = CommonConfigOptions.KNOWLEDGE_BASE_NAME.defaultValue();
@@ -18,18 +13,4 @@ public class KnowledgeBaseConfig implements Serializable {
private Map<String, String> properties = CommonConfigOptions.KNOWLEDGE_BASE_PROPERTIES.defaultValue();
private List<String> files = CommonConfigOptions.KNOWLEDGE_BASE_FILES.defaultValue();
- public void setFsType(String fsType) {
- this.fsType = fsType;
- }
-
- public void setFsPath(String fsPath) {
- this.fsPath = fsPath;
- }
-
- public void setFiles(List<String> files) {
- this.files = files;
- }
-
-
-
}