Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
AWS Toolkit for Eclipse: v201801042359 Release.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhx committed Jan 5, 2018
1 parent 74a40f8 commit 1ffe7b8
Show file tree
Hide file tree
Showing 20 changed files with 400 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"current": [
"* **Merge Pull Request #93.**",
"* **Resolve Issues: #87, #94, #95, #96, #97.**"
],
"v201712181839": [
"**Support AWS SAM Local to locally debug Lambda functions and AWS Gateway**",
"",
"* Debug Lambda Function",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.amazonaws.AmazonWebServiceClient;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
Expand Down Expand Up @@ -127,6 +128,8 @@ public class AWSClientFactory {
*/
private AccountInfo accountInfo;

private AWSCredentialsProvider credentialsProviderOverride;

/**
* Constructs a client factory that uses the given account identifier to
* retrieve its credentials.
Expand All @@ -142,6 +145,15 @@ public AWSClientFactory(String accountId) {
plugin.getAccountManager().addAccountInfoChangeListener(this::onAccountInfoChange);
}

/**
* Decoupling AWS Client Factory from AwsToolkitCore for testing purpose only.
* @TestOnly
*/
public AWSClientFactory(AWSCredentialsProvider credentialsProvider) {
this.accountId = null;
this.credentialsProviderOverride = credentialsProvider;
}

private void onProxyChange(IProxyChangeEvent e) {
onAccountInfoChange();
}
Expand Down Expand Up @@ -377,12 +389,12 @@ public AWSCodeCommit getCodeCommitClientByEndpoint(String endpoint) {

public AmazonIdentityManagement getIAMClientByRegion(String regionId) {
return getOrCreateClientByRegion(ServiceAbbreviations.IAM, regionId,
AmazonIdentityManagementClientBuilder.standard(), AmazonIdentityManagement.class);
AmazonIdentityManagementClientBuilder.standard(), AmazonIdentityManagement.class, true);
}

public AmazonCloudFront getCloudFrontClientByRegion(String regionId) {
return getOrCreateClientByRegion(ServiceAbbreviations.CLOUDFRONT, regionId,
AmazonCloudFrontClientBuilder.standard(), AmazonCloudFront.class);
AmazonCloudFrontClientBuilder.standard(), AmazonCloudFront.class, true);
}

/**
Expand Down Expand Up @@ -505,22 +517,26 @@ private <T extends AmazonWebServiceClient> T getOrCreateClient(String endpoint,
}

private <T> T getOrCreateClientByRegion(String serviceName, String regionId,
AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, Class<T> clientClass) {
AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, Class<T> clientClass, boolean isGlobalClient) {
Region region = RegionUtils.getRegion(regionId);
if (region == null) {
return null;
}
String endpoint = region.getServiceEndpoint(serviceName);

synchronized (clientClass) {
if ( cachedClients.getClient(regionId, clientClass) == null ) {
cachedClients.cacheClient(regionId, clientClass, createClientByRegion(builder, regionId, endpoint));
cachedClients.cacheClient(regionId, clientClass, createClientByRegion(builder, serviceName, region, isGlobalClient));
}
}

return cachedClients.getClient(regionId, clientClass);
}

private <T> T getOrCreateClientByRegion(String serviceName, String regionId,
AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, Class<T> clientClass) {
return getOrCreateClientByRegion(serviceName, regionId, builder, clientClass, false);
}

/**
* @deprecated for {@link #createClientByRegion(AwsSyncClientBuilder, String, String)}
*/
Expand Down Expand Up @@ -569,9 +585,12 @@ private <T extends AmazonWebServiceClient> T createClient(String endpoint, Class

// Low layer method for building a service client by using the client builder.
@SuppressWarnings("unchecked")
private <T> T createClientByRegion(AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, String region, String endpoint) {
builder.withEndpointConfiguration(new EndpointConfiguration(endpoint, region));
private <T> T createClientByRegion(AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder,
String serviceName, Region region, boolean isGlobalClient) {
String endpoint = region.getServiceEndpoint(serviceName);
String signingRegion = isGlobalClient ? region.getGlobalRegionSigningRegion() : region.getId();
Object client = builder
.withEndpointConfiguration(new EndpointConfiguration(endpoint, signingRegion))
.withCredentials(new AWSStaticCredentialsProvider(getAwsCredentials()))
.withClientConfiguration(createClientConfiguration(endpoint))
.build();
Expand Down Expand Up @@ -614,7 +633,9 @@ private <T extends AmazonWebServiceClient> Method lookupSigV4SetEndpointMethod(C
private AWSCredentials getAwsCredentials() {
AWSCredentials credentials = null;

if (accountInfo.isUseSessionToken()) {
if (credentialsProviderOverride != null) {
credentials = credentialsProviderOverride.getCredentials();
} else if (accountInfo.isUseSessionToken()) {
credentials = new BasicSessionCredentials(
accountInfo.getAccessKey(), accountInfo.getSecretKey(),
accountInfo.getSessionToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.amazonaws.eclipse.core.maven;

import java.util.List;
import java.util.Optional;
import java.util.Properties;

import org.apache.maven.archetype.catalog.Archetype;
Expand All @@ -23,6 +24,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;

Expand All @@ -42,12 +44,12 @@ public class MavenFactory {
private static String AWS_JAVA_SDK_GROUP_NAME = "com.amazonaws";
private static String AWS_JAVA_SDK_ARTIFACT_NAME = "aws-java-sdk";
private static String AWS_JAVA_SDK_ARTIFACT_TYPE = "jar";
private static String DEFAULT_AWS_JAVA_SDK_VERSION = "1.11.66";
private static String DEFAULT_AWS_JAVA_SDK_VERSION = "1.11.256";

private static String AWS_JAVA_SDK_BOM_GROUP_NAME = "com.amazonaws";
private static String AWS_JAVA_SDK_BOM_ARTIFACT_NAME = "aws-java-sdk-bom";
private static String AWS_JAVA_SDK_BOM_ARTIFACT_TYPE = "pom";
private static String DEFAULT_AWS_JAVA_SDK_BOM_VERSION = "1.11.66";
private static String DEFAULT_AWS_JAVA_SDK_BOM_VERSION = "1.11.256";

private static String AMAZON_KINESIS_CLIENT_GROUP_NAME = "com.amazonaws";
private static String AMAZON_KINESIS_CLIENT_ARTIFACT_NAME = "amazon-kinesis-client";
Expand Down Expand Up @@ -150,8 +152,9 @@ public static Dependency getJunitDependency() {
return getJunitDependency(DEFAULT_JUNIT_VERSION, "test");
}

@NonNull
public static String getLatestJavaSdkVersion() {
return getLatestArtifactVersion(AWS_JAVA_SDK_GROUP_NAME, AWS_JAVA_SDK_ARTIFACT_NAME);
return Optional.ofNullable(getLatestArtifactVersion(AWS_JAVA_SDK_GROUP_NAME, AWS_JAVA_SDK_ARTIFACT_NAME)).orElse(DEFAULT_AWS_JAVA_SDK_VERSION);
}

private static Dependency getLatestArtifactDependency(String groupId, String artifactId, String scope, String type, String defaultVersion) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.amazonaws.eclipse.core.model;

import java.util.ArrayList;
import java.util.List;

/**
* Data model for a widget of List with check box. The data model collects the checked items instead of
* the selected items from the List.
*/
public class MultipleSelectionListDataModel<T> {
private final List<T> selectedList = new ArrayList<>();

public List<T> getSelectedList() {
return selectedList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,9 @@ public ImageDescriptor getFlagImageDescriptor() {
public String toString() {
return "Region: Local (localhost) (local)";
}

@Override
public String getRegionRestriction() {
return "IsLocalAccount";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,53 @@ public interface Region {
* Returns the flag's image descriptor.
*/
ImageDescriptor getFlagImageDescriptor();

String getRegionRestriction();

default String getGlobalRegionSigningRegion() {
RegionPartition partition = RegionPartition.fromValue(getRegionRestriction());
if (partition == null) {
return getId();
} else {
return partition.getGlobalSigningRegion();
}
}

public static enum RegionPartition {
US_GOV_CLOUD("IsGovCloudAccount", "us-gov-west-1"),
CHINA_CLOUD("IsChinaAccount", "cn-north-1"),
AWS_CLOUD("IsAwsAccount", "us-east-1")
;

private final String restriction;
private final String globalSigningRegion;

private RegionPartition(String restriction, String globalSigningRegion) {
this.restriction = restriction;
this.globalSigningRegion = globalSigningRegion;
}
public String getRestriction() {
return this.restriction;
}
public String getGlobalSigningRegion() {
return globalSigningRegion;
}

/**
* Find the {@link RegionPartition} by the provided restriction. If the restriction
* is null or empty, return the default AWS_CLOUD; Otherwise, return the corresponding
* {@link RegionPartition} if found in the enum or null if not.
*/
public static RegionPartition fromValue(String restriction) {
if (restriction == null || restriction.isEmpty()) {
return AWS_CLOUD;
}
for (RegionPartition partition : RegionPartition.values()) {
if (partition.getRestriction().equals(restriction)) {
return partition;
}
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ class RegionImpl implements Region {
private final String name;
private final String id;
private final String flagIconPath;
private final String restriction;
private final Map<String, String> serviceEndpoints = new HashMap<>();
private final Map<String, Service> servicesByName = new HashMap<>();


public RegionImpl(String name, String id, String flagIconPath) {
public RegionImpl(String name, String id, String flagIconPath, String restriction) {
this.name = name;
this.id = id;
this.flagIconPath = flagIconPath;
this.restriction = restriction;
}

/**
Expand Down Expand Up @@ -154,4 +156,9 @@ public boolean equals(Object obj) {
public String toString() {
return "Region: " + name + " (" + id + ")";
}

@Override
public String getRegionRestriction() {
return restriction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class RegionMetadataParser {
private static final String SERVICE_ID_ATTRIBUTE = "serviceId";
private static final String SERVICE_NAME_ATTRIBUTE = "name";
private static final String SIGNER_ATTRIBUTE = "signer";
private static final String RESTRICTIONS = "restrictions";

/**
* Parses the specified input stream and returns a list of the regions
Expand Down Expand Up @@ -77,7 +78,8 @@ private Region parseRegionElement(Element regionElement) {
String name = getTagValue(REGION_DISPLAY_NAME_TAG, regionElement);
String id = getTagValue(REGION_SYSTEM_ID_TAG, regionElement);
String flagIcon = getTagValue(FLAG_ICON_TAG, regionElement);
Region region = new RegionImpl(name, id, flagIcon);
String restriction = getTagValue(RESTRICTIONS, regionElement);
Region region = new RegionImpl(name, id, flagIcon, restriction);

NodeList serviceNodes = regionElement.getElementsByTagName(SERVICE_TAG);
for (int i = 0; i < serviceNodes.getLength(); i++) {
Expand Down
Loading

0 comments on commit 1ffe7b8

Please sign in to comment.