use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.
the class FakeSecureStore method get.
@Override
public SecureStoreData get(String namespace, String name) throws Exception {
Map<String, SecureStoreData> namespaceData = values.get(namespace);
if (namespaceData == null) {
throw new Exception("namespace " + namespace + " does not exist");
}
SecureStoreData data = namespaceData.get(name);
if (data == null) {
throw new Exception("Data for name " + name + " does not exist");
}
return data;
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.
the class FileSecureStoreServiceTest method testGet.
@Test
public void testGet() throws Exception {
populateStore();
SecureStoreMetadata metadata = new SecureStoreMetadata(KEY1, DESCRIPTION1, System.currentTimeMillis(), PROPERTIES_1);
SecureStoreData secureStoreData = new SecureStoreData(metadata, VALUE1.getBytes(Charsets.UTF_8));
Assert.assertArrayEquals(secureStoreData.get(), secureStore.get(NAMESPACE1, KEY1).get());
Assert.assertEquals(metadata.getDescription(), secureStore.get(NAMESPACE1, KEY1).getMetadata().getDescription());
Assert.assertEquals(metadata.getName(), secureStore.get(NAMESPACE1, KEY1).getMetadata().getName());
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.
the class FileSecureStoreServiceTest method testDelete.
@Test(expected = NotFoundException.class)
public void testDelete() throws Exception {
populateStore();
SecureStoreMetadata metadata = new SecureStoreMetadata(KEY1, DESCRIPTION1, System.currentTimeMillis(), PROPERTIES_1);
SecureStoreData secureStoreData = new SecureStoreData(metadata, VALUE1.getBytes(Charsets.UTF_8));
Assert.assertArrayEquals(secureStoreData.get(), secureStore.get(NAMESPACE1, KEY1).get());
secureStoreManager.delete(NAMESPACE1, KEY1);
try {
secureStore.get(NAMESPACE1, KEY1);
} catch (IOException ioe) {
Assert.assertTrue(ioe.getMessage().contains("not found in the secure store"));
throw ioe;
}
}
use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.
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 caskdata.
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);
}
Aggregations