use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by cdapio.
the class FileSecureStoreService method deserialize.
private SecureStoreData deserialize(byte[] data) throws IOException {
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));
String name = dis.readUTF();
boolean descriptionExists = dis.readBoolean();
String description = descriptionExists ? dis.readUTF() : null;
long lastModified = dis.readLong();
Map<String, String> properties = new HashMap<>();
int len = dis.readInt();
for (int i = 0; i < len; i++) {
properties.put(dis.readUTF(), dis.readUTF());
}
SecureStoreMetadata meta = new SecureStoreMetadata(name, description, lastModified, properties);
byte[] secret = new byte[dis.readInt()];
dis.readFully(secret);
return new SecureStoreData(meta, secret);
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by cdapio.
the class SecureStoreHandler method getMetadata.
@Path("/{key-name}/metadata")
@GET
public void getMetadata(HttpRequest httpRequest, HttpResponder httpResponder, @PathParam("namespace-id") String namespace, @PathParam("key-name") String name) throws Exception {
SecureStoreData secureStoreData = secureStore.get(namespace, name);
httpResponder.sendJson(HttpResponseStatus.OK, GSON.toJson(secureStoreData.getMetadata()));
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by cdapio.
the class RemoteSecureStore method get.
@Override
public SecureStoreData get(String namespace, String name) throws Exception {
// 1. Get metadata of the secure key
HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace, name) + "/metadata").build();
HttpResponse response = remoteClient.execute(request);
handleResponse(response, namespace, name, String.format("Error occurred while getting metadata for key %s:%s", namespace, name));
SecureStoreMetadata metadata = GSON.fromJson(response.getResponseBodyAsString(), SecureStoreMetadata.class);
// 2. Get sensitive data for the secure key
request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace, name)).build();
response = remoteClient.execute(request);
handleResponse(response, namespace, name, String.format("Error occurred while getting key %s:%s", namespace, name));
// response is not a json object
byte[] data = response.getResponseBody();
return new SecureStoreData(metadata, data);
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by cdapio.
the class SecretManagerSecureStoreService method get.
@Override
public SecureStoreData get(String namespace, String name) throws Exception {
validate(namespace);
try {
Secret secret = secretManager.get(namespace, name);
SecretMetadata metadata = secret.getMetadata();
return new SecureStoreData(new SecureStoreMetadata(metadata.getName(), metadata.getDescription(), metadata.getCreationTimeMs(), metadata.getProperties()), secret.getData());
} catch (SecretNotFoundException e) {
throw new SecureKeyNotFoundException(new SecureKeyId(namespace, name), e);
}
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by cdapio.
the class RemoteSecureStoreTest method testRemoteSecureStore.
@Test
public void testRemoteSecureStore() throws Exception {
SecureStoreMetadata secureStoreMetadata = new SecureStoreMetadata("key", "description", 1, ImmutableMap.of("prop1", "value1"));
SecureStoreData secureStoreData = new SecureStoreData(secureStoreMetadata, "value".getBytes(StandardCharsets.UTF_8));
// test put and get
remoteSecureStore.put(NAMESPACE1, "key", "value", "description", ImmutableMap.of("prop1", "value1"));
SecureStoreData actual = remoteSecureStore.get(NAMESPACE1, "key");
Assert.assertEquals(secureStoreMetadata.getName(), actual.getMetadata().getName());
Assert.assertArrayEquals(secureStoreData.get(), actual.get());
Assert.assertEquals(secureStoreMetadata.getDescription(), actual.getMetadata().getDescription());
Assert.assertEquals(secureStoreMetadata.getProperties().size(), actual.getMetadata().getProperties().size());
// test list
List<SecureStoreMetadata> secureData = remoteSecureStore.list(NAMESPACE1);
Assert.assertEquals(1, secureData.size());
SecureStoreMetadata metadata = secureData.get(0);
Assert.assertEquals("key", metadata.getName());
Assert.assertEquals("description", metadata.getDescription());
// test delete
remoteSecureStore.delete(NAMESPACE1, "key");
Assert.assertEquals(0, remoteSecureStore.list(NAMESPACE1).size());
}
Aggregations