use of io.cdap.cdap.proto.id.SecureKeyId in project cdap by caskdata.
the class SecureStoreClientTest method testSecureKeys.
@Test
public void testSecureKeys() throws Exception {
// no secure keys to begin with
List<SecureStoreMetadata> secureKeys = client.listKeys(NamespaceId.DEFAULT);
Assert.assertTrue(secureKeys.isEmpty());
// create a key
String key = "securekey";
String desc = "SomeDesc";
String data = "secureData";
Map<String, String> properties = ImmutableMap.of("k1", "v1");
long creationTime = System.currentTimeMillis();
SecureKeyId secureKeyId = new SecureKeyId(NamespaceId.DEFAULT.getNamespace(), key);
client.createKey(secureKeyId, new SecureKeyCreateRequest(desc, data, properties));
Assert.assertEquals(data, client.getData(secureKeyId));
Assert.assertEquals(1, client.listKeys(NamespaceId.DEFAULT).size());
SecureStoreMetadata metadata = client.getKeyMetadata(secureKeyId);
Assert.assertEquals(desc, metadata.getDescription());
Assert.assertTrue(metadata.getLastModifiedTime() >= creationTime);
Assert.assertEquals(properties, metadata.getProperties());
client.createKey(secureKeyId, new SecureKeyCreateRequest(desc, "updatedSecureData", properties));
Assert.assertEquals("updatedSecureData", client.getData(secureKeyId));
Assert.assertEquals(1, client.listKeys(NamespaceId.DEFAULT).size());
metadata = client.getKeyMetadata(secureKeyId);
Assert.assertEquals(desc, metadata.getDescription());
Assert.assertTrue(metadata.getLastModifiedTime() >= creationTime);
Assert.assertEquals(properties, metadata.getProperties());
// delete the key
client.deleteKey(secureKeyId);
Assert.assertTrue(client.listKeys(NamespaceId.DEFAULT).isEmpty());
}
use of io.cdap.cdap.proto.id.SecureKeyId in project cdap by caskdata.
the class KMSSecureStoreService method get.
/**
* Returns the data stored in the secure store. Makes two calls to the provider, one to get the metadata and another
* to get the data.
* @param namespace The namespace this key belongs to.
* @param name Name of the key.
* @return An object representing the securely stored data associated with the name.
* @throws NamespaceNotFoundException If the specified namespace does not exist.
* @throws IOException If there was a problem getting the key or the metadata from the underlying key provider.
*/
// Unfortunately KeyProvider does not specify the underlying cause except in the message, so we can not throw a
// more specific exception.
@Override
public SecureStoreData get(String namespace, String name) throws Exception {
checkNamespaceExists(namespace);
String keyName = getKeyName(namespace, name);
KeyProvider.Metadata metadata = provider.getMetadata(keyName);
// Provider returns null if the key is not found.
if (metadata == null) {
throw new NotFoundException(new SecureKeyId(namespace, name));
}
SecureStoreMetadata meta = new SecureStoreMetadata(name, metadata.getDescription(), metadata.getCreated().getTime(), metadata.getAttributes());
KeyProvider.KeyVersion keyVersion = provider.getCurrentKey(keyName);
return new SecureStoreData(meta, keyVersion.getMaterial());
}
use of io.cdap.cdap.proto.id.SecureKeyId in project cdap by caskdata.
the class AuthorizableTest method testSecureKey.
@Test
public void testSecureKey() {
SecureKeyId secureKeyId = new SecureKeyId("ns", "test_secure");
Authorizable authorizable = Authorizable.fromEntityId(secureKeyId);
Assert.assertEquals(secureKeyId.toString(), authorizable.toString());
String widcardId = secureKeyId.toString().replace("est", "*es?t");
Assert.assertEquals(widcardId, Authorizable.fromString(widcardId).toString());
}
Aggregations