use of io.github.satr.common.OperationValueResultImpl in project intellij-idea-plugin-connector-for-aws-lambda by satr.
the class FunctionConnectorModel method getCredentialProfiles.
public OperationValueResult<List<CredentialProfileEntity>> getCredentialProfiles() {
OperationValueResult<List<CredentialProfileEntity>> valueResult = new OperationValueResultImpl<>();
ArrayList<CredentialProfileEntity> credentialProfilesEntries = new ArrayList<>();
valueResult.setValue(credentialProfilesEntries);
if (!validateCredentialProfilesExist()) {
valueResult.addWarning("No credential profiles file found.\n To create one - please follow the instruction:\n https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html ");
return valueResult;
}
ProfilesConfigFile profilesConfigFile = new ProfilesConfigFile();
Map<String, BasicProfile> profiles = profilesConfigFile.getAllBasicProfiles();
for (String credentialProfileName : profiles.keySet()) {
credentialProfilesEntries.add(new CredentialProfileEntity(credentialProfileName, profiles.get(credentialProfileName)));
}
valueResult.addInfo("Found %d credential profiles.", credentialProfilesEntries.size());
return valueResult;
}
use of io.github.satr.common.OperationValueResultImpl in project intellij-idea-plugin-connector-for-aws-lambda by satr.
the class FunctionConnectorModel method deleteAwsLogStreamsFor.
public OperationValueResult deleteAwsLogStreamsFor(String functionName) {
OperationValueResult operationResult = new OperationValueResultImpl();
LogGroup logGroup = getLogGroupForAwsLambdaFunction(functionName);
if (logGroup == null) {
operationResult.addError("Not found log group for the function \"%s\"", functionName);
return operationResult;
}
DeleteLogGroupResult deleteLogGroupResult = awsLogClient.deleteLogGroup(new DeleteLogGroupRequest(logGroup.getLogGroupName()));
int httpStatusCode = deleteLogGroupResult.getSdkHttpMetadata().getHttpStatusCode();
if (httpStatusCode == HttpStatusCode.OK.getCode()) {
return operationResult;
}
operationResult.addError("Operation responded with code %d", httpStatusCode);
return operationResult;
}
use of io.github.satr.common.OperationValueResultImpl in project intellij-idea-plugin-connector-for-aws-lambda by satr.
the class FunctionConnectorModel method invokeFunction.
public OperationValueResult<String> invokeFunction(final String functionName, final String inputText) {
OperationValueResult<String> operationResult = new OperationValueResultImpl<>();
try {
InvokeRequest invokeRequest = new InvokeRequest();
invokeRequest.setFunctionName(functionName);
invokeRequest.setPayload(inputText);
final InvokeResult invokeResult = awsLambdaClient.invoke(invokeRequest);
operationResult.addInfo("Invoked function \"%s\". Result status code: %d", functionName, invokeResult.getStatusCode());
String functionError = invokeResult.getFunctionError();
if (!isEmpty(functionError)) {
operationResult.addError(functionError);
}
String logResult = invokeResult.getLogResult();
if (!isEmpty(logResult)) {
operationResult.addInfo(logResult);
}
ByteBuffer byteBuffer = invokeResult.getPayload();
String rawJson = new String(byteBuffer.array(), "UTF-8");
operationResult.setValue(rawJson);
} catch (Exception e) {
e.printStackTrace();
operationResult.addError(e.getMessage());
}
return operationResult;
}
use of io.github.satr.common.OperationValueResultImpl in project intellij-idea-plugin-connector-for-aws-lambda by satr.
the class FunctionConnectorModel method updateWithJar.
public OperationValueResult<FunctionEntity> updateWithJar(final FunctionEntity functionEntity, final File file) {
final OperationValueResultImpl<FunctionEntity> operationResult = new OperationValueResultImpl<>();
validateLambdaFunctionJarFile(file, operationResult);
if (operationResult.failed())
return operationResult;
try {
final String readOnlyAccessFileMode = "r";
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, readOnlyAccessFileMode);
final FileChannel fileChannel = randomAccessFile.getChannel()) {
return updateFunctionCode(functionEntity, fileChannel);
}
} catch (InvalidParameterValueException e) {
operationResult.addError("Invalid request parameters: %s", e.getMessage());
} catch (ResourceNotFoundException e) {
operationResult.addError("Function not found.");
} catch (Exception e) {
e.printStackTrace();
operationResult.addError(e.getMessage());
}
return operationResult;
}
use of io.github.satr.common.OperationValueResultImpl in project intellij-idea-plugin-connector-for-aws-lambda by satr.
the class FunctionConnectorModel method updateFunctionCode.
private OperationValueResult<FunctionEntity> updateFunctionCode(final FunctionEntity functionEntity, final FileChannel fileChannel) throws IOException {
final OperationValueResultImpl<FunctionEntity> valueResult = new OperationValueResultImpl<>();
try {
final MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
buffer.load();
final UpdateFunctionCodeRequest request = new UpdateFunctionCodeRequest().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());
}
return valueResult;
}
Aggregations