import com.sonymusic.Utils

def call(Map args = [:]) {
    def params = Utils.validateParams('retagEcrImage', args, [
        awsRegions: [type: List, itemType: String, required: true],
        ecrAccountId: [type: String, required: true],
        imageName: [type: String, required: true],
        imageTag: [type: String, required: true],
        newTag: [type: String, required: true]
    ])

    params.awsRegions.each { region ->
        withEcr(registries: [
            [accountId: params.ecrAccountId, region: region]
        ]) {
            withEnv([
                "AWS_DEFAULT_REGION=${region}",
                "ECR_ACCOUNT_ID=${params.ecrAccountId}",
                "IMAGE_NAME=${params.imageName}",
                "IMAGE_TAG=${params.imageTag}",
                "NEW_TAG=${params.newTag}"
            ]) {
                sh(libraryResource('retagEcrImage.sh'))
            }
        }
    }
}
