- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
228 lines
9.0 KiB
Java
228 lines
9.0 KiB
Java
package com.amazonaws;
|
|
|
|
import com.amazonaws.auth.RegionAwareSigner;
|
|
import com.amazonaws.auth.Signer;
|
|
import com.amazonaws.auth.SignerFactory;
|
|
import com.amazonaws.http.AmazonHttpClient;
|
|
import com.amazonaws.http.ExecutionContext;
|
|
import com.amazonaws.http.HttpClient;
|
|
import com.amazonaws.logging.Log;
|
|
import com.amazonaws.logging.LogFactory;
|
|
import com.amazonaws.metrics.AwsSdkMetrics;
|
|
import com.amazonaws.metrics.RequestMetricCollector;
|
|
import com.amazonaws.regions.Region;
|
|
import com.amazonaws.regions.Regions;
|
|
import com.amazonaws.util.AWSRequestMetrics;
|
|
import com.amazonaws.util.AwsHostNameUtils;
|
|
import com.amazonaws.util.Classes;
|
|
import com.amazonaws.util.StringUtils;
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.util.List;
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class AmazonWebServiceClient {
|
|
public static final Log LOG = LogFactory.getLog(AmazonWebServiceClient.class);
|
|
public AmazonHttpClient client;
|
|
public ClientConfiguration clientConfiguration;
|
|
public volatile URI endpoint;
|
|
public volatile String endpointPrefix;
|
|
public volatile Region region;
|
|
public final List requestHandler2s = new CopyOnWriteArrayList();
|
|
public volatile String serviceName;
|
|
public volatile Signer signer;
|
|
public volatile String signerRegionOverride;
|
|
public long timeOffset;
|
|
|
|
public String getEndpointPrefix() {
|
|
return this.endpointPrefix;
|
|
}
|
|
|
|
public AmazonWebServiceClient(ClientConfiguration clientConfiguration, HttpClient httpClient) {
|
|
this.clientConfiguration = clientConfiguration;
|
|
this.client = new AmazonHttpClient(clientConfiguration, httpClient);
|
|
}
|
|
|
|
public void setEndpoint(String str) {
|
|
URI uri = toURI(str);
|
|
Signer computeSignerByURI = computeSignerByURI(uri, this.signerRegionOverride, false);
|
|
synchronized (this) {
|
|
this.endpoint = uri;
|
|
this.signer = computeSignerByURI;
|
|
}
|
|
}
|
|
|
|
public final URI toURI(String str) {
|
|
if (!str.contains("://")) {
|
|
str = this.clientConfiguration.getProtocol().toString() + "://" + str;
|
|
}
|
|
try {
|
|
return new URI(str);
|
|
} catch (URISyntaxException e) {
|
|
throw new IllegalArgumentException(e);
|
|
}
|
|
}
|
|
|
|
public Signer getSignerByURI(URI uri) {
|
|
return computeSignerByURI(uri, this.signerRegionOverride, true);
|
|
}
|
|
|
|
public final Signer computeSignerByURI(URI uri, String str, boolean z) {
|
|
if (uri == null) {
|
|
throw new IllegalArgumentException("Endpoint is not set. Use setEndpoint to set an endpoint before performing any request.");
|
|
}
|
|
String serviceNameIntern = getServiceNameIntern();
|
|
return computeSignerByServiceRegion(serviceNameIntern, AwsHostNameUtils.parseRegionName(uri.getHost(), serviceNameIntern), str, z);
|
|
}
|
|
|
|
public final Signer computeSignerByServiceRegion(String str, String str2, String str3, boolean z) {
|
|
Signer signerByTypeAndService;
|
|
String signerOverride = this.clientConfiguration.getSignerOverride();
|
|
if (signerOverride == null) {
|
|
signerByTypeAndService = SignerFactory.getSigner(str, str2);
|
|
} else {
|
|
signerByTypeAndService = SignerFactory.getSignerByTypeAndService(signerOverride, str);
|
|
}
|
|
if (signerByTypeAndService instanceof RegionAwareSigner) {
|
|
RegionAwareSigner regionAwareSigner = (RegionAwareSigner) signerByTypeAndService;
|
|
if (str3 != null) {
|
|
regionAwareSigner.setRegionName(str3);
|
|
} else if (str2 != null && z) {
|
|
regionAwareSigner.setRegionName(str2);
|
|
}
|
|
}
|
|
synchronized (this) {
|
|
this.region = Region.getRegion(str2);
|
|
}
|
|
return signerByTypeAndService;
|
|
}
|
|
|
|
public void setRegion(Region region) {
|
|
String format;
|
|
if (region == null) {
|
|
throw new IllegalArgumentException("No region provided");
|
|
}
|
|
String serviceNameIntern = getServiceNameIntern();
|
|
if (region.isServiceSupported(serviceNameIntern)) {
|
|
format = region.getServiceEndpoint(serviceNameIntern);
|
|
int indexOf = format.indexOf("://");
|
|
if (indexOf >= 0) {
|
|
format = format.substring(indexOf + 3);
|
|
}
|
|
} else {
|
|
format = String.format("%s.%s.%s", getEndpointPrefix(), region.getName(), region.getDomain());
|
|
}
|
|
URI uri = toURI(format);
|
|
Signer computeSignerByServiceRegion = computeSignerByServiceRegion(serviceNameIntern, region.getName(), this.signerRegionOverride, false);
|
|
synchronized (this) {
|
|
this.endpoint = uri;
|
|
this.signer = computeSignerByServiceRegion;
|
|
}
|
|
}
|
|
|
|
public Regions getRegions() {
|
|
Regions fromName;
|
|
synchronized (this) {
|
|
fromName = Regions.fromName(this.region.getName());
|
|
}
|
|
return fromName;
|
|
}
|
|
|
|
public ExecutionContext createExecutionContext(AmazonWebServiceRequest amazonWebServiceRequest) {
|
|
return new ExecutionContext(this.requestHandler2s, isRequestMetricsEnabled(amazonWebServiceRequest) || isProfilingEnabled(), this);
|
|
}
|
|
|
|
public static boolean isProfilingEnabled() {
|
|
return System.getProperty("com.amazonaws.sdk.enableRuntimeProfiling") != null;
|
|
}
|
|
|
|
public final boolean isRequestMetricsEnabled(AmazonWebServiceRequest amazonWebServiceRequest) {
|
|
RequestMetricCollector requestMetricCollector = amazonWebServiceRequest.getRequestMetricCollector();
|
|
if (requestMetricCollector == null || !requestMetricCollector.isEnabled()) {
|
|
return isRMCEnabledAtClientOrSdkLevel();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final boolean isRMCEnabledAtClientOrSdkLevel() {
|
|
RequestMetricCollector requestMetricCollector = requestMetricCollector();
|
|
return requestMetricCollector != null && requestMetricCollector.isEnabled();
|
|
}
|
|
|
|
public RequestMetricCollector getRequestMetricsCollector() {
|
|
return this.client.getRequestMetricCollector();
|
|
}
|
|
|
|
public RequestMetricCollector requestMetricCollector() {
|
|
RequestMetricCollector requestMetricCollector = this.client.getRequestMetricCollector();
|
|
return requestMetricCollector == null ? AwsSdkMetrics.getRequestMetricCollector() : requestMetricCollector;
|
|
}
|
|
|
|
public final RequestMetricCollector findRequestMetricCollector(Request request) {
|
|
RequestMetricCollector requestMetricCollector = request.getOriginalRequest().getRequestMetricCollector();
|
|
if (requestMetricCollector != null) {
|
|
return requestMetricCollector;
|
|
}
|
|
RequestMetricCollector requestMetricsCollector = getRequestMetricsCollector();
|
|
return requestMetricsCollector == null ? AwsSdkMetrics.getRequestMetricCollector() : requestMetricsCollector;
|
|
}
|
|
|
|
public final void endClientExecution(AWSRequestMetrics aWSRequestMetrics, Request request, Response response) {
|
|
endClientExecution(aWSRequestMetrics, request, response, false);
|
|
}
|
|
|
|
public final void endClientExecution(AWSRequestMetrics aWSRequestMetrics, Request request, Response response, boolean z) {
|
|
if (request != null) {
|
|
aWSRequestMetrics.endEvent(AWSRequestMetrics.Field.ClientExecuteTime);
|
|
aWSRequestMetrics.getTimingInfo().endTiming();
|
|
findRequestMetricCollector(request).collectMetrics(request, response);
|
|
}
|
|
if (z) {
|
|
aWSRequestMetrics.log();
|
|
}
|
|
}
|
|
|
|
public String getServiceNameIntern() {
|
|
if (this.serviceName == null) {
|
|
synchronized (this) {
|
|
try {
|
|
if (this.serviceName == null) {
|
|
this.serviceName = computeServiceName();
|
|
return this.serviceName;
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
return this.serviceName;
|
|
}
|
|
|
|
public final String computeServiceName() {
|
|
int i;
|
|
String simpleName = Classes.childClassOf(AmazonWebServiceClient.class, this).getSimpleName();
|
|
String serviceName = ServiceNameFactory.getServiceName(simpleName);
|
|
if (serviceName != null) {
|
|
return serviceName;
|
|
}
|
|
int indexOf = simpleName.indexOf("JavaClient");
|
|
if (indexOf == -1 && (indexOf = simpleName.indexOf("Client")) == -1) {
|
|
throw new IllegalStateException("Unrecognized suffix for the AWS http client class name " + simpleName);
|
|
}
|
|
int indexOf2 = simpleName.indexOf("Amazon");
|
|
if (indexOf2 == -1) {
|
|
indexOf2 = simpleName.indexOf("AWS");
|
|
if (indexOf2 == -1) {
|
|
throw new IllegalStateException("Unrecognized prefix for the AWS http client class name " + simpleName);
|
|
}
|
|
i = 3;
|
|
} else {
|
|
i = 6;
|
|
}
|
|
if (indexOf2 >= indexOf) {
|
|
throw new IllegalStateException("Unrecognized AWS http client class name " + simpleName);
|
|
}
|
|
return StringUtils.lowerCase(simpleName.substring(indexOf2 + i, indexOf));
|
|
}
|
|
}
|