def common = new com.mirantis.mk.Common()
def aptly = new com.mirantis.mk.Aptly()
def jenkinsUtils = new com.mirantis.mk.JenkinsUtils()

def packages
try {
    packages = PACKAGES
} catch (MissingPropertyException e) {
    packages = ""
}

def components
try {
    components = COMPONENTS
} catch (MissingPropertyException e) {
    components = ""
}

def storages
try {
    storages = STORAGES.tokenize(',')
} catch (MissingPropertyException e) {
    storages = ['local']
}

def insufficientPermissions = false

timeout(time: 12, unit: 'HOURS') {
    node("docker&&hardware") {
        try {
            stage("promote") {
                // promote is restricted to users in aptly-promote-users LDAP group
                if (jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "aptly-promote-users"])) {
                    lock("aptly-api") {
                        for (storage in storages) {
                            if (storage == "local") {
                                storage = ""
                            }
                            retry(2) {
                                aptly.promotePublish(APTLY_URL, SOURCE, TARGET, RECREATE, components, packages, DIFF_ONLY, '-d --timeout 600', DUMP_PUBLISH.toBoolean(), storage)
                            }
                        }
                    }
                } else {
                    insufficientPermissions = true
                    throw new Exception(String.format("You don't have permissions to make aptly promote from source:%s to target:%s! Only CI/CD and QA team can perform aptly promote.", SOURCE, TARGET))
                }
            }
        } catch (Throwable e) {
            // If there was an error or exception thrown, the build failed
            if (insufficientPermissions) {
                currentBuild.result = "ABORTED"
                currentBuild.description = "Promote aborted due to insufficient permissions"
            } else {
                currentBuild.result = "FAILURE"
                currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
            }
            throw e
        } finally {
            if (!insufficientPermissions) {
                common.sendNotification(currentBuild.result, "", ["slack"])
                def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
                currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
            }
        }
    }
}

