apucher commented on code in PR #8670: URL: https://github.com/apache/pinot/pull/8670#discussion_r870864421
########## pinot-plugins/pinot-minion-tasks/pinot-minion-builtin-tasks/src/main/java/org/apache/pinot/plugin/minion/tasks/BaseMultipleSegmentsConversionExecutor.java: ########## @@ -291,8 +292,8 @@ public String getUploadURL() { return _uploadURL; } - public String getAuthToken() { - return _authToken; + public AuthProvider getAuthProvider() { + return _authProvider; } Review Comment: I try to minimize changes to SPIs whenever possible. This one one is minor, fortunately, and it doesn't change the observed behavior if the configuration doesn't change. The authProvider may be different across the same JVM. For example, the segment fetcher could use a different auth provider from the uploader. Generally, they'll be the same though. ########## pinot-common/src/main/java/org/apache/pinot/common/auth/AuthProviderUtils.java: ########## @@ -0,0 +1,168 @@ +/** + * 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.pinot.common.auth; + +import java.lang.reflect.Constructor; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.Header; +import org.apache.http.message.BasicHeader; +import org.apache.pinot.spi.auth.AuthProvider; +import org.apache.pinot.spi.env.PinotConfiguration; + + +/** + * Utility class to wrap inference of optimal auth provider from component configs. + */ +public final class AuthProviderUtils { + private AuthProviderUtils() { + // left blank + } + + /** + * Extract an AuthConfig from a pinot configuration subset namespace. + * + * @param pinotConfig pinot configuration + * @param namespace subset namespace + * @return auth config + */ + public static AuthConfig extractAuthConfig(PinotConfiguration pinotConfig, String namespace) { + return new AuthConfig(pinotConfig.subset(namespace).toMap()); + } + + /** + * Create an AuthProvider after extracting a config from a pinot configuration subset namespace + * @see AuthProviderUtils#extractAuthConfig(PinotConfiguration, String) + * + * @param pinotConfig pinot configuration + * @param namespace subset namespace + * @return auth provider + */ + public static AuthProvider extractAuthProvider(PinotConfiguration pinotConfig, String namespace) { + return makeDynamicProvider(extractAuthConfig(pinotConfig, namespace)); + } + + /** + * Create auth provider based on the availability of a static token only, if any. This typically applies to task specs + * + * @param authToken static auth token + * @return auth provider + */ + public static AuthProvider makeStaticProvider(String authToken) { + if (StringUtils.isBlank(authToken)) { + return new NullAuthProvider(); + } + return new StaticTokenAuthProvider(authToken); + } + + /** + * Create auth provider based on an auth config. Mimics legacy behavior for static tokens if provided, or dynamic auth + * providers if additional configs are given. + * + * @param authConfig auth config + * @return auth provider + */ + public static AuthProvider makeDynamicProvider(AuthConfig authConfig) { 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org