Skip to content

Commit

Permalink
Update code formatting, remove infix/postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
gheine committed Jan 27, 2020
1 parent 0baab9c commit 4468a4e
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 97 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/com/gilt/aws/lambda/AwsIAM.scala
Expand Up @@ -10,15 +10,17 @@ object AwsIAM {

private[lambda] class AwsIAM(client: wrapper.AmazonIdentityManagement) {

def basicLambdaRole(): Option[Role] = {
def basicLambdaRole(
): Option[Role] = {
client.listRoles()
.toOption
.flatMap { result =>
result.getRoles.asScala.find(_.getRoleName == AwsIAM.BasicLambdaRoleName)
}
}

def createBasicLambdaRole(): Try[RoleARN] = {
def createBasicLambdaRole(
): Try[RoleARN] = {
val createRoleRequest = {
val policyDocument = """{"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}"""
new CreateRoleRequest()
Expand Down
67 changes: 41 additions & 26 deletions src/main/scala/com/gilt/aws/lambda/AwsLambda.scala
Expand Up @@ -7,16 +7,22 @@ import scala.util.Try

private[lambda] class AwsLambda(client: wrapper.AwsLambda) {

def publishVersion(name: String, revisionId: String, version: String)
: Try[PublishVersionResult] = {
def publishVersion(
name: String,
revisionId: String,
version: String,
): Try[PublishVersionResult] = {
val request = new PublishVersionRequest()
.withFunctionName(name)
.withRevisionId(revisionId)
.withDescription(version)
client.publishVersion(request)
}

def updateLambdaWithFunctionCodeRequest(updateFunctionCodeRequest: UpdateFunctionCodeRequest, version: String): Try[UpdateFunctionCodeResult] = {
def updateLambdaWithFunctionCodeRequest(
updateFunctionCodeRequest: UpdateFunctionCodeRequest,
version: String,
): Try[UpdateFunctionCodeResult] = {
println(s"Updating lambda code ${updateFunctionCodeRequest.getFunctionName}")
for {
updateResult <- client.updateFunctionCode(updateFunctionCodeRequest)
Expand All @@ -27,7 +33,10 @@ private[lambda] class AwsLambda(client: wrapper.AwsLambda) {
}
}

def tagLambda(functionArn: String, version: String) = {
def tagLambda(
functionArn: String,
version: String,
): Try[TagResourceResult] = {
val tags = Map(
"deploy.code.version" -> version,
"deploy.timestamp" -> Instant.now.toString
Expand All @@ -40,7 +49,9 @@ private[lambda] class AwsLambda(client: wrapper.AwsLambda) {
client.tagResource(tagResourceReq)
}

def getLambdaConfig(functionName: LambdaName): Try[Option[GetFunctionConfigurationResult]] = {
def getLambdaConfig(
functionName: LambdaName,
): Try[Option[GetFunctionConfigurationResult]] = {
val request = new GetFunctionConfigurationRequest()
.withFunctionName(functionName.value)

Expand All @@ -51,21 +62,23 @@ private[lambda] class AwsLambda(client: wrapper.AwsLambda) {
}
}

def updateLambdaConfig(functionName: LambdaName,
handlerName: HandlerName,
roleName: RoleARN,
timeout: Option[Timeout],
memory: Option[Memory],
deadLetterName: Option[DeadLetterARN],
vpcConfig: Option[VpcConfig],
environment: Environment,
version: String): Try[UpdateFunctionConfigurationResult] = {
def updateLambdaConfig(
functionName: LambdaName,
handlerName: HandlerName,
roleName: RoleARN,
timeout: Option[Timeout],
memory: Option[Memory],
deadLetterName: Option[DeadLetterARN],
vpcConfig: Option[VpcConfig],
environment: Environment,
version: String,
): Try[UpdateFunctionConfigurationResult] = {

var request = new UpdateFunctionConfigurationRequest()
.withFunctionName(functionName.value)
.withHandler(handlerName.value)
.withRole(roleName.value)
.withRuntime(com.amazonaws.services.lambda.model.Runtime.Java8)
.withRuntime(Runtime.Java8)
.withEnvironment(environment)

request = timeout.fold(request)(t => request.withTimeout(t.value))
Expand All @@ -82,22 +95,24 @@ private[lambda] class AwsLambda(client: wrapper.AwsLambda) {
}
}

def createLambda(functionName: LambdaName,
handlerName: HandlerName,
roleName: RoleARN,
timeout: Option[Timeout],
memory: Option[Memory],
deadLetterName: Option[DeadLetterARN],
vpcConfig: Option[VpcConfig],
functionCode: FunctionCode,
environment: Environment,
version: String): Try[CreateFunctionResult] = {
def createLambda(
functionName: LambdaName,
handlerName: HandlerName,
roleName: RoleARN,
timeout: Option[Timeout],
memory: Option[Memory],
deadLetterName: Option[DeadLetterARN],
vpcConfig: Option[VpcConfig],
functionCode: FunctionCode,
environment: Environment,
version: String,
): Try[CreateFunctionResult] = {

var request = new CreateFunctionRequest()
.withFunctionName(functionName.value)
.withHandler(handlerName.value)
.withRole(roleName.value)
.withRuntime(com.amazonaws.services.lambda.model.Runtime.Java8)
.withRuntime(Runtime.Java8)
.withEnvironment(environment)
.withCode(functionCode)
request = timeout.fold(request)(t => request.withTimeout(t.value))
Expand Down

0 comments on commit 4468a4e

Please sign in to comment.