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;
}
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);
}
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());
}
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;
}
Aggregations