com.atlassian.maven.plugins.aws.it.Uploader.kt Maven / Gradle / Ivy
package com.atlassian.maven.plugins.aws.it
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import org.apache.maven.plugin.logging.Log
import java.io.File
class Uploader(
private val log: Log
) {
fun upload(
s3Uploads: List,
stackInfo: StackInfo
) {
s3Uploads.forEach {
upload(it, stackInfo)
}
}
private fun upload(
s3Upload: S3Upload,
stackInfo: StackInfo
) {
val logicalId = s3Upload.bucketLogicalId
val bucket = stackInfo.findBucket(logicalId)
upload(
s3Upload.files,
AmazonS3ClientBuilder.standard()
.withRegion(stackInfo.awsRegion)
.build(),
bucket.physicalResourceId
)
}
private fun upload(
files: List,
s3: AmazonS3,
bucketName: String
) {
files.forEach {
log.info("Uploading $it to $bucketName")
s3.putObject(
bucketName,
it.name,
it
)
}
}
}