javaposse.jobdsl.dsl.helpers.AuthorizationContextHelper.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of job-dsl-core Show documentation
Show all versions of job-dsl-core Show documentation
Javaposse jenkins job-dsl-core
package javaposse.jobdsl.dsl.helpers
import javaposse.jobdsl.dsl.JobType
import javaposse.jobdsl.dsl.WithXmlAction
class AuthorizationContextHelper extends AbstractContextHelper {
/**
* Per-execution state, cleared each time, look for STATEFUL
* TOOD initialize and support permission methods being called directly
*/
AuthorizationContextHelper(List withXmlActions, JobType jobType) {
super(withXmlActions, jobType)
}
// STATEFUL
List authorization(Closure closure) {
// Reset context
def context = new AuthorizationContext()
execute(closure, context)
context.perms
}
// TODO: Support dotted notation. Currently because of perms being around for the closure, we can't just append to it outside of a closure
AuthorizationContextHelper getAuthorization() {
return this
}
private addAuthorization(String perm) {
withXmlActions << generateWithXmlAction( new AuthorizationContext([perm]))
}
def permission(String perm) {
// TODO Check formatting, e.g. has colon
addAuthorization(perm)
this
}
def permission(Permissions perm, String user) {
addAuthorization("${perm.longForm}:${user}")
this
}
def permission(String permEnumName, String user) {
permission( Permissions.valueOf(Permissions, permEnumName), user)
this
}
Closure generateWithXmlClosure(AuthorizationContext context) {
List perms = context.perms
return { Node project ->
def matrix = project / 'properties' / 'hudson.security.AuthorizationMatrixProperty'
perms.each { String perm ->
// Using matrix << permission(perm) will resolve permission locally on AuthorizationContextHelper
matrix.appendNode('permission', perm)
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy