2022-01-25 15:11:54 +01:00
|
|
|
import groovy.json.JsonOutput
|
|
|
|
|
2022-02-10 10:26:05 +01:00
|
|
|
def getResourceHREF(
|
|
|
|
String credentials,
|
|
|
|
String resourceEndpoint,
|
2022-02-10 14:27:49 +01:00
|
|
|
String resourceName,
|
|
|
|
String pulpHost = '192.168.30.3'
|
2022-02-10 10:26:05 +01:00
|
|
|
) {
|
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/${resourceEndpoint}", httpMode: 'GET', ignoreSslErrors: true
|
|
|
|
def jsonResponse = readJSON text: response.content
|
|
|
|
def resource = jsonResponse.results.find { it -> it.name == resourceName}
|
|
|
|
if (resource) {
|
|
|
|
return resource.pulp_href
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
def waitForTaskCompletion(
|
|
|
|
String credentials,
|
|
|
|
String taskHREF,
|
|
|
|
String pulpHost = '192.168.30.3'
|
|
|
|
) {
|
|
|
|
def status = ''
|
|
|
|
def created_resources = []
|
|
|
|
while (status != 'completed') {
|
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true
|
|
|
|
def jsonResponse = readJSON text: response.content
|
|
|
|
status = jsonResponse.state
|
|
|
|
if (status == 'completed') {
|
|
|
|
created_resources = jsonResponse.created_resources
|
|
|
|
}
|
|
|
|
sleep(10)
|
|
|
|
}
|
|
|
|
return created_resources
|
|
|
|
}
|
|
|
|
|
2022-01-25 15:11:54 +01:00
|
|
|
def exportPackages(
|
|
|
|
String credentials,
|
|
|
|
List packages = [],
|
2022-02-08 09:28:59 +01:00
|
|
|
String pulpHost = '192.168.30.3'
|
2022-01-25 15:11:54 +01:00
|
|
|
) {
|
|
|
|
def exportTasks = []
|
|
|
|
packages.each {
|
2022-02-09 21:03:53 +01:00
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/content/deb/packages/", httpMode: 'POST', ignoreSslErrors: true, multipartName: "file", timeout: 900, uploadFile: "${it}"
|
2022-02-09 20:43:21 +01:00
|
|
|
def jsonResponse = readJSON text: response.content
|
2022-01-25 15:11:54 +01:00
|
|
|
exportTasks << jsonResponse['task']
|
|
|
|
}
|
|
|
|
return exportTasks
|
|
|
|
}
|
|
|
|
|
2022-02-09 19:05:31 +01:00
|
|
|
def createRepository(
|
|
|
|
String credentials,
|
|
|
|
String name,
|
|
|
|
String pulpHost = '192.168.30.3'
|
|
|
|
) {
|
|
|
|
def repositoryName = ["name": name]
|
|
|
|
def postBody = JsonOutput.toJson(repositoryName)
|
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/repositories/deb/apt/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "100:399"
|
|
|
|
def jsonResponse = readJSON text: response.content
|
2022-02-09 19:39:15 +01:00
|
|
|
return jsonResponse.pulp_href
|
2022-02-09 19:05:31 +01:00
|
|
|
|
|
|
|
}
|
2022-01-25 15:11:54 +01:00
|
|
|
def getRepositoryHREF(
|
|
|
|
String credentials,
|
2022-02-10 14:27:49 +01:00
|
|
|
String repository = 'Cadoles4MSE unstable'
|
2022-01-25 15:11:54 +01:00
|
|
|
) {
|
2022-02-10 10:26:05 +01:00
|
|
|
def repositoryHREF = getResourceHREF(credentials, 'repositories/deb/apt/', repository)
|
2022-02-09 19:05:31 +01:00
|
|
|
if (repositoryHREF) {
|
2022-02-10 10:26:05 +01:00
|
|
|
return repositoryHREF
|
2022-02-09 19:05:31 +01:00
|
|
|
} else {
|
2022-02-09 22:53:00 +01:00
|
|
|
return createRepository(credentials, repository)
|
2022-02-09 19:05:31 +01:00
|
|
|
}
|
2022-01-25 15:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def addToRepository(
|
|
|
|
String credentials,
|
|
|
|
List packagesHREF,
|
|
|
|
String repositoryHREF,
|
2022-02-08 09:28:59 +01:00
|
|
|
String pulpHost = '192.168.30.3'
|
2022-01-25 15:11:54 +01:00
|
|
|
) {
|
|
|
|
def packagesHREFURL = ["add_content_units": packagesHREF.collect { "https://$pulpHost$it" }]
|
|
|
|
def postBody = JsonOutput.toJson(packagesHREFURL)
|
2022-02-09 19:05:31 +01:00
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${repositoryHREF}modify/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "100:399"
|
2022-01-25 15:11:54 +01:00
|
|
|
def jsonResponse = readJSON text: response.content
|
|
|
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
|
|
|
}
|
|
|
|
|
|
|
|
def publishRepository(
|
|
|
|
String credentials,
|
|
|
|
String repositoryHREF,
|
2022-02-10 11:18:39 +01:00
|
|
|
String signing_service = null,
|
2022-02-08 09:28:59 +01:00
|
|
|
String pulpHost = '192.168.30.3'
|
2022-01-25 15:11:54 +01:00
|
|
|
) {
|
2022-02-10 10:26:05 +01:00
|
|
|
def postContent = ["repository": repositoryHREF, "simple": true]
|
|
|
|
if (signing_service) {
|
|
|
|
def signingServiceHREF = getResourceHREF(credentials, 'signing-services/', signing_service)
|
|
|
|
if (signingServiceHREF) {
|
2022-03-01 16:39:06 +01:00
|
|
|
postContent.put("signing_service", "https://${pulpHost}${signingServiceHREF}")
|
2022-02-10 10:26:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
def postBody = JsonOutput.toJson(postContent)
|
2022-03-01 16:30:14 +01:00
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/publications/deb/apt/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "100:599"
|
2022-01-25 15:11:54 +01:00
|
|
|
def jsonResponse = readJSON text: response.content
|
2022-03-01 16:21:31 +01:00
|
|
|
println(jsonResponse)
|
2022-01-25 15:11:54 +01:00
|
|
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
|
|
|
}
|
|
|
|
|
|
|
|
def distributePublication(
|
|
|
|
String credentials,
|
|
|
|
String publicationHREF,
|
|
|
|
String distributionName,
|
|
|
|
String basePath,
|
2022-02-10 10:51:09 +01:00
|
|
|
String contentGuard = null,
|
2022-02-10 11:18:39 +01:00
|
|
|
String pulpHost = '192.168.30.3'
|
2022-01-25 15:11:54 +01:00
|
|
|
) {
|
|
|
|
def httpMode = ''
|
|
|
|
def url = ''
|
2022-02-10 10:26:05 +01:00
|
|
|
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
|
|
|
if (distributionHREF) {
|
2022-01-25 15:11:54 +01:00
|
|
|
httpMode = 'PUT'
|
2022-02-10 10:26:05 +01:00
|
|
|
url = distributionHREF
|
2022-01-25 15:11:54 +01:00
|
|
|
} else {
|
|
|
|
httpMode = 'POST'
|
|
|
|
url = '/pulp/api/v3/distributions/deb/apt/'
|
|
|
|
}
|
2022-02-10 10:26:05 +01:00
|
|
|
def bodyContent = ["publication": publicationHREF, "name": distributionName, "base_path": basePath]
|
|
|
|
if (contentGuard) {
|
|
|
|
def contentGuardHREF = getResourceHREF(credentials, 'contentguards/core/rbac/', contentGuard)
|
|
|
|
if (contentGuardHREF) {
|
|
|
|
bodyContent.put('content_guard', "https://${pulpHost}${contentGuardHREF}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
def postBody = JsonOutput.toJson(bodyContent)
|
2022-02-09 19:05:31 +01:00
|
|
|
response = httpRequest authentication: credentials, url: "https://${pulpHost}${url}", httpMode: httpMode, requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "100:399"
|
2022-01-25 15:11:54 +01:00
|
|
|
jsonResponse = readJSON text: response.content
|
2022-02-10 15:05:22 +01:00
|
|
|
if (distributionHREF) {
|
2022-01-25 15:11:54 +01:00
|
|
|
waitForTaskCompletion(credentials, jsonResponse.task)
|
|
|
|
return [url]
|
|
|
|
} else {
|
|
|
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def getDistributionURL(
|
|
|
|
String credentials,
|
|
|
|
String resourceHREF,
|
2022-02-08 09:28:59 +01:00
|
|
|
String pulpHost = '192.168.30.3'
|
2022-01-25 15:11:54 +01:00
|
|
|
) {
|
|
|
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${resourceHREF}", httpMode: 'GET', ignoreSslErrors: true
|
|
|
|
def jsonResponse = readJSON text: response.content
|
|
|
|
println(jsonResponse)
|
|
|
|
return jsonResponse.base_url
|
|
|
|
}
|