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

Commit 1ffe7b8

Browse files
author
zhangzhx
committed
AWS Toolkit for Eclipse: v201801042359 Release.
1 parent 74a40f8 commit 1ffe7b8

File tree

20 files changed

+400
-31
lines changed

20 files changed

+400
-31
lines changed

CHANGELOG.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"current": [
3+
"* **Merge Pull Request #93.**",
4+
"* **Resolve Issues: #87, #94, #95, #96, #97.**"
5+
],
6+
"v201712181839": [
37
"**Support AWS SAM Local to locally debug Lambda functions and AWS Gateway**",
48
"",
59
"* Debug Lambda Function",

bundles/com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/AWSClientFactory.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.amazonaws.AmazonWebServiceClient;
3131
import com.amazonaws.ClientConfiguration;
3232
import com.amazonaws.auth.AWSCredentials;
33+
import com.amazonaws.auth.AWSCredentialsProvider;
3334
import com.amazonaws.auth.AWSStaticCredentialsProvider;
3435
import com.amazonaws.auth.AnonymousAWSCredentials;
3536
import com.amazonaws.auth.BasicAWSCredentials;
@@ -127,6 +128,8 @@ public class AWSClientFactory {
127128
*/
128129
private AccountInfo accountInfo;
129130

131+
private AWSCredentialsProvider credentialsProviderOverride;
132+
130133
/**
131134
* Constructs a client factory that uses the given account identifier to
132135
* retrieve its credentials.
@@ -142,6 +145,15 @@ public AWSClientFactory(String accountId) {
142145
plugin.getAccountManager().addAccountInfoChangeListener(this::onAccountInfoChange);
143146
}
144147

148+
/**
149+
* Decoupling AWS Client Factory from AwsToolkitCore for testing purpose only.
150+
* @TestOnly
151+
*/
152+
public AWSClientFactory(AWSCredentialsProvider credentialsProvider) {
153+
this.accountId = null;
154+
this.credentialsProviderOverride = credentialsProvider;
155+
}
156+
145157
private void onProxyChange(IProxyChangeEvent e) {
146158
onAccountInfoChange();
147159
}
@@ -377,12 +389,12 @@ public AWSCodeCommit getCodeCommitClientByEndpoint(String endpoint) {
377389

378390
public AmazonIdentityManagement getIAMClientByRegion(String regionId) {
379391
return getOrCreateClientByRegion(ServiceAbbreviations.IAM, regionId,
380-
AmazonIdentityManagementClientBuilder.standard(), AmazonIdentityManagement.class);
392+
AmazonIdentityManagementClientBuilder.standard(), AmazonIdentityManagement.class, true);
381393
}
382394

383395
public AmazonCloudFront getCloudFrontClientByRegion(String regionId) {
384396
return getOrCreateClientByRegion(ServiceAbbreviations.CLOUDFRONT, regionId,
385-
AmazonCloudFrontClientBuilder.standard(), AmazonCloudFront.class);
397+
AmazonCloudFrontClientBuilder.standard(), AmazonCloudFront.class, true);
386398
}
387399

388400
/**
@@ -505,22 +517,26 @@ private <T extends AmazonWebServiceClient> T getOrCreateClient(String endpoint,
505517
}
506518

507519
private <T> T getOrCreateClientByRegion(String serviceName, String regionId,
508-
AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, Class<T> clientClass) {
520+
AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, Class<T> clientClass, boolean isGlobalClient) {
509521
Region region = RegionUtils.getRegion(regionId);
510522
if (region == null) {
511523
return null;
512524
}
513-
String endpoint = region.getServiceEndpoint(serviceName);
514525

515526
synchronized (clientClass) {
516527
if ( cachedClients.getClient(regionId, clientClass) == null ) {
517-
cachedClients.cacheClient(regionId, clientClass, createClientByRegion(builder, regionId, endpoint));
528+
cachedClients.cacheClient(regionId, clientClass, createClientByRegion(builder, serviceName, region, isGlobalClient));
518529
}
519530
}
520531

521532
return cachedClients.getClient(regionId, clientClass);
522533
}
523534

535+
private <T> T getOrCreateClientByRegion(String serviceName, String regionId,
536+
AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, Class<T> clientClass) {
537+
return getOrCreateClientByRegion(serviceName, regionId, builder, clientClass, false);
538+
}
539+
524540
/**
525541
* @deprecated for {@link #createClientByRegion(AwsSyncClientBuilder, String, String)}
526542
*/
@@ -569,9 +585,12 @@ private <T extends AmazonWebServiceClient> T createClient(String endpoint, Class
569585

570586
// Low layer method for building a service client by using the client builder.
571587
@SuppressWarnings("unchecked")
572-
private <T> T createClientByRegion(AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder, String region, String endpoint) {
573-
builder.withEndpointConfiguration(new EndpointConfiguration(endpoint, region));
588+
private <T> T createClientByRegion(AwsSyncClientBuilder<? extends AwsSyncClientBuilder, T> builder,
589+
String serviceName, Region region, boolean isGlobalClient) {
590+
String endpoint = region.getServiceEndpoint(serviceName);
591+
String signingRegion = isGlobalClient ? region.getGlobalRegionSigningRegion() : region.getId();
574592
Object client = builder
593+
.withEndpointConfiguration(new EndpointConfiguration(endpoint, signingRegion))
575594
.withCredentials(new AWSStaticCredentialsProvider(getAwsCredentials()))
576595
.withClientConfiguration(createClientConfiguration(endpoint))
577596
.build();
@@ -614,7 +633,9 @@ private <T extends AmazonWebServiceClient> Method lookupSigV4SetEndpointMethod(C
614633
private AWSCredentials getAwsCredentials() {
615634
AWSCredentials credentials = null;
616635

617-
if (accountInfo.isUseSessionToken()) {
636+
if (credentialsProviderOverride != null) {
637+
credentials = credentialsProviderOverride.getCredentials();
638+
} else if (accountInfo.isUseSessionToken()) {
618639
credentials = new BasicSessionCredentials(
619640
accountInfo.getAccessKey(), accountInfo.getSecretKey(),
620641
accountInfo.getSessionToken());

bundles/com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/maven/MavenFactory.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.amazonaws.eclipse.core.maven;
1616

1717
import java.util.List;
18+
import java.util.Optional;
1819
import java.util.Properties;
1920

2021
import org.apache.maven.archetype.catalog.Archetype;
@@ -23,6 +24,7 @@
2324
import org.eclipse.core.resources.IProject;
2425
import org.eclipse.core.runtime.CoreException;
2526
import org.eclipse.core.runtime.IProgressMonitor;
27+
import org.eclipse.jdt.annotation.NonNull;
2628
import org.eclipse.m2e.core.MavenPlugin;
2729
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
2830

@@ -42,12 +44,12 @@ public class MavenFactory {
4244
private static String AWS_JAVA_SDK_GROUP_NAME = "com.amazonaws";
4345
private static String AWS_JAVA_SDK_ARTIFACT_NAME = "aws-java-sdk";
4446
private static String AWS_JAVA_SDK_ARTIFACT_TYPE = "jar";
45-
private static String DEFAULT_AWS_JAVA_SDK_VERSION = "1.11.66";
47+
private static String DEFAULT_AWS_JAVA_SDK_VERSION = "1.11.256";
4648

4749
private static String AWS_JAVA_SDK_BOM_GROUP_NAME = "com.amazonaws";
4850
private static String AWS_JAVA_SDK_BOM_ARTIFACT_NAME = "aws-java-sdk-bom";
4951
private static String AWS_JAVA_SDK_BOM_ARTIFACT_TYPE = "pom";
50-
private static String DEFAULT_AWS_JAVA_SDK_BOM_VERSION = "1.11.66";
52+
private static String DEFAULT_AWS_JAVA_SDK_BOM_VERSION = "1.11.256";
5153

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

155+
@NonNull
153156
public static String getLatestJavaSdkVersion() {
154-
return getLatestArtifactVersion(AWS_JAVA_SDK_GROUP_NAME, AWS_JAVA_SDK_ARTIFACT_NAME);
157+
return Optional.ofNullable(getLatestArtifactVersion(AWS_JAVA_SDK_GROUP_NAME, AWS_JAVA_SDK_ARTIFACT_NAME)).orElse(DEFAULT_AWS_JAVA_SDK_VERSION);
155158
}
156159

157160
private static Dependency getLatestArtifactDependency(String groupId, String artifactId, String scope, String type, String defaultVersion) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.amazonaws.eclipse.core.model;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
20+
/**
21+
* Data model for a widget of List with check box. The data model collects the checked items instead of
22+
* the selected items from the List.
23+
*/
24+
public class MultipleSelectionListDataModel<T> {
25+
private final List<T> selectedList = new ArrayList<>();
26+
27+
public List<T> getSelectedList() {
28+
return selectedList;
29+
}
30+
}

bundles/com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/regions/LocalRegion.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,9 @@ public ImageDescriptor getFlagImageDescriptor() {
135135
public String toString() {
136136
return "Region: Local (localhost) (local)";
137137
}
138+
139+
@Override
140+
public String getRegionRestriction() {
141+
return "IsLocalAccount";
142+
}
138143
}

bundles/com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/regions/Region.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,53 @@ public interface Region {
8787
* Returns the flag's image descriptor.
8888
*/
8989
ImageDescriptor getFlagImageDescriptor();
90+
91+
String getRegionRestriction();
92+
93+
default String getGlobalRegionSigningRegion() {
94+
RegionPartition partition = RegionPartition.fromValue(getRegionRestriction());
95+
if (partition == null) {
96+
return getId();
97+
} else {
98+
return partition.getGlobalSigningRegion();
99+
}
100+
}
101+
102+
public static enum RegionPartition {
103+
US_GOV_CLOUD("IsGovCloudAccount", "us-gov-west-1"),
104+
CHINA_CLOUD("IsChinaAccount", "cn-north-1"),
105+
AWS_CLOUD("IsAwsAccount", "us-east-1")
106+
;
107+
108+
private final String restriction;
109+
private final String globalSigningRegion;
110+
111+
private RegionPartition(String restriction, String globalSigningRegion) {
112+
this.restriction = restriction;
113+
this.globalSigningRegion = globalSigningRegion;
114+
}
115+
public String getRestriction() {
116+
return this.restriction;
117+
}
118+
public String getGlobalSigningRegion() {
119+
return globalSigningRegion;
120+
}
121+
122+
/**
123+
* Find the {@link RegionPartition} by the provided restriction. If the restriction
124+
* is null or empty, return the default AWS_CLOUD; Otherwise, return the corresponding
125+
* {@link RegionPartition} if found in the enum or null if not.
126+
*/
127+
public static RegionPartition fromValue(String restriction) {
128+
if (restriction == null || restriction.isEmpty()) {
129+
return AWS_CLOUD;
130+
}
131+
for (RegionPartition partition : RegionPartition.values()) {
132+
if (partition.getRestriction().equals(restriction)) {
133+
return partition;
134+
}
135+
}
136+
return null;
137+
}
138+
}
90139
}

bundles/com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/regions/RegionImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ class RegionImpl implements Region {
3131
private final String name;
3232
private final String id;
3333
private final String flagIconPath;
34+
private final String restriction;
3435
private final Map<String, String> serviceEndpoints = new HashMap<>();
3536
private final Map<String, Service> servicesByName = new HashMap<>();
3637

3738

38-
public RegionImpl(String name, String id, String flagIconPath) {
39+
public RegionImpl(String name, String id, String flagIconPath, String restriction) {
3940
this.name = name;
4041
this.id = id;
4142
this.flagIconPath = flagIconPath;
43+
this.restriction = restriction;
4244
}
4345

4446
/**
@@ -154,4 +156,9 @@ public boolean equals(Object obj) {
154156
public String toString() {
155157
return "Region: " + name + " (" + id + ")";
156158
}
159+
160+
@Override
161+
public String getRegionRestriction() {
162+
return restriction;
163+
}
157164
}

bundles/com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/regions/RegionMetadataParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class RegionMetadataParser {
4141
private static final String SERVICE_ID_ATTRIBUTE = "serviceId";
4242
private static final String SERVICE_NAME_ATTRIBUTE = "name";
4343
private static final String SIGNER_ATTRIBUTE = "signer";
44+
private static final String RESTRICTIONS = "restrictions";
4445

4546
/**
4647
* Parses the specified input stream and returns a list of the regions
@@ -77,7 +78,8 @@ private Region parseRegionElement(Element regionElement) {
7778
String name = getTagValue(REGION_DISPLAY_NAME_TAG, regionElement);
7879
String id = getTagValue(REGION_SYSTEM_ID_TAG, regionElement);
7980
String flagIcon = getTagValue(FLAG_ICON_TAG, regionElement);
80-
Region region = new RegionImpl(name, id, flagIcon);
81+
String restriction = getTagValue(RESTRICTIONS, regionElement);
82+
Region region = new RegionImpl(name, id, flagIcon, restriction);
8183

8284
NodeList serviceNodes = regionElement.getElementsByTagName(SERVICE_TAG);
8385
for (int i = 0; i < serviceNodes.getLength(); i++) {

0 commit comments

Comments
 (0)