Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2014 Google Inc.
*
* Licensed 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 com.google.cloud.hadoop.util;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import com.google.api.client.http.HttpTransport;
import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.ComputeEngineCredentials;
import com.google.auth.oauth2.ExternalAccountCredentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ImpersonatedCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.auth.oauth2.UserCredentials;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.GoogleLogger;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
/**
* The Hadoop credentials configuration.
*
*
When reading configuration this class makes use of a list of key prefixes that are each
* applied to key suffixes to create a complete configuration key. There is a base prefix of
* 'google.cloud.' that is included by the builder for each configuration key suffix. When
* constructing, other prefixes can be specified. Prefixes specified later can be used to override
* the values of previously set values. In this way a set of global credentials can be specified for
* most connectors with an override specified for any connectors that need different credentials.
*/
public class HadoopCredentialsConfiguration {
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/**
* All instances constructed using the builder will use {@code google.cloud} as the first prefix
* checked. Other prefixes can be added and will override values in the {@code google.cloud}
* prefix.
*/
public static final String BASE_KEY_PREFIX = "google.cloud";
public static final String CLOUD_PLATFORM_SCOPE =
"https://www.googleapis.com/auth/cloud-platform";
/** Key suffix used to configure authentication type. */
public static final HadoopConfigurationProperty AUTHENTICATION_TYPE_SUFFIX =
new HadoopConfigurationProperty<>(".auth.type", AuthenticationType.COMPUTE_ENGINE);
/**
* Key suffix used to configure the path to a JSON file containing a Service Account key and
* identifier (email). Technically, this could be a JSON containing a non-service account user,
* but this setting is only used in the service account flow and is namespaced as such.
*/
public static final HadoopConfigurationProperty SERVICE_ACCOUNT_JSON_KEYFILE_SUFFIX =
new HadoopConfigurationProperty<>(".auth.service.account.json.keyfile");
/**
* Key suffix used to configure the path to a JSON file containing a workload identity federation,
* i.e. external account credential configuration. Technically, this could be a JSON containing an
* service account impersonation url and credential source. but this setting is only used in the
* workload identity federation flow and is namespaced as such.
*/
public static final HadoopConfigurationProperty
WORKLOAD_IDENTITY_FEDERATION_CREDENTIAL_CONFIG_FILE_SUFFIX =
new HadoopConfigurationProperty<>(
".auth.workload.identity.federation.credential.config.file");
/**
* Key suffix used to configure {@link AccessTokenProvider} that will be used to generate {@link
* AccessTokenProvider.AccessToken}s.
*/
public static final HadoopConfigurationProperty>
ACCESS_TOKEN_PROVIDER_SUFFIX =
new HadoopConfigurationProperty<>(".auth.access.token.provider");
/**
* Key suffix used to configure the impersonating service account with which to call GCS API to
* get access token.
*/
public static final HadoopConfigurationProperty IMPERSONATION_SERVICE_ACCOUNT_SUFFIX =
new HadoopConfigurationProperty<>(".auth.impersonation.service.account");
/**
* Key prefix for the user identifier associated with the service account to impersonate when
* accessing GCS.
*/
public static final HadoopConfigurationProperty