hubgeter commented on code in PR #60649: URL: https://github.com/apache/doris/pull/60649#discussion_r2792085149
########## fe/fe-common/src/main/java/org/apache/doris/common/maxcompute/MCUtils.java: ########## @@ -0,0 +1,78 @@ +// 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.doris.common.maxcompute; + +import com.aliyun.auth.credentials.Credential; +import com.aliyun.auth.credentials.provider.EcsRamRoleCredentialProvider; +import com.aliyun.auth.credentials.provider.RamRoleArnCredentialProvider; +import com.aliyun.odps.Odps; +import com.aliyun.odps.account.Account; +import com.aliyun.odps.account.AklessAccount; +import com.aliyun.odps.account.AliyunAccount; + +import java.util.Map; + +public class MCUtils { + public static void checkAuthProperties(Map<String, String> properties) { + String authType = properties.getOrDefault(MCProperties.AUTH_TYPE, MCProperties.DEFAULT_AUTH_TYPE); + if (authType.equalsIgnoreCase(MCProperties.AUTH_TYPE_AK_SK)) { + if (!properties.containsKey(MCProperties.ACCESS_KEY) || !properties.containsKey(MCProperties.SECRET_KEY)) { + throw new RuntimeException("Missing access key or secret key for AK/SK auth type"); + } + } else if (authType.equalsIgnoreCase(MCProperties.AUTH_TYPE_RAM_ROLE_ARN)) { + if (!properties.containsKey(MCProperties.ACCESS_KEY) || !properties.containsKey(MCProperties.SECRET_KEY) + || !properties.containsKey(MCProperties.RAM_ROLE_ARN)) { + throw new RuntimeException("Missing access key, secret key or role arn for RAM Role ARN auth type"); + } + } else if (authType.equalsIgnoreCase(MCProperties.AUTH_TYPE_ECS_RAM_ROLE)) { + if (!properties.containsKey(MCProperties.ECS_RAM_ROLE)) { + throw new RuntimeException("Missing role name for ECS RAM Role auth type"); + } + } else { + throw new RuntimeException("Unsupported auth type: " + authType); + } + } + + public static Odps createMcClient(Map<String, String> properties) { + String authType = properties.getOrDefault(MCProperties.AUTH_TYPE, MCProperties.DEFAULT_AUTH_TYPE); + if (authType.equalsIgnoreCase(MCProperties.AUTH_TYPE_AK_SK)) { + String accessKey = properties.get(MCProperties.ACCESS_KEY); + String secretKey = properties.get(MCProperties.SECRET_KEY); + Account account = new AliyunAccount(accessKey, secretKey); + return new Odps(account); + } else if (authType.equalsIgnoreCase(MCProperties.AUTH_TYPE_RAM_ROLE_ARN)) { + String accessKey = properties.get(MCProperties.ACCESS_KEY); Review Comment: This is typically used to access maxcompute across Alibaba Cloud accounts, and aksk is required. -- 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]
