Search in sources :

Example 1 with KeyListEntry

use of com.amazonaws.services.kms.model.KeyListEntry in project cyberduck by iterate-ch.

the class KMSEncryptionFeature method getKeys.

/**
 * @return List of IDs of KMS managed keys
 */
@Override
public Set<Algorithm> getKeys(final Path file, final LoginCallback prompt) throws BackgroundException {
    final Path container = containerService.getContainer(file);
    final Set<Algorithm> keys = super.getKeys(container, prompt);
    if (container.isRoot()) {
        return keys;
    }
    try {
        final AWSKMS client = this.client(container);
        try {
            final Map<String, String> aliases = new HashMap<>();
            for (AliasListEntry entry : client.listAliases().getAliases()) {
                aliases.put(entry.getTargetKeyId(), entry.getAliasName());
            }
            for (KeyListEntry entry : client.listKeys().getKeys()) {
                keys.add(new AliasedAlgorithm(entry, aliases.get(entry.getKeyId())));
            }
        } catch (AmazonClientException e) {
            throw new AmazonServiceExceptionMappingService().map("Cannot read AWS KMS configuration", e);
        } finally {
            client.shutdown();
        }
    } catch (AccessDeniedException e) {
        log.warn(String.format("Ignore failure reading keys from KMS. %s", e.getMessage()));
        keys.add(SSE_KMS_DEFAULT);
    }
    return keys;
}
Also used : Path(ch.cyberduck.core.Path) AliasListEntry(com.amazonaws.services.kms.model.AliasListEntry) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceExceptionMappingService(ch.cyberduck.core.aws.AmazonServiceExceptionMappingService) AWSKMS(com.amazonaws.services.kms.AWSKMS) KeyListEntry(com.amazonaws.services.kms.model.KeyListEntry)

Example 2 with KeyListEntry

use of com.amazonaws.services.kms.model.KeyListEntry in project aws-doc-sdk-examples by awsdocs.

the class ListCustomerMasterKeys method main.

public static void main(String[] args) {
    AWSKMS kmsClient = AWSKMSClientBuilder.standard().build();
    // List CMKs in this account
    String nextMarker = null;
    do {
        ListKeysRequest req = new ListKeysRequest().withMarker(nextMarker);
        ListKeysResult result = kmsClient.listKeys(req);
        for (KeyListEntry key : result.getKeys()) {
            System.out.printf("Found key with ARN \"%s\".%n", key.getKeyArn());
        }
        nextMarker = result.getNextMarker();
    } while (nextMarker != null);
}
Also used : KeyListEntry(com.amazonaws.services.kms.model.KeyListEntry) ListKeysRequest(com.amazonaws.services.kms.model.ListKeysRequest) ListKeysResult(com.amazonaws.services.kms.model.ListKeysResult) AWSKMS(com.amazonaws.services.kms.AWSKMS)

Example 3 with KeyListEntry

use of com.amazonaws.services.kms.model.KeyListEntry in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method collectEncryptionKeysWhenWeGetBackInfoThenItShouldReturnListWithElements.

@Test
public void collectEncryptionKeysWhenWeGetBackInfoThenItShouldReturnListWithElements() {
    ListKeysResult listKeysResult = new ListKeysResult();
    Set<KeyListEntry> listEntries = new HashSet<>();
    listEntries.add(keyListEntry(1));
    listEntries.add(keyListEntry(2));
    listEntries.add(keyListEntry(3));
    listEntries.add(keyListEntry(4));
    listKeysResult.setKeys(listEntries);
    DescribeKeyResult describeKeyResult = new DescribeKeyResult();
    describeKeyResult.setKeyMetadata(new KeyMetadata());
    ListAliasesResult describeAliasResult = new ListAliasesResult();
    Set<AliasListEntry> aliasListEntries = new HashSet<>();
    aliasListEntries.add(aliasListEntry(1));
    aliasListEntries.add(aliasListEntry(2));
    aliasListEntries.add(aliasListEntry(3));
    aliasListEntries.add(aliasListEntry(4));
    describeAliasResult.setAliases(aliasListEntries);
    when(awsClient.createAWSKMS(any(AwsCredentialView.class), anyString())).thenReturn(awskmsClient);
    when(awskmsClient.listKeys(any(ListKeysRequest.class))).thenReturn(listKeysResult);
    when(awskmsClient.describeKey(any(DescribeKeyRequest.class))).thenReturn(describeKeyResult);
    when(awskmsClient.listAliases(any(ListAliasesRequest.class))).thenReturn(describeAliasResult);
    CloudEncryptionKeys cloudEncryptionKeys = underTest.encryptionKeys(cloudCredential, region("London"), new HashMap<>());
    assertEquals(4L, cloudEncryptionKeys.getCloudEncryptionKeys().size());
}
Also used : ListAliasesResult(com.amazonaws.services.kms.model.ListAliasesResult) AliasListEntry(com.amazonaws.services.kms.model.AliasListEntry) DescribeKeyRequest(com.amazonaws.services.kms.model.DescribeKeyRequest) ListKeysRequest(com.amazonaws.services.kms.model.ListKeysRequest) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) KeyListEntry(com.amazonaws.services.kms.model.KeyListEntry) KeyMetadata(com.amazonaws.services.kms.model.KeyMetadata) DescribeKeyResult(com.amazonaws.services.kms.model.DescribeKeyResult) ListKeysResult(com.amazonaws.services.kms.model.ListKeysResult) ListAliasesRequest(com.amazonaws.services.kms.model.ListAliasesRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with KeyListEntry

use of com.amazonaws.services.kms.model.KeyListEntry in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method keyListEntry.

private KeyListEntry keyListEntry(int i) {
    KeyListEntry keyListEntry = new KeyListEntry();
    keyListEntry.setKeyArn(String.format("key-%s", i));
    keyListEntry.setKeyId(String.format("%s", i));
    return keyListEntry;
}
Also used : KeyListEntry(com.amazonaws.services.kms.model.KeyListEntry)

Aggregations

KeyListEntry (com.amazonaws.services.kms.model.KeyListEntry)4 AWSKMS (com.amazonaws.services.kms.AWSKMS)2 AliasListEntry (com.amazonaws.services.kms.model.AliasListEntry)2 ListKeysRequest (com.amazonaws.services.kms.model.ListKeysRequest)2 ListKeysResult (com.amazonaws.services.kms.model.ListKeysResult)2 Path (ch.cyberduck.core.Path)1 AmazonServiceExceptionMappingService (ch.cyberduck.core.aws.AmazonServiceExceptionMappingService)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 AmazonClientException (com.amazonaws.AmazonClientException)1 DescribeKeyRequest (com.amazonaws.services.kms.model.DescribeKeyRequest)1 DescribeKeyResult (com.amazonaws.services.kms.model.DescribeKeyResult)1 KeyMetadata (com.amazonaws.services.kms.model.KeyMetadata)1 ListAliasesRequest (com.amazonaws.services.kms.model.ListAliasesRequest)1 ListAliasesResult (com.amazonaws.services.kms.model.ListAliasesResult)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1