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

Commit

Permalink
Version Bumps and Code Cleanup (#114)
Browse files Browse the repository at this point in the history
* version bumps

* fix tests, resolve codenarc violations

* Revert AwsClientUtil rename
  • Loading branch information
mftruso authored Oct 7, 2020
1 parent 166845c commit ae3b186
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 49 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version=2.4.7
awsJavaSdkVersion=1.11.714
awsKinesisClientVersion=1.10.0
gradleWrapperVersion=5.5.1
grailsVersion=4.0.0
awsJavaSdkVersion=1.11.874
awsKinesisClientVersion=1.14.0
gradleWrapperVersion=5.6.4
grailsVersion=4.0.4
groovyVersion=2.5.6
logbackVersion=1.2.3
slf4jVersion=1.7.26
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grails.plugin.awssdk.kinesis

import agorapulse.libs.awssdk.util.AwsClientUtil
import com.amazonaws.regions.Region

import com.amazonaws.services.kinesis.AmazonKinesis
import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder
import com.amazonaws.services.kinesis.model.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package grails.plugin.awssdk.ses

import com.agorapulse.awssdk.ses.UnsupportedAttachmentTypeException
import grails.test.mixin.integration.Integration
import grails.testing.mixin.integration.Integration
import grails.util.Environment
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.IgnoreIf
Expand Down Expand Up @@ -102,6 +102,7 @@ class AmazonSESServiceIntegrationSpec extends Specification {
!emailFound
}

@IgnoreIf({ !System.getenv('TEST_INBOX_EMAIL') })
void "test that if you try to send an unsupported attachment an exception is thrown "() {
when:
def subjectStr = 'GRAILS AWS SDK SES with Attachment'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package grails.plugin.awssdk.ses

import grails.test.mixin.integration.Integration
import grails.testing.mixin.integration.Integration
import grails.util.Environment
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.IgnoreIf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.agorapulse.awssdk.ses

import static com.agorapulse.awssdk.ses.AwsSdkSesEmailDeliveryStatus.STATUS_DELIVERED
import static com.agorapulse.awssdk.ses.AwsSdkSesEmailDeliveryStatus.STATUS_NOT_DELIVERED
import static com.agorapulse.awssdk.ses.AwsSdkSesEmailDeliveryStatus.STATUS_BLACKLISTED

import com.agorapulse.awssdk.AwsSdkUtils
import com.amazonaws.AmazonClientException
import com.amazonaws.AmazonServiceException
Expand All @@ -12,7 +16,13 @@ import com.amazonaws.regions.RegionUtils
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder
import com.amazonaws.services.simpleemail.model.*
import com.amazonaws.services.simpleemail.model.Body
import com.amazonaws.services.simpleemail.model.Content
import com.amazonaws.services.simpleemail.model.Destination
import com.amazonaws.services.simpleemail.model.Message
import com.amazonaws.services.simpleemail.model.RawMessage
import com.amazonaws.services.simpleemail.model.SendEmailRequest
import com.amazonaws.services.simpleemail.model.SendRawEmailRequest
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j

Expand All @@ -27,8 +37,6 @@ import javax.mail.internet.MimeMultipart
import javax.mail.util.ByteArrayDataSource
import java.nio.ByteBuffer

import static com.agorapulse.awssdk.ses.AwsSdkSesEmailDeliveryStatus.*

@Slf4j
@CompileStatic
class AwsSesMailer {
Expand All @@ -44,7 +52,7 @@ class AwsSesMailer {
ClientConfiguration clientConfiguration = AwsSdkUtils.clientConfigurationWithMap([:])
client = AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(new AWSCredentialsProvider() {
@Override AWSCredentials getCredentials() { return new BasicAWSCredentials(accessKey, secretKey) }
@Override AWSCredentials getCredentials() { new BasicAWSCredentials(accessKey, secretKey) }

@Override void refresh() { }
})
Expand All @@ -71,7 +79,7 @@ class AwsSesMailer {
sendEmailWithAttachment(transactionalEmail)
}

@SuppressWarnings(['LineLength', 'ElseBlockBraces', 'JavaIoPackageAccess'])
@SuppressWarnings(['LineLength', 'ElseBlockBraces', 'JavaIoPackageAccess', 'AbcMetric'])
int sendEmailWithAttachment(TransactionalEmail transactionalEmail) throws UnsupportedAttachmentTypeException {
int statusId = STATUS_NOT_DELIVERED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import com.amazonaws.auth.AWSCredentialsProvider
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.client.builder.AwsSyncClientBuilder
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.regions.Region
import com.amazonaws.regions.RegionUtils

@SuppressWarnings(['FactoryMethodName'])
class AwsClientUtil {

static final String DEFAULT_REGION = 'us-east-1'
Expand All @@ -19,7 +20,7 @@ class AwsClientUtil {
Region region = buildRegion(config, serviceConfig)
assert region.isServiceSupported(serviceName)

AwsClientBuilder.EndpointConfiguration endpointConfiguration = buildEndpointConfiguration(config, serviceConfig)
EndpointConfiguration endpointConfiguration = buildEndpointConfiguration(config, serviceConfig)

if (endpointConfiguration) {
builder.withEndpointConfiguration(endpointConfiguration)
Expand All @@ -38,6 +39,7 @@ class AwsClientUtil {
* @param serviceConfig
* @return
*/
@SuppressWarnings(['CyclomaticComplexity', 'AbcMetric', 'MethodSize'])
static ClientConfiguration buildClientConfiguration(defaultConfig, serviceConfig) {
Map config = [
connectionTimeout: defaultConfig.connectionTimeout ?: 0,
Expand All @@ -54,36 +56,85 @@ class AwsClientUtil {
proxyWorkstation: defaultConfig.proxyWorkstation ?: ''
]
if (serviceConfig) {
if (serviceConfig.connectionTimeout) config.connectionTimeout = serviceConfig.connectionTimeout
if (serviceConfig.maxConnections) config.maxConnections = serviceConfig.maxConnections
if (serviceConfig.maxErrorRetry) config.maxErrorRetry = serviceConfig.maxErrorRetry
if (serviceConfig.protocol) config.protocol = serviceConfig.protocol
if (serviceConfig.socketTimeout) config.socketTimeout = serviceConfig.socketTimeout
if (serviceConfig.userAgent) config.userAgent = serviceConfig.userAgent
if (serviceConfig.proxyDomain) config.proxyDomain = serviceConfig.proxyDomain
if (serviceConfig.proxyHost) config.proxyHost = serviceConfig.proxyHost
if (serviceConfig.proxyPassword) config.proxyPassword = serviceConfig.proxyPassword
if (serviceConfig.proxyPort) config.proxyPort = serviceConfig.proxyPort
if (serviceConfig.proxyUsername) config.proxyUsername = serviceConfig.proxyUsername
if (serviceConfig.proxyWorkstation) config.proxyWorkstation = serviceConfig.proxyWorkstation
if (serviceConfig.connectionTimeout) {
config.connectionTimeout = serviceConfig.connectionTimeout
}
if (serviceConfig.maxConnections) {
config.maxConnections = serviceConfig.maxConnections
}
if (serviceConfig.maxErrorRetry) {
config.maxErrorRetry = serviceConfig.maxErrorRetry
}
if (serviceConfig.protocol) {
config.protocol = serviceConfig.protocol
}
if (serviceConfig.socketTimeout) {
config.socketTimeout = serviceConfig.socketTimeout
}
if (serviceConfig.userAgent) {
config.userAgent = serviceConfig.userAgent
}
if (serviceConfig.proxyDomain) {
config.proxyDomain = serviceConfig.proxyDomain
}
if (serviceConfig.proxyHost) {
config.proxyHost = serviceConfig.proxyHost
}
if (serviceConfig.proxyPassword) {
config.proxyPassword = serviceConfig.proxyPassword
}
if (serviceConfig.proxyPort) {
config.proxyPort = serviceConfig.proxyPort
}
if (serviceConfig.proxyUsername) {
config.proxyUsername = serviceConfig.proxyUsername
}
if (serviceConfig.proxyWorkstation) {
config.proxyWorkstation = serviceConfig.proxyWorkstation
}
}

ClientConfiguration clientConfiguration = new ClientConfiguration()
if (config.connectionTimeout) clientConfiguration.connectionTimeout = config.connectionTimeout
if (config.maxConnections) clientConfiguration.maxConnections = config.maxConnections
if (config.maxErrorRetry) clientConfiguration.maxErrorRetry = config.maxErrorRetry
if (config.connectionTimeout) {
clientConfiguration.connectionTimeout = config.connectionTimeout
}
if (config.maxConnections) {
clientConfiguration.maxConnections = config.maxConnections
}
if (config.maxErrorRetry) {
clientConfiguration.maxErrorRetry = config.maxErrorRetry
}
if (config.protocol) {
if (config.protocol.toUpperCase() == 'HTTP') clientConfiguration.protocol = Protocol.HTTP
else clientConfiguration.protocol = Protocol.HTTPS
}
if (config.socketTimeout) clientConfiguration.socketTimeout = config.socketTimeout
if (config.userAgent) clientConfiguration.userAgent = config.userAgent
if (config.proxyDomain) clientConfiguration.proxyDomain = config.proxyDomain
if (config.proxyHost) clientConfiguration.proxyHost = config.proxyHost
if (config.proxyPassword) clientConfiguration.proxyPassword = config.proxyPassword
if (config.proxyPort) clientConfiguration.proxyPort = config.proxyPort
if (config.proxyUsername) clientConfiguration.proxyUsername = config.proxyUsername
if (config.proxyWorkstation) clientConfiguration.proxyWorkstation = config.proxyWorkstation
if (config.protocol.toUpperCase() == 'HTTP') {
clientConfiguration.protocol = Protocol.HTTP
} else {
clientConfiguration.protocol = Protocol.HTTPS
}
}
if (config.socketTimeout) {
clientConfiguration.socketTimeout = config.socketTimeout
}
if (config.userAgent) {
clientConfiguration.userAgent = config.userAgent
}
if (config.proxyDomain) {
clientConfiguration.proxyDomain = config.proxyDomain
}
if (config.proxyHost) {
clientConfiguration.proxyHost = config.proxyHost
}
if (config.proxyPassword) {
clientConfiguration.proxyPassword = config.proxyPassword
}
if (config.proxyPort) {
clientConfiguration.proxyPort = config.proxyPort
}
if (config.proxyUsername) {
clientConfiguration.proxyUsername = config.proxyUsername
}
if (config.proxyWorkstation) {
clientConfiguration.proxyWorkstation = config.proxyWorkstation
}
clientConfiguration
}

Expand All @@ -99,8 +150,12 @@ class AwsClientUtil {
secretKey: defaultConfig.secretKey ?: ''
]
if (serviceConfig) {
if (serviceConfig.accessKey) config.accessKey = serviceConfig.accessKey
if (serviceConfig.secretKey) config.secretKey = serviceConfig.secretKey
if (serviceConfig.accessKey) {
config.accessKey = serviceConfig.accessKey
}
if (serviceConfig.secretKey) {
config.secretKey = serviceConfig.secretKey
}
}

if (!config.accessKey || !config.secretKey) {
Expand All @@ -115,6 +170,7 @@ class AwsClientUtil {
* @param defaultConfig
* @param serviceConfig
*/
@SuppressWarnings(['ElseBlockBraces'])
static buildRegion(defaultConfig, serviceConfig) {
String regionName = DEFAULT_REGION
if (serviceConfig?.region) {
Expand All @@ -125,15 +181,15 @@ class AwsClientUtil {
RegionUtils.getRegion(regionName)
}

static AwsClientBuilder.EndpointConfiguration buildEndpointConfiguration(defaultConfig, serviceConfig) {
@SuppressWarnings(['ElseBlockBraces'])
static EndpointConfiguration buildEndpointConfiguration(defaultConfig, serviceConfig) {
Region region = buildRegion(defaultConfig, serviceConfig)
if (serviceConfig?.endpoint) {
return new AwsClientBuilder.EndpointConfiguration(serviceConfig.endpoint as String, region.name)
return new EndpointConfiguration(serviceConfig.endpoint as String, region.name)
} else if (defaultConfig?.endpoint) {
return new AwsClientBuilder.EndpointConfiguration(defaultConfig.endpoint as String, region.name)
return new EndpointConfiguration(defaultConfig.endpoint as String, region.name)
}
return null
null
}


}

0 comments on commit ae3b186

Please sign in to comment.