szlta commented on code in PR #13136: URL: https://github.com/apache/iceberg/pull/13136#discussion_r2166599796
########## aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.aws; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.nio.ByteBuffer; +import java.util.Map; +import org.apache.iceberg.encryption.KeyManagementClient; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.kms.KmsClient; +import software.amazon.awssdk.services.kms.model.CreateKeyRequest; +import software.amazon.awssdk.services.kms.model.CreateKeyResponse; +import software.amazon.awssdk.services.kms.model.DataKeySpec; +import software.amazon.awssdk.services.kms.model.KeySpec; +import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest; +import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse; + +@EnabledIfEnvironmentVariables({ + @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"), + @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"), + @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"), + @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}") +}) +public class TestKeyManagementClient { + + private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class); + + private static KmsClient kmsClient; + private static String keyId; + + @BeforeAll + public static void beforeClass() { + kmsClient = AwsClientFactories.defaultFactory().kms(); + CreateKeyRequest createKeyRequest = + CreateKeyRequest.builder() + .keySpec(KeySpec.SYMMETRIC_DEFAULT) + .description( + "Iceberg integration test key for " + TestKeyManagementClient.class.getName()) + .build(); + CreateKeyResponse response = kmsClient.createKey(createKeyRequest); + keyId = response.keyMetadata().keyId(); + } + + @Test + public void testKeyWrapping() { + AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient(); + try { + keyManagementClient.initialize(ImmutableMap.of()); + + ByteBuffer key = ByteBuffer.wrap(new String("super-secret-table-master-key").getBytes()); + ByteBuffer encryptedKey = keyManagementClient.wrapKey(key, keyId); + + assertThat(keyManagementClient.unwrapKey(encryptedKey, keyId)).isEqualTo(key); + } finally { + keyManagementClient.close(); + } + } + + @Test Review Comment: Yep, refactored. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org