Search in sources :

Example 1 with BlockCrypto

use of com.amazonaws.athena.connector.lambda.security.BlockCrypto in project aws-athena-query-federation by awslabs.

the class S3BlockSpillReader method read.

/**
 * Reads a spilled block.
 *
 * @param spillLocation The location to read the spilled Block from.
 * @param key The encryption key to use when reading the spilled Block.
 * @param schema The Schema to use when deserializing the spilled Block.
 * @return The Block stored at the spill location.
 */
public Block read(S3SpillLocation spillLocation, EncryptionKey key, Schema schema) {
    S3Object fullObject = null;
    try {
        logger.debug("read: Started reading block from S3");
        fullObject = amazonS3.getObject(spillLocation.getBucket(), spillLocation.getKey());
        logger.debug("read: Completed reading block from S3");
        BlockCrypto blockCrypto = (key != null) ? new AesGcmBlockCrypto(allocator) : new NoOpBlockCrypto(allocator);
        Block block = blockCrypto.decrypt(key, ByteStreams.toByteArray(fullObject.getObjectContent()), schema);
        logger.debug("read: Completed decrypting block of size.");
        return block;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (fullObject != null) {
            try {
                fullObject.close();
            } catch (IOException ex) {
                logger.warn("read: Exception while closing S3 object", ex);
            }
        }
    }
}
Also used : NoOpBlockCrypto(com.amazonaws.athena.connector.lambda.security.NoOpBlockCrypto) S3Object(com.amazonaws.services.s3.model.S3Object) IOException(java.io.IOException) AesGcmBlockCrypto(com.amazonaws.athena.connector.lambda.security.AesGcmBlockCrypto) BlockCrypto(com.amazonaws.athena.connector.lambda.security.BlockCrypto) AesGcmBlockCrypto(com.amazonaws.athena.connector.lambda.security.AesGcmBlockCrypto) NoOpBlockCrypto(com.amazonaws.athena.connector.lambda.security.NoOpBlockCrypto)

Example 2 with BlockCrypto

use of com.amazonaws.athena.connector.lambda.security.BlockCrypto in project aws-athena-query-federation by awslabs.

the class S3BlockSpillReader method read.

/**
 * Reads spilled data as a byte[].
 *
 * @param spillLocation The location to read the spilled Block from.
 * @param key The encryption key to use when reading the spilled Block.
 * @return The Block stored at the spill location.
 */
public byte[] read(S3SpillLocation spillLocation, EncryptionKey key) {
    S3Object fullObject = null;
    try {
        logger.debug("read: Started reading block from S3");
        fullObject = amazonS3.getObject(spillLocation.getBucket(), spillLocation.getKey());
        logger.debug("read: Completed reading block from S3");
        BlockCrypto blockCrypto = (key != null) ? new AesGcmBlockCrypto(allocator) : new NoOpBlockCrypto(allocator);
        return blockCrypto.decrypt(key, ByteStreams.toByteArray(fullObject.getObjectContent()));
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (fullObject != null) {
            try {
                fullObject.close();
            } catch (IOException ex) {
                logger.warn("read: Exception while closing S3 object", ex);
            }
        }
    }
}
Also used : NoOpBlockCrypto(com.amazonaws.athena.connector.lambda.security.NoOpBlockCrypto) S3Object(com.amazonaws.services.s3.model.S3Object) IOException(java.io.IOException) AesGcmBlockCrypto(com.amazonaws.athena.connector.lambda.security.AesGcmBlockCrypto) BlockCrypto(com.amazonaws.athena.connector.lambda.security.BlockCrypto) AesGcmBlockCrypto(com.amazonaws.athena.connector.lambda.security.AesGcmBlockCrypto) NoOpBlockCrypto(com.amazonaws.athena.connector.lambda.security.NoOpBlockCrypto)

Aggregations

AesGcmBlockCrypto (com.amazonaws.athena.connector.lambda.security.AesGcmBlockCrypto)2 BlockCrypto (com.amazonaws.athena.connector.lambda.security.BlockCrypto)2 NoOpBlockCrypto (com.amazonaws.athena.connector.lambda.security.NoOpBlockCrypto)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 IOException (java.io.IOException)2