Search in sources :

Example 1 with SecretNotFoundException

use of io.cdap.cdap.securestore.spi.SecretNotFoundException in project cdap by caskdata.

the class DefaultSecretStore method delete.

@Override
public void delete(String namespace, String name) throws SecretNotFoundException, IOException {
    TransactionRunners.run(transactionRunner, context -> {
        StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
        List<Field<?>> keyFields = ImmutableList.<Field<?>>builder().addAll(getKeyFields(namespace, name)).build();
        if (!table.read(keyFields).isPresent()) {
            throw new SecretNotFoundException(namespace, name);
        }
        table.delete(keyFields);
    }, SecretNotFoundException.class, IOException.class);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) SecretNotFoundException(io.cdap.cdap.securestore.spi.SecretNotFoundException)

Example 2 with SecretNotFoundException

use of io.cdap.cdap.securestore.spi.SecretNotFoundException in project cdap by caskdata.

the class DefaultSecretStore method get.

@Override
public <T> T get(String namespace, String name, Decoder<T> decoder) throws SecretNotFoundException, IOException {
    return TransactionRunners.run(transactionRunner, context -> {
        StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
        List<Field<?>> keyFields = ImmutableList.<Field<?>>builder().addAll(getKeyFields(namespace, name)).build();
        Optional<StructuredRow> optionalRow = table.read(keyFields);
        if (!optionalRow.isPresent()) {
            throw new SecretNotFoundException(namespace, name);
        }
        StructuredRow row = optionalRow.get();
        return decoder.decode(row.getBytes(StoreDefinition.SecretStore.SECRET_DATA_FIELD));
    }, SecretNotFoundException.class, IOException.class);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) SecretNotFoundException(io.cdap.cdap.securestore.spi.SecretNotFoundException)

Example 3 with SecretNotFoundException

use of io.cdap.cdap.securestore.spi.SecretNotFoundException 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)

Aggregations

SecretNotFoundException (io.cdap.cdap.securestore.spi.SecretNotFoundException)3 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)2 Field (io.cdap.cdap.spi.data.table.field.Field)2 SecureStoreData (io.cdap.cdap.api.security.store.SecureStoreData)1 SecureStoreMetadata (io.cdap.cdap.api.security.store.SecureStoreMetadata)1 SecureKeyNotFoundException (io.cdap.cdap.common.SecureKeyNotFoundException)1 SecureKeyId (io.cdap.cdap.proto.id.SecureKeyId)1 Secret (io.cdap.cdap.securestore.spi.secret.Secret)1 SecretMetadata (io.cdap.cdap.securestore.spi.secret.SecretMetadata)1 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)1