jackye1995 commented on code in PR #4423: URL: https://github.com/apache/iceberg/pull/4423#discussion_r856517022
########## aws/src/integration/java/org/apache/iceberg/aws/lakeformation/LakeFormationTestBase.java: ########## @@ -0,0 +1,511 @@ +/* + * 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.lakeformation; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.aws.AssumeRoleAwsClientFactory; +import org.apache.iceberg.aws.AwsIntegTestUtil; +import org.apache.iceberg.aws.AwsProperties; +import org.apache.iceberg.aws.glue.GlueCatalog; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.types.Types; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; +import software.amazon.awssdk.regions.PartitionMetadata; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.glue.GlueClient; +import software.amazon.awssdk.services.glue.GlueClientBuilder; +import software.amazon.awssdk.services.iam.IamClient; +import software.amazon.awssdk.services.iam.model.AttachRolePolicyRequest; +import software.amazon.awssdk.services.iam.model.CreatePolicyRequest; +import software.amazon.awssdk.services.iam.model.CreateRoleRequest; +import software.amazon.awssdk.services.iam.model.CreateRoleResponse; +import software.amazon.awssdk.services.iam.model.DeletePolicyRequest; +import software.amazon.awssdk.services.iam.model.DeleteRoleRequest; +import software.amazon.awssdk.services.iam.model.DetachRolePolicyRequest; +import software.amazon.awssdk.services.iam.model.GetPolicyVersionRequest; +import software.amazon.awssdk.services.iam.model.GetRolePolicyRequest; +import software.amazon.awssdk.services.iam.model.NoSuchEntityException; +import software.amazon.awssdk.services.iam.model.PolicyVersion; +import software.amazon.awssdk.services.lakeformation.LakeFormationClient; +import software.amazon.awssdk.services.lakeformation.LakeFormationClientBuilder; +import software.amazon.awssdk.services.lakeformation.model.AlreadyExistsException; +import software.amazon.awssdk.services.lakeformation.model.CatalogResource; +import software.amazon.awssdk.services.lakeformation.model.DataLakePrincipal; +import software.amazon.awssdk.services.lakeformation.model.DataLakeSettings; +import software.amazon.awssdk.services.lakeformation.model.DataLocationResource; +import software.amazon.awssdk.services.lakeformation.model.DatabaseResource; +import software.amazon.awssdk.services.lakeformation.model.DeregisterResourceRequest; +import software.amazon.awssdk.services.lakeformation.model.EntityNotFoundException; +import software.amazon.awssdk.services.lakeformation.model.GetDataLakeSettingsRequest; +import software.amazon.awssdk.services.lakeformation.model.GetDataLakeSettingsResponse; +import software.amazon.awssdk.services.lakeformation.model.GrantPermissionsRequest; +import software.amazon.awssdk.services.lakeformation.model.Permission; +import software.amazon.awssdk.services.lakeformation.model.PutDataLakeSettingsRequest; +import software.amazon.awssdk.services.lakeformation.model.PutDataLakeSettingsResponse; +import software.amazon.awssdk.services.lakeformation.model.RegisterResourceRequest; +import software.amazon.awssdk.services.lakeformation.model.Resource; +import software.amazon.awssdk.services.lakeformation.model.TableResource; +import software.amazon.awssdk.services.sts.StsClient; +import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider; +import software.amazon.awssdk.services.sts.model.AssumeRoleRequest; + +@SuppressWarnings({"VisibilityModifier", "HideUtilityClassConstructor"}) +public class LakeFormationTestBase { + + static final Logger LOG = LoggerFactory.getLogger(LakeFormationTestBase.class); + static final int IAM_PROPAGATION_DELAY = 10000; + static final int ASSUME_ROLE_SESSION_DURATION = 3600; + static final String LF_REGISTER_PATH_ROLE_PREFIX = "LFRegisterPathRole_"; + static final String LF_PRIVILEGED_ROLE_PREFIX = "LFPrivilegedRole_"; + static final String LF_TEST_DB_PREFIX = "lf_test_db"; + static final String LF_TEST_TABLE_PREFIX = "lf_test_table"; + static final String TEST_PATH_PREFIX = "iceberg-lf-test/"; + static final String DEFAULT_IAM_POLICY_VERSION = "v1"; + static final String LF_AUTHORIZED_CALLER_VALUE = "emr"; + static final String LF_REGISTER_PATH_ROLE_S3_POLICY_PREFIX = "LFRegisterPathRoleS3Policy_"; + static final String LF_REGISTER_PATH_ROLE_LF_POLICY_PREFIX = "LFRegisterPathRoleLfPolicy_"; + static final String LF_REGISTER_PATH_ROLE_IAM_POLICY_PREFIX = "LFRegisterPathRoleIamPolicy_"; + static final String LF_PRIVILEGED_ROLE_POLICY_PREFIX = "LFPrivilegedRoleTestPolicy_"; + + static Map<String, String> assumeRoleProperties; + static String lfRegisterPathRoleName; + static String lfPrivilegedRoleName; + static String lfRegisterPathRoleArn; + static String lfPrivilegedRoleArn; + static String lfRegisterPathRoleS3PolicyName; + static String lfRegisterPathRoleLfPolicyName; + static String lfRegisterPathRoleIamPolicyName; + static String lfPrivilegedRolePolicyName; + static DataLakePrincipal principalUnderTest; + static String testBucketPath = "s3://" + AwsIntegTestUtil.testBucketName() + "/" + TEST_PATH_PREFIX; + static Schema schema = new Schema(Types.NestedField.required(1, "c1", Types.StringType.get(), "c1")); + static PartitionSpec partitionSpec = PartitionSpec.builderFor(schema).build(); + + static GlueCatalog glueCatalogRegisterPathRole; + static GlueCatalog glueCatalogPrivilegedRole; + static IamClient iam; + static LakeFormationClient lf; Review Comment: nit: prefer to use full name `lakeformation` ########## aws/src/integration/java/org/apache/iceberg/aws/lakeformation/LakeFormationTestBase.java: ########## @@ -0,0 +1,511 @@ +/* + * 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.lakeformation; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.aws.AssumeRoleAwsClientFactory; +import org.apache.iceberg.aws.AwsIntegTestUtil; +import org.apache.iceberg.aws.AwsProperties; +import org.apache.iceberg.aws.glue.GlueCatalog; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.types.Types; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; +import software.amazon.awssdk.regions.PartitionMetadata; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.glue.GlueClient; +import software.amazon.awssdk.services.glue.GlueClientBuilder; +import software.amazon.awssdk.services.iam.IamClient; +import software.amazon.awssdk.services.iam.model.AttachRolePolicyRequest; +import software.amazon.awssdk.services.iam.model.CreatePolicyRequest; +import software.amazon.awssdk.services.iam.model.CreateRoleRequest; +import software.amazon.awssdk.services.iam.model.CreateRoleResponse; +import software.amazon.awssdk.services.iam.model.DeletePolicyRequest; +import software.amazon.awssdk.services.iam.model.DeleteRoleRequest; +import software.amazon.awssdk.services.iam.model.DetachRolePolicyRequest; +import software.amazon.awssdk.services.iam.model.GetPolicyVersionRequest; +import software.amazon.awssdk.services.iam.model.GetRolePolicyRequest; +import software.amazon.awssdk.services.iam.model.NoSuchEntityException; +import software.amazon.awssdk.services.iam.model.PolicyVersion; +import software.amazon.awssdk.services.lakeformation.LakeFormationClient; +import software.amazon.awssdk.services.lakeformation.LakeFormationClientBuilder; +import software.amazon.awssdk.services.lakeformation.model.AlreadyExistsException; +import software.amazon.awssdk.services.lakeformation.model.CatalogResource; +import software.amazon.awssdk.services.lakeformation.model.DataLakePrincipal; +import software.amazon.awssdk.services.lakeformation.model.DataLakeSettings; +import software.amazon.awssdk.services.lakeformation.model.DataLocationResource; +import software.amazon.awssdk.services.lakeformation.model.DatabaseResource; +import software.amazon.awssdk.services.lakeformation.model.DeregisterResourceRequest; +import software.amazon.awssdk.services.lakeformation.model.EntityNotFoundException; +import software.amazon.awssdk.services.lakeformation.model.GetDataLakeSettingsRequest; +import software.amazon.awssdk.services.lakeformation.model.GetDataLakeSettingsResponse; +import software.amazon.awssdk.services.lakeformation.model.GrantPermissionsRequest; +import software.amazon.awssdk.services.lakeformation.model.Permission; +import software.amazon.awssdk.services.lakeformation.model.PutDataLakeSettingsRequest; +import software.amazon.awssdk.services.lakeformation.model.PutDataLakeSettingsResponse; +import software.amazon.awssdk.services.lakeformation.model.RegisterResourceRequest; +import software.amazon.awssdk.services.lakeformation.model.Resource; +import software.amazon.awssdk.services.lakeformation.model.TableResource; +import software.amazon.awssdk.services.sts.StsClient; +import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider; +import software.amazon.awssdk.services.sts.model.AssumeRoleRequest; + +@SuppressWarnings({"VisibilityModifier", "HideUtilityClassConstructor"}) +public class LakeFormationTestBase { + + static final Logger LOG = LoggerFactory.getLogger(LakeFormationTestBase.class); + static final int IAM_PROPAGATION_DELAY = 10000; + static final int ASSUME_ROLE_SESSION_DURATION = 3600; + static final String LF_REGISTER_PATH_ROLE_PREFIX = "LFRegisterPathRole_"; + static final String LF_PRIVILEGED_ROLE_PREFIX = "LFPrivilegedRole_"; + static final String LF_TEST_DB_PREFIX = "lf_test_db"; + static final String LF_TEST_TABLE_PREFIX = "lf_test_table"; + static final String TEST_PATH_PREFIX = "iceberg-lf-test/"; + static final String DEFAULT_IAM_POLICY_VERSION = "v1"; + static final String LF_AUTHORIZED_CALLER_VALUE = "emr"; + static final String LF_REGISTER_PATH_ROLE_S3_POLICY_PREFIX = "LFRegisterPathRoleS3Policy_"; + static final String LF_REGISTER_PATH_ROLE_LF_POLICY_PREFIX = "LFRegisterPathRoleLfPolicy_"; + static final String LF_REGISTER_PATH_ROLE_IAM_POLICY_PREFIX = "LFRegisterPathRoleIamPolicy_"; + static final String LF_PRIVILEGED_ROLE_POLICY_PREFIX = "LFPrivilegedRoleTestPolicy_"; + + static Map<String, String> assumeRoleProperties; + static String lfRegisterPathRoleName; + static String lfPrivilegedRoleName; + static String lfRegisterPathRoleArn; + static String lfPrivilegedRoleArn; + static String lfRegisterPathRoleS3PolicyName; + static String lfRegisterPathRoleLfPolicyName; + static String lfRegisterPathRoleIamPolicyName; + static String lfPrivilegedRolePolicyName; + static DataLakePrincipal principalUnderTest; + static String testBucketPath = "s3://" + AwsIntegTestUtil.testBucketName() + "/" + TEST_PATH_PREFIX; + static Schema schema = new Schema(Types.NestedField.required(1, "c1", Types.StringType.get(), "c1")); + static PartitionSpec partitionSpec = PartitionSpec.builderFor(schema).build(); + + static GlueCatalog glueCatalogRegisterPathRole; + static GlueCatalog glueCatalogPrivilegedRole; + static IamClient iam; + static LakeFormationClient lf; Review Comment: nit: prefer to use full name `lakeformation` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
