All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atlassian.maven.plugins.aws.it.Cleaner.kt Maven / Gradle / Ivy

package com.atlassian.maven.plugins.aws.it

import com.amazonaws.services.cloudformation.AmazonCloudFormationClientBuilder
import com.amazonaws.services.cloudformation.model.DeleteStackRequest
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder
import com.amazonaws.services.ec2.model.DeleteKeyPairRequest
import com.google.gson.Gson
import org.apache.commons.io.FileUtils
import org.apache.maven.plugin.logging.Log
import java.io.File

class Cleaner(
        private val buildDirectory: File,
        private val log: Log
) {
    fun clean() {
        val json = FileUtils.readFileToString(File(buildDirectory, "stack.json"))
        val stackInfo = Gson().fromJson(json, StackInfo::class.java)
        log.info("Deleting key pair ${stackInfo.keyPairName}")
        AmazonEC2ClientBuilder.standard()
                .withRegion(stackInfo.awsRegion)
                .build()
                .deleteKeyPair(DeleteKeyPairRequest().withKeyName(stackInfo.keyPairName))
        log.info("Deleting stack ${stackInfo.stackName}")
        AmazonCloudFormationClientBuilder.standard()
                .withRegion(stackInfo.awsRegion)
                .build()
                .deleteStack(DeleteStackRequest().withStackName(stackInfo.stackName))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy