xunliu commented on code in PR #5791: URL: https://github.com/apache/gravitino/pull/5791#discussion_r1877586827
########## core/src/main/java/org/apache/gravitino/authorization/AuthorizationPropertiesMetadata.java: ########## @@ -0,0 +1,230 @@ +/* + * 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.authorization; + +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.apache.gravitino.connector.BasePropertiesMetadata; +import org.apache.gravitino.connector.PropertyEntry; +import org.apache.gravitino.connector.WildcardPropertiesMetadata; + +public class AuthorizationPropertiesMetadata extends BasePropertiesMetadata + implements WildcardPropertiesMetadata { + private static volatile AuthorizationPropertiesMetadata instance = null; + + public static synchronized AuthorizationPropertiesMetadata getInstance() { + if (instance == null) { + synchronized (AuthorizationPropertiesMetadata.class) { + if (instance == null) { + instance = new AuthorizationPropertiesMetadata(); + } + } + } + return instance; + } + + public static final String FIRST_SEGMENT_NAME = "authorization"; + public static final String SECOND_SEGMENT_NAME = "chain"; + + /** Ranger admin web URIs */ + private static final String RANGER_ADMIN_URL_KEY = "ranger.admin.url"; + + public static final String getRangerAdminUrlKey() { + return RANGER_ADMIN_URL_KEY; + } + + public static final String RANGER_ADMIN_URL = + String.format("%s.%s", FIRST_SEGMENT_NAME, RANGER_ADMIN_URL_KEY); + /** Ranger authentication type kerberos or simple */ + private static final String RANGER_AUTH_TYPE_KEY = "ranger.auth.type"; + + public static final String getRangerAuthTypeKey() { + return RANGER_AUTH_TYPE_KEY; + } + + public static final String RANGER_AUTH_TYPE = + String.format("%s.%s", FIRST_SEGMENT_NAME, RANGER_AUTH_TYPE_KEY); + /** + * Ranger admin web login username(auth_type=simple), or kerberos principal(auth_type=kerberos) + */ + private static final String RANGER_USERNAME_KEY = "ranger.username"; + + public static final String getRangerUsernameKey() { + return RANGER_USERNAME_KEY; + } + + public static final String RANGER_USERNAME = + String.format("%s.%s", FIRST_SEGMENT_NAME, RANGER_USERNAME_KEY); + /** + * Ranger admin web login user password(auth_type=simple), or path of the keytab + * file(auth_type=kerberos) + */ + private static final String RANGER_PASSWORD_KEY = "ranger.password"; + + public static final String getRangerPasswordKey() { + return RANGER_PASSWORD_KEY; + } + + public static final String RANGER_PASSWORD = + String.format("%s.%s", FIRST_SEGMENT_NAME, RANGER_PASSWORD_KEY); + + /** Ranger service name */ + private static final String RANGER_SERVICE_NAME_KEY = "ranger.service.name"; + + public static final String getRangerServiceNameKey() { + return RANGER_SERVICE_NAME_KEY; + } + + public static final String RANGER_SERVICE_NAME = + String.format("%s.%s", FIRST_SEGMENT_NAME, RANGER_SERVICE_NAME_KEY); + + /** Chain authorization plugin provider */ + private static final String CHAIN_CATALOG_PROVIDER_KEY = "catalog-provider"; + + public static final String getChainCatalogProviderKey() { + return CHAIN_CATALOG_PROVIDER_KEY; + } + + public static final String CHAIN_CATALOG_PROVIDER = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, CHAIN_CATALOG_PROVIDER_KEY); + + /** Chain authorization plugin provider */ + private static final String CHAIN_PROVIDER_KEY = "provider"; + + public static final String getChainProviderKey() { + return CHAIN_PROVIDER_KEY; + } + + public static final String CHAIN_PROVIDER = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, CHAIN_PROVIDER_KEY); + /** Chain authorization Ranger admin web URIs */ + public static final String CHAIN_RANGER_ADMIN_URL = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, RANGER_ADMIN_URL_KEY); + /** Chain authorization Ranger authentication type kerberos or simple */ + public static final String CHAIN_RANGER_AUTH_TYPES = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, RANGER_AUTH_TYPE_KEY); + /** Chain authorization Ranger username */ + public static final String CHAIN_RANGER_USERNAME = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, RANGER_USERNAME_KEY); + /** + * Chain authorization Ranger admin web login user password(auth_type=simple), or path of the + * keytab file(auth_type=kerberos) + */ + public static final String CHAIN_RANGER_PASSWORD = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, RANGER_PASSWORD_KEY); + /** Chain authorization Ranger service name */ + public static final String CHAIN_RANGER_SERVICE_NAME = + AuthorizationPropertiesMetadata.getInstance() + .getPropertyValue(Constants.WILDCARD, RANGER_SERVICE_NAME_KEY); + + public static String chainKeyToPluginKey(String chainKey, String plugin) { Review Comment: Removed. ########## core/src/main/java/org/apache/gravitino/connector/PropertyEntry.java: ########## @@ -268,6 +278,22 @@ public static PropertyEntry<Boolean> booleanReservedPropertyEntry( return booleanPropertyEntry(name, description, false, true, defaultValue, hidden, true); } + public static PropertyEntry<String> wildcardPropertyEntry(String name, String description) { + return new Builder<String>() + .withName(name) + .withDescription(description) + .withRequired(false) + .withImmutable(false) + .withJavaType(String.class) + .withDefaultValue(null) + .withDecoder(Function.identity()) + .withEncoder(Function.identity()) + .withHidden(false) + .withReserved(false) Review Comment: Modified these codes. ########## core/src/main/java/org/apache/gravitino/connector/PropertyEntry.java: ########## @@ -64,7 +65,8 @@ private PropertyEntry( Function<String, T> decoder, Function<T, String> encoder, boolean hidden, - boolean reserved) { + boolean reserved, + boolean wildcard) { Review Comment: DONE. ########## core/src/main/java/org/apache/gravitino/connector/WildcardPropertiesMeta.java: ########## @@ -0,0 +1,178 @@ +/* + * 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.connector; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * WildcardPropertiesMeta is a utility class to validate wildcard properties in the properties + * metadata. <br> + * <br> + * WildcardPropertiesMeta interface defines: <br> + * FirstNode.SecondNode.WildcardNode = "" <br> + * FirstNode.SecondNode.*.property-key1 = "" <br> + * FirstNode.SecondNode.*.property-key2 = "" <br> Review Comment: DONE. ########## core/src/main/java/org/apache/gravitino/connector/WildcardPropertiesMetadata.java: ########## @@ -0,0 +1,171 @@ +/* + * 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.connector; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import org.apache.gravitino.authorization.AuthorizationPropertiesMetadata; + +/** + * WildcardPropertiesMeta is a utility class to validate wildcard properties in the properties Review Comment: DONE. ########## core/src/main/java/org/apache/gravitino/connector/WildcardPropertiesMetadata.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.connector; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import org.apache.gravitino.authorization.AuthorizationPropertiesMetadata; + +/** + * WildcardPropertiesMeta is a interface class to support wildcard in the properties metadata. <br> Review Comment: DONE ########## core/src/main/java/org/apache/gravitino/authorization/AuthorizationPropertiesMetadata.java: ########## @@ -0,0 +1,230 @@ +/* + * 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.authorization; + +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.apache.gravitino.connector.BasePropertiesMetadata; +import org.apache.gravitino.connector.PropertyEntry; +import org.apache.gravitino.connector.WildcardPropertiesMetadata; + +public class AuthorizationPropertiesMetadata extends BasePropertiesMetadata + implements WildcardPropertiesMetadata { + private static volatile AuthorizationPropertiesMetadata instance = null; + + public static synchronized AuthorizationPropertiesMetadata getInstance() { + if (instance == null) { + synchronized (AuthorizationPropertiesMetadata.class) { + if (instance == null) { + instance = new AuthorizationPropertiesMetadata(); + } + } + } + return instance; + } + + public static final String FIRST_SEGMENT_NAME = "authorization"; + public static final String SECOND_SEGMENT_NAME = "chain"; + + /** Ranger admin web URIs */ + private static final String RANGER_ADMIN_URL_KEY = "ranger.admin.url"; + + public static final String getRangerAdminUrlKey() { Review Comment: I removed `final`. ########## core/src/main/java/org/apache/gravitino/connector/WildcardPropertiesMetadata.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.connector; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import org.apache.gravitino.authorization.AuthorizationPropertiesMetadata; + +/** + * WildcardPropertiesMeta is a interface class to support wildcard in the properties metadata. <br> + * <br> + * WildcardPropertiesMetadata interface defines: <br> + * Prefix.Wildcard = "" <br> + * Prefix.*.properties-key1 = "" <br> + * Prefix.*.properties-key2 = "" <br> + * NOTE: Prefix support multiple segment, separated by dot. <br> Review Comment: DONE ########## core/src/main/java/org/apache/gravitino/connector/WildcardPropertiesMetadata.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.connector; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import org.apache.gravitino.authorization.AuthorizationPropertiesMetadata; + +/** + * WildcardPropertiesMeta is a interface class to support wildcard in the properties metadata. <br> + * <br> + * WildcardPropertiesMetadata interface defines: <br> + * Prefix.Wildcard = "" <br> + * Prefix.*.properties-key1 = "" <br> + * Prefix.*.properties-key2 = "" <br> + * NOTE: Prefix support multiple segment, separated by dot. <br> + * NOTE: properties-key{N} support multiple segment, separated by dot. <br> + * <br> + * Use define a WildcardPropertiesMetadata object: <br> + * a1.b1.c1.WildcardNode = "WildcardValue1,WildcardValue2" <br> + * a1.b1.c1.{WildcardValue1}.x1.y1.z1 = "WildcardValue1 properties-key1 value" <br> + * a1.b1.c1.{WildcardValue1}.x1.y2.z2 = "WildcardValue1 properties-key2 value" <br> + * a1.b1.c1.{WildcardValue1}.x1.y2.z3 = "WildcardValue1 properties-key3 value" <br> + * a1.b1.c1.{WildcardValue2}.x1.y1.z1 = "WildcardValue2 properties-key1 value" <br> + * a1.b1.c1.{WildcardValue2}.x1.y2.z2 = "WildcardValue2 properties-key2 value" <br> + * a1.b1.c1.{WildcardValue2}.x1.y2.z3 = "WildcardValue2 properties-key3 value" <br> + * <br> + * Configuration Example: {@link AuthorizationPropertiesMetadata} <br> + * "authorization.chain.plugins" = "hive1,hdfs1" <br> + * "authorization.chain.hive1.provider" = "ranger"; <br> + * "authorization.chain.hive1.catalog-provider" = "hive"; <br> + * "authorization.chain.hive1.ranger.auth.type" = "simple"; <br> + * "authorization.chain.hive1.ranger.admin.url" = "http://localhost:6080"; <br> + * "authorization.chain.hive1.ranger.username" = "admin"; <br> + * "authorization.chain.hive1.ranger.password" = "admin"; <br> + * "authorization.chain.hive1.ranger.service.name" = "hiveDev"; <br> + * "authorization.chain.hdfs1.provider" = "ranger"; <br> + * "authorization.chain.hdfs1.catalog-provider" = "hadoop"; <br> + * "authorization.chain.hdfs1.ranger.auth.type" = "simple"; <br> + * "authorization.chain.hdfs1.ranger.admin.url" = "http://localhost:6080"; <br> + * "authorization.chain.hdfs1.ranger.username" = "admin"; <br> + * "authorization.chain.hdfs1.ranger.password" = "admin"; <br> + * "authorization.chain.hdfs1.ranger.service.name" = "hdfsDev"; <br> + */ +public interface WildcardPropertiesMetadata { + class Constants { + public static final String WILDCARD = "*"; + public static final String WILDCARD_CONFIG_VALUES_SPLITTER = ","; + } + + /** The prefix name */ + String prefixName(); Review Comment: DONE. ########## core/src/main/java/org/apache/gravitino/connector/WildcardPropertiesMetadata.java: ########## @@ -0,0 +1,170 @@ +/* + * 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.connector; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import org.apache.gravitino.authorization.AuthorizationPropertiesMetadata; + +/** + * WildcardPropertiesMeta is a interface class to support wildcard in the properties metadata. <br> + * <br> + * WildcardPropertiesMetadata interface defines: <br> + * Prefix.Wildcard = "" <br> + * Prefix.*.properties-key1 = "" <br> + * Prefix.*.properties-key2 = "" <br> + * NOTE: Prefix support multiple segment, separated by dot. <br> + * NOTE: properties-key{N} support multiple segment, separated by dot. <br> + * <br> + * Use define a WildcardPropertiesMetadata object: <br> + * a1.b1.c1.WildcardNode = "WildcardValue1,WildcardValue2" <br> Review Comment: DONE -- 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]
