diff --git a/examples-secret/pom.xml b/examples-secret/pom.xml
new file mode 100644
index 0000000..07d7624
--- /dev/null
+++ b/examples-secret/pom.xml
@@ -0,0 +1,79 @@
+
+
+ 4.0.0
+
+
+ runtime-sdk-parent
+ io.mosn.layotto
+ 1.3.0-SNAPSHOT
+
+
+ io.mosn.layotto
+ examples-secret
+ 1.3.0-SNAPSHOT
+
+
+ 8
+ 8
+
+
+
+
+ io.mosn.layotto
+ runtime-sdk
+ 1.3.0-SNAPSHOT
+
+
+ org.apache.logging.log4j
+ log4j-api
+ 2.9.1
+
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.9.1
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ 2.9.1
+
+
+ io.mosn.layotto
+ runtime-sdk
+
+
+
+
+ src/main/java
+ examples-secret
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 3.2.0
+
+
+
+ io.mosn.layotto.examples.secret.Secret
+
+
+
+ jar-with-dependencies
+
+
+
+
+ assemble-all
+ package
+
+ single
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples-secret/src/main/java/io/mosn/layotto/examples/secret/Secret.java b/examples-secret/src/main/java/io/mosn/layotto/examples/secret/Secret.java
new file mode 100644
index 0000000..1fbf291
--- /dev/null
+++ b/examples-secret/src/main/java/io/mosn/layotto/examples/secret/Secret.java
@@ -0,0 +1,64 @@
+package io.mosn.layotto.examples.secret;
+
+import io.mosn.layotto.v1.RuntimeClientBuilder;
+import io.mosn.layotto.v1.config.RuntimeProperties;
+import spec.sdk.runtime.v1.client.RuntimeClient;
+import spec.sdk.runtime.v1.domain.secret.GetBulkSecretRequest;
+import spec.sdk.runtime.v1.domain.secret.GetBulkSecretResponse;
+import spec.sdk.runtime.v1.domain.secret.GetSecretRequest;
+import spec.sdk.runtime.v1.domain.secret.GetSecretResponse;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Secret {
+
+ static String storeName = "secret_demo";
+ static String key = "db-user-pass:password";
+ static String value = "S!S*d$zDsb=";
+ static String []keys = new String[]{"redisPassword", "db-user-pass:password", "db-user-pass:username"};
+ static Map values = new HashMap(){{put("redisPassword", "redis123");put("db-user-pass:password", "S!S*d$zDsb=");put("db-user-pass:username", "devuser");}};
+
+ public static void main(String args[]){
+ RuntimeClient client = new RuntimeClientBuilder()
+ .withPort(RuntimeProperties.DEFAULT_PORT)
+ .build();
+
+ /*GetSecret*/
+ Map meta = new HashMap<>();
+ GetSecretRequest secretreq = new GetSecretRequest();
+ secretreq.setStoreName(storeName);
+ secretreq.setKey(key);
+ secretreq.setMetaData(meta);
+ GetSecretResponse response = client.getSecret(secretreq);
+ System.out.println(response.getData());
+ assertMap(response.getData(),key,value);
+
+ /*GetBulkSecret*/
+ Map meta2 = new HashMap<>();
+ GetBulkSecretRequest bulksecretreq = new GetBulkSecretRequest();
+ bulksecretreq.setStoreName(storeName);
+ bulksecretreq.setMetaData(meta2);
+ GetBulkSecretResponse bulkrespone = client.getBulkSecret(bulksecretreq);
+ System.out.println(bulkrespone.getData());
+ assertBulkMap(bulkrespone.getData(), keys,values);
+ }
+ private static void assertMap(Map secret, String key, String value) {
+ if (secret.get(key).equals(value)) {
+ return;
+ }
+ throw new AssertionError();
+ }
+
+ private static void assertBulkMap(Map> bulksecret, String keys[], Map values ) {
+ Map temp = new HashMap<>();
+ for (String key : keys) {
+ temp = bulksecret.get(key);
+ if(!(temp.get(key).equals(values.get(key))))
+ throw new AssertionError();
+ }
+ return;
+ }
+
+
+}
diff --git a/examples-secret/src/main/resources/log4j2.xml b/examples-secret/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..22578a9
--- /dev/null
+++ b/examples-secret/src/main/resources/log4j2.xml
@@ -0,0 +1,18 @@
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 7487042..002e359 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,6 +27,7 @@
examples-preview-service
examples-oss
examples-lock
+ examples-secret
diff --git a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java
index 65d1f5c..55ce872 100644
--- a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java
+++ b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java
@@ -28,9 +28,9 @@
import io.mosn.layotto.v1.grpc.stub.StubManager;
import io.mosn.layotto.v1.serializer.ObjectSerializer;
import org.slf4j.Logger;
+import spec.proto.extension.v1.s3.ObjectStorageServiceGrpc;
import spec.proto.runtime.v1.RuntimeGrpc;
import spec.proto.runtime.v1.RuntimeProto;
-import spec.proto.extension.v1.s3.ObjectStorageServiceGrpc;
import spec.sdk.runtime.v1.domain.file.DelFileRequest;
import spec.sdk.runtime.v1.domain.file.DelFileResponse;
import spec.sdk.runtime.v1.domain.file.FileInfo;
@@ -47,6 +47,10 @@
import spec.sdk.runtime.v1.domain.lock.TryLockResponse;
import spec.sdk.runtime.v1.domain.lock.UnlockRequest;
import spec.sdk.runtime.v1.domain.lock.UnlockResponse;
+import spec.sdk.runtime.v1.domain.secret.GetBulkSecretRequest;
+import spec.sdk.runtime.v1.domain.secret.GetBulkSecretResponse;
+import spec.sdk.runtime.v1.domain.secret.GetSecretRequest;
+import spec.sdk.runtime.v1.domain.secret.GetSecretResponse;
import spec.sdk.runtime.v1.domain.sequencer.GetNextIdRequest;
import spec.sdk.runtime.v1.domain.sequencer.GetNextIdResponse;
import spec.sdk.runtime.v1.domain.state.DeleteStateRequest;
@@ -79,7 +83,8 @@ public class RuntimeClientGrpc extends AbstractRuntimeClient implements GrpcRunt
int timeoutMs,
ObjectSerializer stateSerializer,
StubManager runtimeStubManager,
- StubManager ossStubManager) {
+ StubManager ossStubManager) {
super(logger, timeoutMs, stateSerializer);
this.runtimeStubManager = runtimeStubManager;
this.ossStubManager = ossStubManager;
@@ -1101,4 +1106,64 @@ public UnlockResponse unlock(UnlockRequest request) {
}
}
+
+ @Override
+ public GetSecretResponse getSecret(GetSecretRequest req) {
+ try {
+ // 1. prepare request
+ RuntimeProto.GetSecretRequest.Builder builder = RuntimeProto.GetSecretRequest.newBuilder()
+ .setStoreName(req.getStoreName())
+ .setKey(req.getKey());
+ if (req.getMetaData() != null) {
+ builder.putAllMetadata(req.getMetaData());
+ }
+ RuntimeProto.GetSecretRequest request = builder.build();
+
+ // 2. invoke
+ RuntimeProto.GetSecretResponse response = runtimeStubManager.getBlockingStub()
+ .getSecret(request);
+ // 3. parse result
+ GetSecretResponse getSecretResponse = new GetSecretResponse();
+ getSecretResponse.setData(response.getDataMap());
+ return getSecretResponse;
+ } catch (Exception e) {
+ logger.error("getSecret error ", e);
+ throw new RuntimeClientException(e);
+ }
+
+ }
+
+ @Override
+ public GetBulkSecretResponse getBulkSecret(GetBulkSecretRequest req) {
+ try {
+ // 1. prepare request
+ RuntimeProto.GetBulkSecretRequest.Builder builder = RuntimeProto.GetBulkSecretRequest.newBuilder()
+ .setStoreName(req.getStoreName());
+ if (req.getMetaData() != null) {
+ builder.putAllMetadata(req.getMetaData());
+ }
+ RuntimeProto.GetBulkSecretRequest request = builder.build();
+ // 2. invoke
+ RuntimeProto.GetBulkSecretResponse response = runtimeStubManager.getBlockingStub()
+ .getBulkSecret(request);
+ // 3. parse result
+ GetBulkSecretResponse getBulkSecretResponse = new GetBulkSecretResponse();
+ Map> tempMap = new HashMap<>();
+ if (!(response.getDataMap().isEmpty())) {
+ for (Map.Entry entry : response.getDataMap().entrySet()) {
+ String key = entry.getKey();
+ RuntimeProto.SecretResponse value = entry.getValue();
+ Map secretMap = value.getSecretsMap();
+ tempMap.put(key, secretMap);
+
+ }
+ }
+ getBulkSecretResponse.setData(tempMap);
+ return getBulkSecretResponse;
+ } catch (Exception e) {
+ logger.error("getSecret error ", e);
+ throw new RuntimeClientException(e);
+ }
+ }
+
}
diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java b/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java
index c14f073..8ca72c1 100644
--- a/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java
+++ b/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java
@@ -24,7 +24,7 @@ public interface RuntimeClient extends
StateRuntime,
LockRuntime,
SequencerRuntime,
- FileRuntime, OssRuntime {
+ FileRuntime, OssRuntime, SecretRuntime {
void shutdown();
}
\ No newline at end of file
diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/SecretRuntime.java b/sdk/src/main/java/spec/sdk/runtime/v1/domain/SecretRuntime.java
new file mode 100644
index 0000000..5aa046f
--- /dev/null
+++ b/sdk/src/main/java/spec/sdk/runtime/v1/domain/SecretRuntime.java
@@ -0,0 +1,13 @@
+package spec.sdk.runtime.v1.domain;
+
+import spec.sdk.runtime.v1.domain.secret.GetBulkSecretRequest;
+import spec.sdk.runtime.v1.domain.secret.GetBulkSecretResponse;
+import spec.sdk.runtime.v1.domain.secret.GetSecretRequest;
+import spec.sdk.runtime.v1.domain.secret.GetSecretResponse;
+
+public interface SecretRuntime {
+
+ GetSecretResponse getSecret(GetSecretRequest req);
+
+ GetBulkSecretResponse getBulkSecret(GetBulkSecretRequest req);
+}
diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetBulkSecretRequest.java b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetBulkSecretRequest.java
new file mode 100644
index 0000000..ff1f6e7
--- /dev/null
+++ b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetBulkSecretRequest.java
@@ -0,0 +1,30 @@
+package spec.sdk.runtime.v1.domain.secret;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GetBulkSecretRequest {
+ private String storeName;
+
+ private Map metaData;
+
+ public String getStoreName() {
+ return storeName;
+ }
+
+ public void setStoreName(String storeName) {
+ this.storeName = storeName;
+ }
+
+ public Map getMetaData() {
+
+ return metaData;
+ }
+
+ public void setMetaData(Map metaData) {
+
+ this.metaData = metaData;
+ }
+
+
+}
diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetBulkSecretResponse.java b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetBulkSecretResponse.java
new file mode 100644
index 0000000..5e46d0e
--- /dev/null
+++ b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetBulkSecretResponse.java
@@ -0,0 +1,19 @@
+package spec.sdk.runtime.v1.domain.secret;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GetBulkSecretResponse {
+
+ private Map> data;
+
+ public Map> getData() {
+ return data;
+ }
+
+ public void setData(Map> data) {
+ this.data = data;
+ }
+
+}
diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetSecretRequest.java b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetSecretRequest.java
new file mode 100644
index 0000000..694281a
--- /dev/null
+++ b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetSecretRequest.java
@@ -0,0 +1,37 @@
+package spec.sdk.runtime.v1.domain.secret;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GetSecretRequest {
+ private String storeName;
+
+ private String key;
+
+ private Map metaData;
+
+ public void setStoreName(String storeName) {
+ this.storeName = storeName;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public void setMetaData(Map metaData) {
+
+ this.metaData = metaData;
+ }
+
+ public String getStoreName() {
+ return storeName;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Map getMetaData() {
+ return metaData;
+ }
+}
diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetSecretResponse.java b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetSecretResponse.java
new file mode 100644
index 0000000..9ab1105
--- /dev/null
+++ b/sdk/src/main/java/spec/sdk/runtime/v1/domain/secret/GetSecretResponse.java
@@ -0,0 +1,17 @@
+package spec.sdk.runtime.v1.domain.secret;
+
+import java.util.Map;
+
+public class GetSecretResponse {
+
+ private Map data;
+
+ public Map getData() {
+ return data;
+ }
+
+ public void setData(Map data) {
+ this.data = data;
+ }
+
+}