diff --git a/sources/.idea/dictionaries/naveronics.xml b/sources/.idea/dictionaries/naveronics.xml
index 86e84a3..b1cf4fa 100644
--- a/sources/.idea/dictionaries/naveronics.xml
+++ b/sources/.idea/dictionaries/naveronics.xml
@@ -2,6 +2,8 @@
drago
+ mumbai
+ ningxia
\ No newline at end of file
diff --git a/sources/.idea/misc.xml b/sources/.idea/misc.xml
index 95f496d..246fc44 100644
--- a/sources/.idea/misc.xml
+++ b/sources/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/sources/.idea/workspace.xml b/sources/.idea/workspace.xml
index b8c7e63..1015d51 100644
--- a/sources/.idea/workspace.xml
+++ b/sources/.idea/workspace.xml
@@ -1,20 +1,30 @@
+
+
+
+
+
-
+
+
-
-
+
+
+
+
+
-
-
+
+
-
+
-
+
+
@@ -43,46 +53,59 @@
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
@@ -94,109 +117,109 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
+
-
+
-
-
+
+
-
-
+
+
+
+
+
+
@@ -211,11 +234,6 @@
- TOPIC
- myListeners
- myProjectsTreeDispatcher
- MavenProjectsManager.getInstance
- myState.myPackaging
cloud
awsLogStreamList
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM
@@ -234,13 +252,18 @@
clear
updateProxySettingsButton
AwsLogRequestMode
- last
sort
java
Code file is invalid of empty
jar
Jar
Java8
+ catch
+ Loading of a function list failed
+ setLas
+ last
+ getLas
+ region
@@ -262,35 +285,38 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -320,11 +346,10 @@
-
-
+
-
-
+
+
@@ -334,7 +359,7 @@
-
+
@@ -342,11 +367,6 @@
-
-
-
-
-
@@ -358,57 +378,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -420,21 +389,12 @@
-
-
-
-
-
-
-
-
-
-
+
@@ -446,15 +406,15 @@
-
-
-
+
+
+
-
+
-
+
@@ -477,7 +437,7 @@
-
+
@@ -490,6 +450,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -506,10 +484,11 @@
-
+
+
@@ -524,6 +503,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -590,7 +588,24 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1520437214334
@@ -718,11 +733,35 @@
1532289932025
-
+
+ 1533371852129
+
+
+
+ 1533371852129
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -734,10 +773,10 @@
-
+
-
+
@@ -746,17 +785,17 @@
-
-
-
+
+
+
-
-
-
-
+
+
+
+
@@ -766,6 +805,7 @@
+
@@ -829,7 +869,9 @@
-
+
+
+
@@ -841,65 +883,95 @@
file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java
- 329
+ 358
+
+ file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
+ 166
+
+
+
+
+ file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
+ 195
+
+
+
+
+ file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
+ 196
+
+
+
+
+ file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
+ 198
+
+
+
+
+ file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/models/RoleConnectorModel.java
+ 32
+
+
+
+
+ file://$PROJECT_DIR$/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java
+ 432
+
+
+
- ((ArchivePackagingElement) packagingElement).getName()
+ credentialsProvider.getCredentials().getAWSSecretKey()
JAVA
- com.intellij.packaging.impl.elements.ArchivePackagingElement
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren().get(0)
+ credentialsProvider.getCredentials()
JAVA
- com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren().get(0).toString()
+ credentialsProvider.profileName
JAVA
- com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren().get(0).myType
+ credentialsProvider
JAVA
- com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren()
+ basicProfile.getProfileName()
JAVA
- com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren().contains("zip")
+ getLastSelectedCredentialProfileName()
JAVA
- com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement()
+ ((ArchivePackagingElement) packagingElement).getName()
JAVA
- com.intellij.packaging.impl.artifacts.ArtifactImpl
+ com.intellij.packaging.impl.elements.ArchivePackagingElement
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getName()
+ ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren().get(0)
JAVA
com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
- ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getOutputFile()
+ ((ArtifactImpl) ((ArrayList) artifactsByType).get(0)).getRootElement().getChildren().get(0).toString()
JAVA
com.intellij.packaging.impl.artifacts.ArtifactImpl
EXPRESSION
@@ -907,350 +979,374 @@
-
-
-
-
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
-
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
@@ -1264,7 +1360,7 @@
@@ -1277,7 +1373,7 @@
-
+
@@ -1296,7 +1392,7 @@
- IntelliJ IDEA IU-182.3684.101
+ IntelliJ IDEA IU-182.4129.33
@@ -1313,6 +1409,7 @@
+
@@ -1320,11 +1417,11 @@
- com.amazonaws:aws-java-sdk-iam:1.11.348
+ com.amazonaws:aws-java-sdk-lambda:1.11.348
-
+
diff --git a/sources/resources/META-INF/plugin.xml b/sources/resources/META-INF/plugin.xml
index 2879c5a..b3b1025 100644
--- a/sources/resources/META-INF/plugin.xml
+++ b/sources/resources/META-INF/plugin.xml
@@ -1,7 +1,7 @@
io.github.satr.idea.plugin.connector.la
Connector for AWS Lambda
- 1.7.RC2
+ 1.7.RC3
github.com/satr
+ 1.7.RC3
+ Fixed an issue with not loading functions when default profile does not exist.
1.7.RC2
Added basic support for uploading Node.js function with zip-archived artifact.
1.7.RC1
diff --git a/sources/src/io/github/satr/common/JsonHelper.java b/sources/src/io/github/satr/common/JsonHelper.java
index f26daa2..530bd96 100644
--- a/sources/src/io/github/satr/common/JsonHelper.java
+++ b/sources/src/io/github/satr/common/JsonHelper.java
@@ -12,14 +12,15 @@ public class JsonHelper {
private final String RESULT_KEY = "result";
public OperationValueResult Reformat(String jsonText) {
- OperationValueResultImpl valueResult = new OperationValueResultImpl<>();
+ OperationValueResultImpl result = new OperationValueResultImpl<>();
scriptEngine.put(VALUE_FORMAT, jsonText);
try {
scriptEngine.eval(SCRIPT_PARAMS);
- valueResult.setValue((String)scriptEngine.get(RESULT_KEY));
+ result.setValue((String)scriptEngine.get(RESULT_KEY));
} catch (ScriptException e) {
- valueResult.addError(e.getMessage());
+ e.printStackTrace();
+ result.addError(e.getMessage());
}
- return valueResult;
+ return result;
}
}
diff --git a/sources/src/io/github/satr/common/OperationResult.java b/sources/src/io/github/satr/common/OperationResult.java
index 60716b4..11e067c 100644
--- a/sources/src/io/github/satr/common/OperationResult.java
+++ b/sources/src/io/github/satr/common/OperationResult.java
@@ -4,11 +4,13 @@ public interface OperationResult {
void addInfo(String format, Object... args);
void addWarning(String format, Object... arg);
void addError(String format, Object... args);
+ void addDebug(String format, Object... args);
boolean failed();
boolean success();
boolean hasInfo();
boolean hasWarnings();
boolean hasErrors();
+ String getDebugAsString();
String getErrorAsString();
String getWarningsAsString();
String getInfoAsString();
diff --git a/sources/src/io/github/satr/common/OperationResultImpl.java b/sources/src/io/github/satr/common/OperationResultImpl.java
index ba47ce9..fecf6d7 100644
--- a/sources/src/io/github/satr/common/OperationResultImpl.java
+++ b/sources/src/io/github/satr/common/OperationResultImpl.java
@@ -7,6 +7,7 @@
import java.util.List;
public class OperationResultImpl implements OperationResult {
+ private final List debugMessages = new ArrayList<>();
private final List errorMessages = new ArrayList<>();
private final List warningMessages = new ArrayList<>();
private final List infoMessages = new ArrayList<>();
@@ -21,6 +22,11 @@ public void addError(String format, Object... args) {
errorMessages.add(String.format(format, args));
}
+ @Override
+ public void addDebug(String format, Object... args) {
+ debugMessages.add(String.format(format, args));
+ }
+
@Override
public void addWarning(String format, Object... args) {
warningMessages.add(String.format(format, args));
@@ -56,6 +62,11 @@ public String getErrorAsString() {
return join(errorMessages);
}
+ @Override
+ public String getDebugAsString() {
+ return join(debugMessages);
+ }
+
@Override
public String getWarningsAsString() {
return join(warningMessages);
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/entities/CredentialProfileEntity.java b/sources/src/io/github/satr/idea/plugin/connector/la/entities/CredentialProfileEntity.java
index 4593d31..0e3f0f2 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/entities/CredentialProfileEntity.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/entities/CredentialProfileEntity.java
@@ -24,6 +24,6 @@ public BasicProfile getBasicProfile() {
@Override
public String toString() {
String regionName = getBasicProfile().getRegion();
- return String.format("%s (%s)", getName(), isEmpty(regionName) ? "no region" : regionName);
+ return String.format("%s (%s)", getName(), isEmpty(regionName) ? "no regionName" : regionName);
}
}
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/models/AbstractConnectorModel.java b/sources/src/io/github/satr/idea/plugin/connector/la/models/AbstractConnectorModel.java
index a9fd846..d017cf9 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/models/AbstractConnectorModel.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/models/AbstractConnectorModel.java
@@ -1,75 +1,187 @@
package io.github.satr.idea.plugin.connector.la.models;
import com.amazonaws.ClientConfiguration;
+import com.amazonaws.SdkClientException;
+import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
-import com.amazonaws.auth.profile.ProfileCredentialsProvider;
-import com.amazonaws.auth.profile.ProfilesConfigFile;
+import com.amazonaws.auth.profile.internal.AllProfiles;
+import com.amazonaws.auth.profile.internal.BasicProfile;
+import com.amazonaws.auth.profile.internal.BasicProfileConfigLoader;
+import com.amazonaws.auth.profile.internal.ProfileStaticCredentialsProvider;
import com.amazonaws.profile.path.AwsProfileFileLocationProvider;
-import com.amazonaws.regions.Regions;
import com.intellij.util.net.HttpConfigurable;
+import io.github.satr.common.Logger;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.apache.http.util.TextUtils.isEmpty;
public abstract class AbstractConnectorModel {
- protected final Regions region;
+ protected String regionName;
protected String proxyDetails = "Unknown";
protected String credentialProfileName;
+ private Logger logger;
- public AbstractConnectorModel(Regions region, String credentialProfileName) {
- this.region = region;
+ public AbstractConnectorModel(String regionName, String credentialProfileName, Logger logger) {
+ this.regionName = regionName;
this.credentialProfileName = credentialProfileName;
+ this.logger = logger;
+ }
+
+ protected Logger getLogger() {
+ return logger;
}
protected ClientConfiguration getClientConfiguration() {
- HttpConfigurable httpConfigurable = HttpConfigurable.getInstance();
- ClientConfiguration clientConfiguration = new ClientConfiguration();
- boolean useProxyAuto = httpConfigurable.USE_PROXY_PAC;
- if (useProxyAuto) {
- proxyDetails = "Auto";
- } else if (!httpConfigurable.USE_HTTP_PROXY) {
- proxyDetails = "Not used";
+ try {
+ HttpConfigurable httpConfigurable = HttpConfigurable.getInstance();
+ ClientConfiguration clientConfiguration = new ClientConfiguration();
+ boolean useProxyAuto = httpConfigurable.USE_PROXY_PAC;
+ if (useProxyAuto) {
+ proxyDetails = "Auto";
+ } else if (!httpConfigurable.USE_HTTP_PROXY) {
+ proxyDetails = "Not used";
+ return clientConfiguration;
+ }
+ String proxyHost = httpConfigurable.PROXY_HOST;
+ int proxyPort = httpConfigurable.PROXY_PORT;
+ clientConfiguration = clientConfiguration.withProxyHost(proxyHost)
+ .withProxyPort(proxyPort);
+ if (!useProxyAuto) {
+ proxyDetails = String.format("%s:%s", proxyHost, proxyPort);
+ }
+
+ if (httpConfigurable.PROXY_AUTHENTICATION) {
+ String proxyLogin = httpConfigurable.getProxyLogin();
+ clientConfiguration = clientConfiguration.withProxyPassword(httpConfigurable.getPlainProxyPassword())
+ .withProxyUsername(proxyLogin);
+ }
return clientConfiguration;
+ } catch (Exception e) {
+ e.printStackTrace();
+ getLogger().logError("Getting od the client configuration failed: %s", e.getMessage());
}
- String proxyHost = httpConfigurable.PROXY_HOST;
- int proxyPort = httpConfigurable.PROXY_PORT;
- clientConfiguration = clientConfiguration.withProxyHost(proxyHost)
- .withProxyPort(proxyPort);
- if (!useProxyAuto) {
- proxyDetails = String.format("%s:%s", proxyHost, proxyPort);
+ return null;
+ }
+
+ protected AWSCredentialsProvider getCredentialsProvider() {
+ if (isEmpty(credentialProfileName)) {
+ getLogger().logDebug("Cannot get a profile for an empty name");
+ return tryDefaultAwsCredentialsProviderChain();
+ }
+ if (!validateCredentialProfilesExist()) {
+ getLogger().logError("Cannot find any credentials profiles. Please create at least one.");
+ return tryDefaultAwsCredentialsProviderChain();
}
- if (httpConfigurable.PROXY_AUTHENTICATION) {
- String proxyLogin = httpConfigurable.getProxyLogin();
- clientConfiguration = clientConfiguration.withProxyPassword(httpConfigurable.getPlainProxyPassword())
- .withProxyUsername(proxyLogin);
+ ProfileStaticCredentialsProvider profileCredentialsProvider = null;
+ AllProfiles allBasicProfiles = loadProfilesWithProperties();
+ BasicProfile profile = allBasicProfiles.getProfile(credentialProfileName);
+ if (profile == null) {
+ getLogger().logDebug("Last loaded profile does not exist: \"%s\".", credentialProfileName);
+ } else {
+ getLogger().logDebug("Select the profile \"%s\".", credentialProfileName);
+ profileCredentialsProvider = tryCreateProfileCredentialsProvider(profile);
+ if (profileCredentialsProvider != null) {
+ String profileRegionName = profile.getRegion();
+ if(!isEmpty(profileRegionName)) {
+ getLogger().logDebug("Selected a region from the profile: %s", regionName);
+ regionName = profileRegionName;
+ }
+ return profileCredentialsProvider;
+ }
+ }
+ profileCredentialsProvider = tryGetAlternativeAwsCredentialsProvider(credentialProfileName, allBasicProfiles);
+ if (profileCredentialsProvider != null) {
+ return profileCredentialsProvider;
}
- return clientConfiguration;
+ getLogger().logDebug("No profiles could be selected and used.");
+ return tryDefaultAwsCredentialsProviderChain();
}
- protected AWSCredentialsProvider getCredentialsProvider(String credentialProfileName) {
- return validateCredentialProfile(credentialProfileName)
- ? new ProfileCredentialsProvider(credentialProfileName)
- : DefaultAWSCredentialsProviderChain.getInstance();
+ @Nullable
+ private ProfileStaticCredentialsProvider tryGetAlternativeAwsCredentialsProvider(String skipProfileName, AllProfiles allBasicProfiles) {
+ ProfileStaticCredentialsProvider profileCredentialsProvider;
+ for(BasicProfile alternativeProfile : allBasicProfiles.getProfiles().values()) {
+ if(alternativeProfile.getProfileName().equals(skipProfileName)) {
+ continue; //skip the profile, already checked before
+ }
+ getLogger().logDebug("Try to selected the profile \"%s\".", alternativeProfile.getProfileName());
+ profileCredentialsProvider = tryCreateProfileCredentialsProvider(alternativeProfile);
+ if (profileCredentialsProvider != null) {
+ credentialProfileName = alternativeProfile.getProfileName();
+ String profileRegionName = alternativeProfile.getRegion();
+ if(!isEmpty(profileRegionName)) {
+ getLogger().logDebug("Selected a region from the profile: %s", regionName);
+ regionName = profileRegionName;
+ }
+ return profileCredentialsProvider;
+ }
+ }
+ return null;
}
- private boolean validateCredentialProfile(String credentialProfileName) {
- return !isEmpty(credentialProfileName)
- && validateCredentialProfilesExist()
- && new ProfilesConfigFile().getAllBasicProfiles().containsKey(credentialProfileName);
+ //Load profiles from the file ".aws/credentials" with regions and other properties (if exist) from the file ".aws/config"
+ //Logic has been borrowed from https://github.com/aws/aws-sdk-java/issues/803#issuecomment-374043898
+ //The issue with not loading regions from the file ".aws/config" supposed to be fixed in Java SDK 2.0, which is in "preview" now
+ //Java SDK 2.0 https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/welcome.html
+ private static AllProfiles loadProfilesWithProperties() {
+ final AllProfiles allProfiles = new AllProfiles(Stream.concat(
+ BasicProfileConfigLoader.INSTANCE.loadProfiles(
+ AwsProfileFileLocationProvider.DEFAULT_CONFIG_LOCATION_PROVIDER.getLocation()).getProfiles().values().stream(),
+ BasicProfileConfigLoader.INSTANCE.loadProfiles(
+ AwsProfileFileLocationProvider.DEFAULT_CREDENTIALS_LOCATION_PROVIDER.getLocation()).getProfiles().values().stream())
+ .map(profile -> new BasicProfile(profile.getProfileName().replaceFirst("^profile ", ""), profile.getProperties()))
+ .collect(Collectors.toMap(profile -> profile.getProfileName(), profile -> profile,
+ (left, right) -> {
+ final Map properties = new HashMap<>(left.getProperties());
+ properties.putAll(right.getProperties());
+ return new BasicProfile(left.getProfileName(), properties);
+ })));
+
+ return allProfiles;
}
- protected boolean validateCredentialProfilesExist() {
- return AwsProfileFileLocationProvider.DEFAULT_CREDENTIALS_LOCATION_PROVIDER.getLocation() != null;
+
+ @Nullable
+ private ProfileStaticCredentialsProvider tryCreateProfileCredentialsProvider(BasicProfile profile) {
+ try {
+ return new ProfileStaticCredentialsProvider(profile);
+ } catch (SdkClientException e) {
+ e.printStackTrace();
+ getLogger().logError("Cannot load the profile \"%s\": %s", profile.getProfileName(), e.getMessage());
+ return null;
+ }
+ }
+
+ private AWSCredentialsProvider tryDefaultAwsCredentialsProviderChain() {
+ getLogger().logDebug("Trying to use default AWS credentials provider chain:");
+ DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = DefaultAWSCredentialsProviderChain.getInstance();
+ AWSCredentials credentials = defaultAWSCredentialsProviderChain.getCredentials();
+ if (!isEmpty(credentials.getAWSSecretKey()) && !isEmpty(credentials.getAWSAccessKeyId())) {
+ getLogger().logError("Found credentials for default AWS credentials provider chain.");
+ } else {
+ getLogger().logError("Invalid or not defined AWSSecretKey or AWSAccessKeyId for default AWS credentials provider chain.");
+ }
+ return defaultAWSCredentialsProviderChain;
}
- public Regions getRegion() {
- return region;
+ protected boolean validateCredentialProfilesExist() {
+ return AwsProfileFileLocationProvider.DEFAULT_CREDENTIALS_LOCATION_PROVIDER.getLocation() != null;
}
public String getCredentialProfileName() {
return credentialProfileName;
}
+ public String getRegionName() {
+ return this.regionName;
+ }
+
public abstract void shutdown();
}
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java b/sources/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
index 3f3ead0..afbce32 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/models/FunctionConnectorModel.java
@@ -7,7 +7,6 @@
import com.amazonaws.auth.profile.internal.BasicProfile;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.RegionUtils;
-import com.amazonaws.regions.Regions;
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import com.amazonaws.services.lambda.model.*;
@@ -34,9 +33,9 @@
import static org.apache.http.util.TextUtils.isEmpty;
public class FunctionConnectorModel extends AbstractConnectorModel {
- private final AWSLogs awsLogClient;
- private final int awsLogStreamItemsLimit = 50;
+ private AWSLogs awsLogClient;
private AWSLambda awsLambdaClient;
+ private final int awsLogStreamItemsLimit = 50;
private static final Map regionDescriptions;
static {
@@ -84,6 +83,7 @@ private static Map createRegionDescriptionsMap() {
map.put("ap-southeast-2", "Asia Pacific (Sydney)");
map.put("ca-central-1", "Canada (Central)");
map.put("cn-north-1", "China (Beijing)");
+ map.put("cn-northwest-1", "China (Ningxia)");
map.put("eu-central-1", "EU (Frankfurt)");
map.put("eu-west-1", "EU (Ireland)");
map.put("eu-west-2", "EU (London)");
@@ -94,42 +94,62 @@ private static Map createRegionDescriptionsMap() {
private ArrayList regionEntries;
- public FunctionConnectorModel(Regions region, String credentialProfileName) {
- super(region, credentialProfileName);
- AWSCredentialsProvider credentialsProvider = getCredentialsProvider(credentialProfileName);
- ClientConfiguration clientConfiguration = getClientConfiguration();
- awsLambdaClient = AWSLambdaClientBuilder.standard()
- .withRegion(region)
- .withClientConfiguration(clientConfiguration)
- .withCredentials(credentialsProvider)
- .build();
- awsLogClient = AWSLogsClientBuilder.standard()
- .withRegion(region)
- .withCredentials(credentialsProvider)
- .withClientConfiguration(clientConfiguration)
- .build();
+ public FunctionConnectorModel(String regionName, String credentialProfileName, Logger logger) {
+ super(regionName, credentialProfileName, logger);
+ try {
+ AWSCredentialsProvider credentialsProvider = getCredentialsProvider();
+ ClientConfiguration clientConfiguration = getClientConfiguration();
+ getLogger().logDebug("Build AWS Lambda client.");
+ awsLambdaClient = AWSLambdaClientBuilder.standard()
+ .withRegion(getRegionName())
+ .withClientConfiguration(clientConfiguration)
+ .withCredentials(credentialsProvider)
+ .build();
+ getLogger().logDebug("Build AWS Logs client.");
+ awsLogClient = AWSLogsClientBuilder.standard()
+ .withRegion(getRegionName())
+ .withCredentials(credentialsProvider)
+ .withClientConfiguration(clientConfiguration)
+ .build();
+ getLogger().logDebug("AWS Lambda and Logs clients created.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.logError("Creating function connector failed: %s", e.getMessage());
+ awsLambdaClient = AWSLambdaClientBuilder.standard().build();
+ awsLogClient = AWSLogsClientBuilder.standard().build();
+ }
}
public OperationValueResult> getFunctions() {
final List entries = new ArrayList<>();
- final OperationValueResult> operationResult = new OperationValueResultImpl>().withValue(entries);
+ final OperationValueResult> result = new OperationValueResultImpl>().withValue(entries);
try {
final ListFunctionsResult functionRequestResult = awsLambdaClient.listFunctions();
for (FunctionConfiguration functionConfiguration : functionRequestResult.getFunctions()) {
entries.add(createFunctionEntity(functionConfiguration));
}
- operationResult.setValue(entries);
+ result.setValue(entries);
} catch (com.amazonaws.services.lambda.model.AWSLambdaException e) {
if ("AccessDeniedException".equals(e.getErrorCode())) {
- operationResult.addError("User has not access to a list of functions.");
+ reportErrorLoadingOfFunctionListFailed(result, e, "User has not access to a list of functions.");
} else {
- operationResult.addError(e.getMessage());
+ reportErrorLoadingOfFunctionListFailed(result, e);
}
} catch (Exception e) {
- e.printStackTrace();
+ reportErrorLoadingOfFunctionListFailed(result, e);
}
- return operationResult;
+ return result;
+ }
+
+ private void reportErrorLoadingOfFunctionListFailed(OperationResult result, Exception e) {
+ reportErrorLoadingOfFunctionListFailed(result, e, "");
+ }
+
+ public void reportErrorLoadingOfFunctionListFailed(OperationResult result,
+ Exception e, String additionalMessage) {
+ e.printStackTrace();
+ result.addError("Loading of a function list failed: %s %s", additionalMessage, e.getMessage());
}
@NotNull
@@ -143,10 +163,10 @@ public OperationValueResult updateWithArtifact(final FunctionEnt
public OperationValueResult updateWithArtifact(final FunctionEntity functionEntity, final File file) {
resetLastLogStreamNextToken();
- final OperationValueResultImpl operationResult = new OperationValueResultImpl<>();
- validateLambdaFunctionArtifactFile(file, operationResult);
- if (operationResult.failed())
- return operationResult;
+ final OperationValueResultImpl result = new OperationValueResultImpl<>();
+ validateLambdaFunctionArtifactFile(file, result);
+ if (result.failed())
+ return result;
try {
final String readOnlyAccessFileMode = "r";
@@ -155,19 +175,18 @@ public OperationValueResult updateWithArtifact(final FunctionEnt
return updateFunctionCode(functionEntity, fileChannel);
}
} catch (InvalidParameterValueException e) {
- operationResult.addError("Invalid request parameters: %s", e.getMessage());
+ reportErrorUpdateOfFunctionFailed(result, e,"invalid request parameters");
} catch (ResourceNotFoundException e) {
- operationResult.addError("Function not found.");
+ reportErrorUpdateOfFunctionFailed(result, e,"function not found");
} catch (Exception e) {
- e.printStackTrace();
- operationResult.addError(e.getMessage());
+ reportErrorUpdateOfFunctionFailed(result, e);
}
- return operationResult;
+ return result;
}
private OperationValueResult updateFunctionCode(final FunctionEntity functionEntity, final FileChannel fileChannel) throws IOException {
resetLastLogStreamNextToken();
- final OperationValueResultImpl valueResult = new OperationValueResultImpl<>();
+ final OperationValueResultImpl result = new OperationValueResultImpl<>();
try {
final MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
buffer.load();
@@ -175,12 +194,20 @@ private OperationValueResult updateFunctionCode(final FunctionEn
.withFunctionName(functionEntity.getFunctionName())
.withZipFile(buffer);
final UpdateFunctionCodeResult updateFunctionResult = awsLambdaClient.updateFunctionCode(request);
- valueResult.setValue(new FunctionEntity(updateFunctionResult));
- } catch (IOException e) {
- e.printStackTrace();
- valueResult.addError("Update function error: %s", e.getMessage());
+ result.setValue(new FunctionEntity(updateFunctionResult));
+ } catch (Exception e) {
+ reportErrorUpdateOfFunctionFailed(result, e);
}
- return valueResult;
+ return result;
+ }
+
+ private void reportErrorUpdateOfFunctionFailed(OperationValueResultImpl result, Exception e) {
+ reportErrorUpdateOfFunctionFailed(result, e, "");
+ }
+
+ private void reportErrorUpdateOfFunctionFailed(OperationValueResultImpl result, Exception e, String additionalMessage) {
+ e.printStackTrace();
+ result.addError("Update of the function failed: %s %s", additionalMessage, e.getMessage());
}
public OperationValueResult invokeFunction(final String functionName, final String inputText) {
@@ -205,7 +232,7 @@ public OperationValueResult invokeFunction(final String functionName, fi
operationResult.setValue(rawJson);
} catch (Exception e) {
e.printStackTrace();
- operationResult.addError(e.getMessage());
+ operationResult.addError("Invocation of the function failed: %s", e.getMessage());
}
return operationResult;
}
@@ -214,34 +241,34 @@ public void resetLastLogStreamNextToken() {
lastLogStreamState = null;
}
- private void validateLambdaFunctionArtifactFile(File file, OperationResult operationResult) {
+ private void validateLambdaFunctionArtifactFile(File file, OperationResult result) {
if (!file.exists()) {
- operationResult.addError("Artifact file does not exist.");
+ result.addError("Artifact file does not exist.");
return;
}
try {
if(file.getName().toLowerCase().endsWith(".jar")) {
- validateJarArtifact(file, operationResult);
+ validateJarArtifact(file, result);
} else if(file.getName().toLowerCase().endsWith(".zip")) {
- validateJarArtifact(file, operationResult);
+ validateZipArtifact(file, result);
}
} catch (IOException e) {
e.printStackTrace();
- operationResult.addError(e.getMessage());
+ result.addError("Validation of an artifact file failed: %s", e.getMessage());
}
}
- private void validateJarArtifact(File file, OperationResult operationResult) throws IOException {
+ private void validateJarArtifact(File file, OperationResult result) throws IOException {
final Object entityEnumeration = new JarFile(file).entries();
if (entityEnumeration == null || !((Enumeration) entityEnumeration).hasMoreElements())
- operationResult.addError("The file is not a valid jar-file.");
+ result.addError("The file is not a valid jar-file.");
}
- private void validateZipArtifact(File file, OperationResult operationResult) throws IOException {
+ private void validateZipArtifact(File file, OperationResult result) throws IOException {
final Object entityEnumeration = new ZipFile(file).entries();
if (entityEnumeration == null || !((Enumeration) entityEnumeration).hasMoreElements())
- operationResult.addError("The file is not a valid zip-file.");
+ result.addError("The file is not a valid zip-file.");
}
public List getRegions() {
@@ -258,7 +285,7 @@ public List getRegions() {
return regionEntries;
}
- public OperationValueResult> getCredentialProfiles() {
+ public OperationValueResult> getCredentialProfileEntities() {
OperationValueResult> valueResult = new OperationValueResultImpl<>();
ArrayList credentialProfilesEntries = new ArrayList<>();
valueResult.setValue(credentialProfilesEntries);
@@ -282,9 +309,9 @@ public String getProxyDetails() {
public OperationValueResult getFunctionBy(String name) {
GetFunctionRequest getFunctionRequest = new GetFunctionRequest().withFunctionName(name);
GetFunctionResult function = awsLambdaClient.getFunction(getFunctionRequest);
- OperationValueResultImpl valueResult = new OperationValueResultImpl<>();
- valueResult.setValue(createFunctionEntity(function.getConfiguration()));
- return valueResult;
+ OperationValueResultImpl result = new OperationValueResultImpl<>();
+ result.setValue(createFunctionEntity(function.getConfiguration()));
+ return result;
}
public OperationResult updateConfiguration(FunctionEntity functionEntity) {
@@ -311,12 +338,12 @@ public OperationResult updateConfiguration(FunctionEntity functionEntity) {
public OperationValueResult> getAwsLogStreamsFor(String functionName,
AwsLogRequestMode awsLogRequestMode) {
List awsLogStreamEntities = new ArrayList<>();
- OperationValueResult> operationResult = new OperationValueResultImpl<>();
- operationResult.setValue(awsLogStreamEntities);
+ OperationValueResult> result = new OperationValueResultImpl<>();
+ result.setValue(awsLogStreamEntities);
LogGroup logGroup = getLogGroupForAwsLambdaFunction(functionName);
if(logGroup == null) {
- operationResult.addInfo("Not found log group for the function \"%s\"", functionName);
- return operationResult;
+ result.addInfo("Not found log group for the function \"%s\"", functionName);
+ return result;
}
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest()
.withLogGroupName(logGroup.getLogGroupName())
@@ -340,7 +367,7 @@ public OperationValueResult> getAwsLogStreamsFor(String
awsLogStreamEntities.add(new AwsLogStreamEntity(logGroup.getLogGroupName(), logStream));
}
awsLogStreamEntities.sort(Comparator.comparing(AwsLogStreamEntity::getLastEventTime).reversed());
- return operationResult;
+ return result;
}
public LastLogStreamState getLastLogStreamStateFor(String functionName) {
@@ -351,19 +378,19 @@ public LastLogStreamState getLastLogStreamStateFor(String functionName) {
public OperationValueResult deleteAwsLogStreamsFor(String functionName) {
resetLastLogStreamNextToken();
- OperationValueResult operationResult = new OperationValueResultImpl();
+ OperationValueResult result = new OperationValueResultImpl();
LogGroup logGroup = getLogGroupForAwsLambdaFunction(functionName);
if(logGroup == null) {
- operationResult.addError("Not found log group for the function \"%s\"", functionName);
- return operationResult;
+ result.addError("Not found log group for the function \"%s\"", functionName);
+ return result;
}
DeleteLogGroupResult deleteLogGroupResult = awsLogClient.deleteLogGroup(new DeleteLogGroupRequest(logGroup.getLogGroupName()));
int httpStatusCode = deleteLogGroupResult.getSdkHttpMetadata().getHttpStatusCode();
if (httpStatusCode == HttpStatusCode.OK.getCode()) {
- return operationResult;
+ return result;
}
- operationResult.addError("Operation responded with code %d", httpStatusCode);
- return operationResult;
+ result.addError("Operation responded with code %d", httpStatusCode);
+ return result;
}
private LogGroup getLogGroupForAwsLambdaFunction(String functionName) {
@@ -402,7 +429,7 @@ public void shutdown() {
}
public enum AwsLogRequestMode {
- NewRequest, RequestNextSet
-
+ NewRequest,
+ RequestNextSet
}
}
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/models/ProjectModelImpl.java b/sources/src/io/github/satr/idea/plugin/connector/la/models/ProjectModelImpl.java
index 930689c..2a15327 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/models/ProjectModelImpl.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/models/ProjectModelImpl.java
@@ -68,8 +68,7 @@ private void collectArchivesFromPlainArtifacts(ArrayList artifac
private boolean addArtifactEntity(ArrayList artifactEntries, Artifact artifact) {
CompositePackagingElement> rootElement = artifact.getRootElement();
if(rootElement.getType() == PackagingElementFactoryImpl.ARCHIVE_ELEMENT_TYPE) {
- artifactEntries.add(new ArtifactEntity(artifact));
- return true;
+ artifactEntries.add(new ArtifactEntity(artifact)); return true;
}
for(PackagingElement> packagingElement : rootElement.getChildren()) {
if (packagingElement.getType() != PackagingElementFactoryImpl.ARCHIVE_ELEMENT_TYPE) {
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/models/RoleConnectorModel.java b/sources/src/io/github/satr/idea/plugin/connector/la/models/RoleConnectorModel.java
index 962a2f1..62f326e 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/models/RoleConnectorModel.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/models/RoleConnectorModel.java
@@ -1,12 +1,14 @@
package io.github.satr.idea.plugin.connector.la.models;
-import com.amazonaws.regions.Regions;
import com.amazonaws.services.identitymanagement.AmazonIdentityManagement;
import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder;
import com.amazonaws.services.identitymanagement.model.AmazonIdentityManagementException;
import com.amazonaws.services.identitymanagement.model.ListRolesRequest;
import com.amazonaws.services.identitymanagement.model.ListRolesResult;
import com.amazonaws.services.identitymanagement.model.Role;
+import io.github.satr.common.Logger;
+import io.github.satr.common.OperationResult;
+import io.github.satr.common.OperationResultImpl;
import io.github.satr.idea.plugin.connector.la.entities.RoleEntity;
import java.util.ArrayList;
@@ -21,18 +23,24 @@ public class RoleConnectorModel extends AbstractConnectorModel {
private Map roleEntityMap = new LinkedHashMap<>();
private boolean loaded;
- public RoleConnectorModel(Regions region, String credentialProfileName) {
- super(region, credentialProfileName);
+ public RoleConnectorModel(String regionName, String credentialProfileName, Logger logger) {
+ super(regionName, credentialProfileName, logger);
}
- public void loadRoles() {
- identityManagementClient = AmazonIdentityManagementClientBuilder.standard()
- .withRegion(region)
- .withCredentials(getCredentialsProvider(credentialProfileName))
- .withClientConfiguration(getClientConfiguration())
- .build();
- populateRoleListAndMap(identityManagementClient);
- loaded = true;
+ public OperationResult loadRoles() {
+ OperationResultImpl result = new OperationResultImpl();
+ try {
+ identityManagementClient = AmazonIdentityManagementClientBuilder.standard()
+ .withRegion(getRegionName())
+ .withCredentials(getCredentialsProvider())
+ .withClientConfiguration(getClientConfiguration())
+ .build();
+ populateRoleListAndMap(identityManagementClient, result);
+ loaded = true;
+ } catch (Exception e) {
+ reportErrorLoadingOfRolesFailed(result, e);
+ }
+ return result;
}
@Override
@@ -53,7 +61,7 @@ public List getRoles() {
return roleEntities;
}
- private void populateRoleListAndMap(AmazonIdentityManagement identityManagementClient) {
+ private void populateRoleListAndMap(AmazonIdentityManagement identityManagementClient, OperationResult result) {
roleEntities = new ArrayList<>();
roleEntityMap = new LinkedHashMap<>();
try {
@@ -63,15 +71,23 @@ private void populateRoleListAndMap(AmazonIdentityManagement identityManagementC
for (Role role : roles) {
addRoleToListAndMap(role);
}
+ result.addDebug("Loaded %d roles", roles.size());
} catch (AmazonIdentityManagementException e) {
if ("AccessDenied".equals(e.getErrorCode())) {
- //"User has not access to a list of roles - skip the error.
+ result.addDebug("User has not access to a list of roles");//skip the error
+ } else {
+ reportErrorLoadingOfRolesFailed(result, e);
}
} catch (Exception e) {
- e.printStackTrace();
+ reportErrorLoadingOfRolesFailed(result, e);
}
}
+ private void reportErrorLoadingOfRolesFailed(OperationResult result, Exception e) {
+ e.printStackTrace();
+ result.addError("Loading of roles failed: %s", e.getMessage());
+ }
+
private RoleEntity addRoleToListAndMap(Role role) {
RoleEntity roleEntity = roleEntityMap.get(role.getArn());
if (roleEntity != null) {
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/ui/AbstractConnectorPresenter.java b/sources/src/io/github/satr/idea/plugin/connector/la/ui/AbstractConnectorPresenter.java
index ca00929..fcc3e67 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/ui/AbstractConnectorPresenter.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/ui/AbstractConnectorPresenter.java
@@ -26,41 +26,49 @@ public Logger getLogger() {
protected void shutdownConnectorModel() {
if(functionConnectorModel != null) {
+ getLogger().logDebug("Shutdown function connector");
functionConnectorModel.shutdown();
}
+ functionConnectorModel = null;
+
if(roleConnectorModel != null) {
+ getLogger().logDebug("Shutdown role connector");
roleConnectorModel.shutdown();
}
+ roleConnectorModel = null;
}
@NotNull
- private FunctionConnectorModel createFunctionConnectorModel(Regions region, String profileName) {
- return new FunctionConnectorModel(region, profileName);
+ private FunctionConnectorModel createFunctionConnectorModel(String profileName, String regionName) {
+ return new FunctionConnectorModel(regionName, profileName, getLogger());
}
@NotNull
- private RoleConnectorModel createRoleConnectorModel(Regions region, String profileName) {
- return new RoleConnectorModel(region, profileName);
+ private RoleConnectorModel createRoleConnectorModel(String profileName, String regionName) {
+ return new RoleConnectorModel(regionName, profileName, getLogger());
}
protected FunctionConnectorModel getFunctionConnectorModel() {
if (functionConnectorModel != null) {
return functionConnectorModel;
}
- return functionConnectorModel = createFunctionConnectorModel(getLastSelectedRegion(), getLastSelectedCredentialProfileName());
+ String lastSelectedCredentialProfileName = getLastSelectedCredentialProfileName();
+ functionConnectorModel = createFunctionConnectorModel(lastSelectedCredentialProfileName, getLastSelectedRegion().getName());
+ getConnectorSettings().setLastSelectedCredentialProfile(functionConnectorModel.getCredentialProfileName());
+ return functionConnectorModel;
}
protected RoleConnectorModel getRoleConnectorModel() {
if (roleConnectorModel != null) {
return roleConnectorModel;
}
- return roleConnectorModel = createRoleConnectorModel(getLastSelectedRegion(), getLastSelectedCredentialProfileName());
+ return roleConnectorModel = createRoleConnectorModel(getLastSelectedCredentialProfileName(), getLastSelectedRegion().getName());
}
- protected void reCreateModels(Regions region, String credentialProfile) {
+ protected void reCreateModels(String credentialProfile, String regionName) {
shutdownConnectorModel();
- functionConnectorModel = createFunctionConnectorModel(region, credentialProfile);
- roleConnectorModel = createRoleConnectorModel(region, credentialProfile);
+ functionConnectorModel = createFunctionConnectorModel(credentialProfile, regionName);
+ roleConnectorModel = createRoleConnectorModel(credentialProfile, regionName);
}
public void addLogger(Logger logger) {
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java b/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java
index 87b3814..958db9f 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java
@@ -21,7 +21,6 @@
import static org.apache.http.util.TextUtils.isEmpty;
public class ConnectorPresenterImpl extends AbstractConnectorPresenter implements ConnectorPresenter {
- private final Regions DEFAULT_REGION = Regions.US_EAST_1;
private ConnectorView view;
private List testFunctionInputRecentEntityList = new ArrayList<>();
private boolean autoRefreshAwsLog = false;
@@ -169,7 +168,7 @@ public void shutdown() {
@Override
public void refreshRegionList() {
- getLogger().logDebug("Refresh region list.");
+ getLogger().logDebug("Refresh regionName list.");
view.setRegionList(getFunctionConnectorModel().getRegions(), getLastSelectedRegion());
}
@@ -182,13 +181,41 @@ public void refreshTracingModeList() {
@Override
public void refreshCredentialProfilesList() {
getLogger().logDebug("Refresh credential profile list.");
- OperationValueResult> credentialProfilesResult = getFunctionConnectorModel().getCredentialProfiles();
- List credentialProfiles = credentialProfilesResult.getValue();
- view.setCredentialProfilesList(credentialProfiles, getLastSelectedCredentialProfileName());
- getLogger().logOperationResult(credentialProfilesResult);
+ FunctionConnectorModel functionConnectorModel = getFunctionConnectorModel();
+ OperationValueResult> result = functionConnectorModel.getCredentialProfileEntities();
+ if(result.success()) {
+ List profileEntities = result.getValue();
+ CredentialProfileEntity selectedProfileEntry = getLastSelectedProfileEntry(functionConnectorModel, profileEntities);
+ if (selectedProfileEntry == null) {
+ result.addError("Profile is not selected.");
+ } else {
+ String profileName = selectedProfileEntry.getName();
+ getConnectorSettings().setLastSelectedCredentialProfile(profileName);
+ view.setCredentialProfilesList(profileEntities, profileName);
+ Regions region = tryGetRegionBy(functionConnectorModel.getRegionName());
+ if (region != null) {
+ view.setRegion(region);
+ }
+ }
+ }
+ getLogger().logOperationResult(result);
refreshStatus();
}
+ public CredentialProfileEntity getLastSelectedProfileEntry(FunctionConnectorModel functionConnectorModel, List credentialProfiles) {
+ String lastSelectedCredentialProfileName = getLastSelectedCredentialProfileName();
+ CredentialProfileEntity profileEntry = getProfileEntry(lastSelectedCredentialProfileName, credentialProfiles);
+ return profileEntry != null ? profileEntry : getProfileEntry(functionConnectorModel.getCredentialProfileName(), credentialProfiles);
+ }
+
+ private CredentialProfileEntity getProfileEntry(String profileName, List credentialProfiles) {
+ for(CredentialProfileEntity profileEntity: credentialProfiles) {
+ if(profileEntity.getName().equals(profileName))
+ return profileEntity;
+ }
+ return null;
+ }
+
@Override
public void refreshStatus() {
CredentialProfileEntity credentialProfileEntity = view.getSelectedCredentialProfileEntity();
@@ -207,6 +234,7 @@ public void refreshStatus() {
@Override
public void refreshAll() {
getLogger().logDebug("Refresh all.");
+ shutdownConnectorModel();
refreshArtifactList();
refreshRegionList();
refreshCredentialProfilesList();
@@ -262,7 +290,8 @@ public boolean initializeFunctionRoleList() {
if (roleListLoaded()) {
return false;
}
- getRoleConnectorModel().loadRoles();
+ OperationResult result = getRoleConnectorModel().loadRoles();
+ getLogger().logOperationResult(result);
refreshRolesList();
return true;
}
@@ -405,14 +434,14 @@ public void setRegion(RegionEntity regionEntity) {
if(region == null) {
return;
}
- setRegionAndProfile(region, getConnectorSettings().getLastSelectedCredentialProfile());
+ setRegionAndProfile(getConnectorSettings().getLastSelectedCredentialProfile(), region.getName());
}
- private void setRegionAndProfile(Regions region, String credentialProfile) {
- getLogger().logInfo("Region is set to: %s", region.toString());
+ private void setRegionAndProfile(String credentialProfile, String regionName) {
+ getLogger().logInfo("Region is set to: %s", regionName);
getLogger().logInfo("Profile is set to: %s", credentialProfile);
- reCreateModels(region, credentialProfile);
- getConnectorSettings().setLastSelectedRegionName(region.getName());
+ reCreateModels(credentialProfile, regionName);
+ getConnectorSettings().setLastSelectedRegionName(regionName);
refreshFunctionList();
}
@@ -443,27 +472,9 @@ private void refreshRolesList() {
@Override
public void setCredentialProfile(CredentialProfileEntity credentialProfileEntity) {
BasicProfile basicProfile = credentialProfileEntity.getBasicProfile();
- Regions lastSelectedRegion = getLastSelectedRegion();
- Regions region = lastSelectedRegion;
- if(!isEmpty(basicProfile.getRegion())) {
- region = tryGetRegionBy(basicProfile.getRegion());
- }
- if(region == null){
- region = lastSelectedRegion;
- }
- String credentialProfile = credentialProfileEntity.getName();
- getConnectorSettings().setLastSelectedCredentialProfile(credentialProfile);
- setRegionAndProfile(region, credentialProfile);
- if(!lastSelectedRegion.getName().equals(region.getName())){
- view.setRegion(region);
- }
- CredentialProfileEntity profileEntity = view.getSelectedCredentialProfileEntity();
- if(profileEntity == null) {
- getLogger().logInfo("Credential profile is not selected.");
- } else {
- getLogger().logInfo("Selected Credential profile: \"%s\"", profileEntity.getName());
- }
- refreshStatus();
+ getConnectorSettings().setLastSelectedCredentialProfile(basicProfile.getProfileName());
+ shutdownConnectorModel();
+ refreshCredentialProfilesList();
}
@Override
@@ -553,7 +564,7 @@ public void openTestFunctionInputFile(File file) {
view.setTestFunctionInputRecentEntityList(testFunctionInputRecentEntityList);
} catch (Exception e) {
e.printStackTrace();
- getLogger().logError(e);
+ getLogger().logError("Cannot open of an input file: %s", e.getMessage());
}
}
@@ -575,8 +586,8 @@ public void setSetTestFunctionInputFromRecent(TestFunctionInputEntity entity) {
@Override
public void setProxySettings() {
- FunctionConnectorModel model = this.getFunctionConnectorModel();
- reCreateModels(model.getRegion(), model.getCredentialProfileName());
+ FunctionConnectorModel functionConnectorModel = this.getFunctionConnectorModel();
+ reCreateModels(functionConnectorModel.getCredentialProfileName(), functionConnectorModel.getRegionName());
refreshStatus();
}
@@ -613,10 +624,10 @@ private Regions tryGetRegionBy(String regionName) {
@NotNull
protected Regions getLastSelectedRegion() {
String lastSelectedRegionName = getConnectorSettings().getLastSelectedRegionName();
- Regions region = lastSelectedRegionName == null
- ? DEFAULT_REGION
+ Regions region = isEmpty(lastSelectedRegionName)
+ ? Regions.DEFAULT_REGION
: tryGetRegionBy(lastSelectedRegionName);
- return region != null ? region : DEFAULT_REGION;
+ return region != null ? region : Regions.DEFAULT_REGION;
}
@Override
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorView.java b/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorView.java
index 444de95..842a627 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorView.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorView.java
@@ -12,7 +12,7 @@ public interface ConnectorView {
void setArtifactList(Collection extends ArtifactEntity> artifacts, ArtifactEntity selectedArtifactEntity);
void setRegionList(List regions, Regions selectedRegion);
void setTracingModeList(Collection tracingModeEntities);
- void setCredentialProfilesList(List credentialProfiles, String selectedCredentialsProfile);
+ void setCredentialProfilesList(List credentialProfiles, String selectedProfileName);
void setRegion(Regions region);
void refreshStatus(String function, String artifact, String region, String regionDescription, String credentialProfile, String proxyDetails);
FunctionEntity getSelectedFunctionEntity();
diff --git a/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorViewFactory.java b/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorViewFactory.java
index e50e486..f3eefcc 100644
--- a/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorViewFactory.java
+++ b/sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorViewFactory.java
@@ -463,7 +463,7 @@ private void openFunctionTestInputFile() {
runOperation(() -> presenter.openTestFunctionInputFile(selectedFile), "Read test function input file \"%s\".", selectedFile.getName());
} catch (Exception e) {
e.printStackTrace();
- logError(e.getMessage());
+ logError("Cannot open of an input file: %s", e.getMessage());
}
}
@@ -552,7 +552,7 @@ private void runSetRegion(ItemEvent e) {
RegionEntity entity = (RegionEntity)e.getItem();
if(entity == null)
return;
- runOperation(() -> presenter.setRegion(entity), "Select region: " + entity.toString());
+ runOperation(() -> presenter.setRegion(entity), "Select regionName: " + entity.toString());
}
private void runSetFunction(ItemEvent e) {
@@ -795,12 +795,12 @@ public void setArtifactList(Collection extends ArtifactEntity> artifacts, Arti
}
@Override
- public void setCredentialProfilesList(List credentialProfiles, String selectedCredentialsProfile) {
+ public void setCredentialProfilesList(List credentialProfiles, String selectedProfileName) {
credentialProfileList.removeAllItems();
CredentialProfileEntity selectedCredentialsProfileEntity = null;
for(CredentialProfileEntity entity : credentialProfiles){
credentialProfileList.addItem(entity);
- if(!isEmpty(selectedCredentialsProfile) && entity.getName().equals(selectedCredentialsProfile))
+ if(!isEmpty(selectedProfileName) && entity.getName().equals(selectedProfileName))
selectedCredentialsProfileEntity = entity;
}
if(selectedCredentialsProfileEntity != null) {
diff --git a/sources/test/io/github/satr/idea/plugin/connector/la/FunctionConnectorModelTestCasesBase.java b/sources/test/io/github/satr/idea/plugin/connector/la/FunctionConnectorModelTestCasesBase.java
index ccdf342..bb156fd 100644
--- a/sources/test/io/github/satr/idea/plugin/connector/la/FunctionConnectorModelTestCasesBase.java
+++ b/sources/test/io/github/satr/idea/plugin/connector/la/FunctionConnectorModelTestCasesBase.java
@@ -3,18 +3,23 @@
import com.amazonaws.regions.Regions;
import io.github.satr.common.Constant;
+import io.github.satr.common.Logger;
import io.github.satr.idea.plugin.connector.la.models.FunctionConnectorModel;
import org.junit.After;
import org.junit.Before;
import java.io.File;
+import static org.mockito.Mockito.mock;
+
public class FunctionConnectorModelTestCasesBase {
protected FunctionConnectorModel functionConnectorModel;
+ Logger logger;
@Before
public void setUp() throws Exception {
- functionConnectorModel = new FunctionConnectorModel(Regions.US_EAST_1, Constant.CredentialProfile.DEFAULT);
+ logger = mock(Logger.class);
+ functionConnectorModel = new FunctionConnectorModel(Regions.US_EAST_1.getName(), Constant.CredentialProfile.DEFAULT, logger);
}
@After
diff --git a/sources/test/io/github/satr/idea/plugin/connector/la/UpdateFunctionWithArtifactTestCases.java b/sources/test/io/github/satr/idea/plugin/connector/la/UpdateFunctionWithArtifactTestCases.java
index 037659d..02bae68 100644
--- a/sources/test/io/github/satr/idea/plugin/connector/la/UpdateFunctionWithArtifactTestCases.java
+++ b/sources/test/io/github/satr/idea/plugin/connector/la/UpdateFunctionWithArtifactTestCases.java
@@ -5,9 +5,9 @@
import java.io.File;
-//Tests expected an existing AWS Lambda function with a name "JavaFuncToTestConnector" in the region US-EAST-1.
+//Tests expected an existing AWS Lambda function with a name "JavaFuncToTestConnector" in the regionName US-EAST-1.
//Alter the function name in the constant FUNC_NAME in this class, if needed.
-//Alter the region if the FunctionConnectorModel class, if needed.
+//Alter the regionName if the FunctionConnectorModel class, if needed.
public class UpdateFunctionWithArtifactTestCases extends FunctionConnectorModelTestCasesBase {
private final String FUNC_NAME = "JavaFuncToTestConnector";