Search in sources :

Example 6 with SecureStoreMetadata

use of io.cdap.cdap.api.security.store.SecureStoreMetadata 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());
}
Also used : SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) Test(org.junit.Test)

Example 7 with SecureStoreMetadata

use of io.cdap.cdap.api.security.store.SecureStoreMetadata in project cdap by caskdata.

the class FileSecureStoreServiceTest method testGetMetadata.

@Test
public void testGetMetadata() throws Exception {
    populateStore();
    SecureStoreMetadata metadata = new SecureStoreMetadata(KEY1, DESCRIPTION1, System.currentTimeMillis(), PROPERTIES_1);
    Assert.assertEquals(metadata.getDescription(), secureStore.get(NAMESPACE1, KEY1).getMetadata().getDescription());
    Assert.assertEquals(metadata.getName(), secureStore.get(NAMESPACE1, KEY1).getMetadata().getName());
    SecureStoreMetadata metadata2 = new SecureStoreMetadata(KEY2, DESCRIPTION2, System.currentTimeMillis(), PROPERTIES_2);
    Assert.assertEquals(metadata2.getDescription(), secureStore.get(NAMESPACE1, KEY2).getMetadata().getDescription());
    Assert.assertEquals(metadata2.getName(), secureStore.get(NAMESPACE1, KEY2).getMetadata().getName());
}
Also used : SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) Test(org.junit.Test)

Example 8 with SecureStoreMetadata

use of io.cdap.cdap.api.security.store.SecureStoreMetadata 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;
    }
}
Also used : SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with SecureStoreMetadata

use of io.cdap.cdap.api.security.store.SecureStoreMetadata 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);
    }
}
Also used : Secret(io.cdap.cdap.securestore.spi.secret.Secret) SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureKeyId(io.cdap.cdap.proto.id.SecureKeyId) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) SecretMetadata(io.cdap.cdap.securestore.spi.secret.SecretMetadata) SecureKeyNotFoundException(io.cdap.cdap.common.SecureKeyNotFoundException) SecretNotFoundException(io.cdap.cdap.securestore.spi.SecretNotFoundException)

Example 10 with SecureStoreMetadata

use of io.cdap.cdap.api.security.store.SecureStoreMetadata in project cdap by caskdata.

the class SecretManagerSecureStoreService method list.

@Override
public List<SecureStoreMetadata> list(String namespace) throws Exception {
    validate(namespace);
    List<SecureStoreMetadata> metadataList = new ArrayList<>();
    for (SecretMetadata metadata : secretManager.list(namespace)) {
        metadataList.add(new SecureStoreMetadata(metadata.getName(), metadata.getDescription(), metadata.getCreationTimeMs(), metadata.getProperties()));
    }
    return metadataList;
}
Also used : SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) SecretMetadata(io.cdap.cdap.securestore.spi.secret.SecretMetadata) ArrayList(java.util.ArrayList)

Aggregations

SecureStoreMetadata (io.cdap.cdap.api.security.store.SecureStoreMetadata)20 SecureStoreData (io.cdap.cdap.api.security.store.SecureStoreData)9 Test (org.junit.Test)8 HashMap (java.util.HashMap)5 SecureKeyId (io.cdap.cdap.proto.id.SecureKeyId)4 IOException (java.io.IOException)4 HttpResponse (io.cdap.common.http.HttpResponse)3 ArrayList (java.util.ArrayList)3 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)2 NotFoundException (io.cdap.cdap.common.NotFoundException)2 SecureKeyCreateRequest (io.cdap.cdap.proto.security.SecureKeyCreateRequest)2 SecretMetadata (io.cdap.cdap.securestore.spi.secret.SecretMetadata)2 KeyStoreException (java.security.KeyStoreException)2 Map (java.util.Map)2 KeyProvider (org.apache.hadoop.crypto.key.KeyProvider)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Predicate (com.google.common.base.Predicate)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TypeToken (com.google.common.reflect.TypeToken)1 AbstractModule (com.google.inject.AbstractModule)1