yuqi1129 commented on code in PR #5701: URL: https://github.com/apache/gravitino/pull/5701#discussion_r1862320351
########## api/src/main/java/org/apache/gravitino/credential/OSSTokenCredential.java: ########## @@ -0,0 +1,112 @@ +/* + * 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.gravitino.credential; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; + +/** OSS token credential. */ +public class OSSTokenCredential implements Credential { + + /** OSS token credential type. */ + public static final String OSS_TOKEN_CREDENTIAL_TYPE = "oss-token"; + /** OSS session access key ID used to access OSS data. */ + public static final String GRAVITINO_OSS_SESSION_ACCESS_KEY_ID = "oss-access-key-id"; + /** OSS session secret access key used to access OSS data. */ + public static final String GRAVITINO_OSS_SESSION_SECRET_ACCESS_KEY = "oss-secret-access-key"; + /** OSS session token. */ + public static final String GRAVITINO_OSS_TOKEN = "oss-security-token"; + + private final String accessKeyId; + private final String secretAccessKey; + private final String securityToken; + private final long expireTimeInMS; Review Comment: is `expireTimeInMS` a timestamp value? ########## iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/integration/test/IcebergRESTOSSIT.java: ########## @@ -0,0 +1,135 @@ +/* + * 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.gravitino.iceberg.integration.test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants; +import org.apache.gravitino.credential.CredentialConstants; +import org.apache.gravitino.iceberg.common.IcebergConfig; +import org.apache.gravitino.integration.test.util.BaseIT; +import org.apache.gravitino.integration.test.util.DownloaderUtils; +import org.apache.gravitino.integration.test.util.ITUtils; +import org.apache.gravitino.storage.OSSProperties; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.junit.platform.commons.util.StringUtils; + +@EnabledIfEnvironmentVariable(named = "GRAVITINO_TEST_CLOUD_IT", matches = "true") +public class IcebergRESTOSSIT extends IcebergRESTJdbcCatalogIT { + + private String warehouse; + private String accessKey; + private String secretKey; + private String endpoint; + private String roleArn; + private String externalId; + private String region; + + @Override + void initEnv() { + this.warehouse = + String.format( + "oss://%s/gravitino-test", + getFromEnvOrDefault("GRAVITINO_OSS_BUCKET", "{BUCKET_NAME}")); + this.accessKey = getFromEnvOrDefault("GRAVITINO_OSS_ACCESS_KEY", "{ACCESS_KEY}"); + this.secretKey = getFromEnvOrDefault("GRAVITINO_OSS_SECRET_KEY", "{SECRET_KEY}"); + this.endpoint = getFromEnvOrDefault("GRAVITINO_OSS_ENDPOINT", "{GRAVITINO_OSS_ENDPOINT}"); + this.region = getFromEnvOrDefault("GRAVITINO_OSS_REGION", "{GRAVITINO_OSS_REGION}"); + this.roleArn = getFromEnvOrDefault("GRAVITINO_OSS_ROLE_ARN", "{ROLE_ARN}"); + this.externalId = getFromEnvOrDefault("GRAVITINO_OSS_EXTERNAL_ID", ""); + + if (ITUtils.isEmbedded()) { + return; + } + try { + downloadIcebergForAliyunJar(); + } catch (IOException e) { + LOG.warn("Download Iceberg AWS bundle jar failed,", e); + throw new RuntimeException(e); + } + copyAliyunOSSJar(); + } + + @Override + public Map<String, String> getCatalogConfig() { + HashMap m = new HashMap<String, String>(); + m.putAll(getCatalogJdbcConfig()); + m.putAll(getOSSConfig()); + return m; + } + + public boolean supportsCredentialVending() { + return true; + } + + private Map<String, String> getOSSConfig() { + Map configMap = new HashMap<String, String>(); + + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + CredentialConstants.CREDENTIAL_PROVIDER_TYPE, + CredentialConstants.OSS_TOKEN_CREDENTIAL_PROVIDER); + configMap.put(IcebergConfig.ICEBERG_CONFIG_PREFIX + OSSProperties.GRAVITINO_OSS_REGION, region); + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + OSSProperties.GRAVITINO_OSS_ENDPOINT, endpoint); + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + OSSProperties.GRAVITINO_OSS_ACCESS_KEY_ID, accessKey); + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + OSSProperties.GRAVITINO_OSS_ACCESS_KEY_SECRET, + secretKey); + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + OSSProperties.GRAVITINO_OSS_ROLE_ARN, roleArn); + if (StringUtils.isNotBlank(externalId)) { + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + OSSProperties.GRAVITINO_OSS_EXTERNAL_ID, + externalId); + } + + configMap.put( + IcebergConfig.ICEBERG_CONFIG_PREFIX + IcebergConstants.IO_IMPL, + "org.apache.iceberg.aliyun.oss.OSSFileIO"); + configMap.put(IcebergConfig.ICEBERG_CONFIG_PREFIX + IcebergConstants.WAREHOUSE, warehouse); + + return configMap; + } + + private void downloadIcebergForAliyunJar() throws IOException { + String icebergBundleJarName = "iceberg-aliyun-1.5.2.jar"; + String icebergBundleJarUri = + "https://repo1.maven.org/maven2/org/apache/iceberg/" + + "iceberg-aliyun/1.5.2/" + + icebergBundleJarName; + String gravitinoHome = System.getenv("GRAVITINO_HOME"); + String targetDir = String.format("%s/iceberg-rest-server/libs/", gravitinoHome); + DownloaderUtils.downloadFile(icebergBundleJarUri, targetDir); + } + + private void copyAliyunOSSJar() { + String gravitinoHome = System.getenv("GRAVITINO_HOME"); + String targetDir = String.format("%s/iceberg-rest-server/libs/", gravitinoHome); + BaseIT.copyBundleJarsToDirectory("aws-bundle", targetDir); Review Comment: This should be `aliyun-bundle` -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org