Skip to content

Commit

Permalink
Create Services Domain in changeJenkinsPassword
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 committed Oct 6, 2024
1 parent 9332d97 commit ef9b935
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/io/codemc/api/jenkins/jenkins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ internal suspend fun createCredentials(username: String, password: String): Bool
* @return `true` if the password was changed, `false` otherwise.
*/
fun changeJenkinsPassword(username: String, newPassword: String): Boolean = runBlocking(Dispatchers.IO) {
// Create Credentials Domain
val checkDomain = req("${jenkinsConfig.url}/job/$username/credentials/store/folder/domain/Services/config.xml") {
GET()

header("Authorization", "Basic ${client.authValue()}")
}

if (checkDomain.statusCode() == 404) {
val domainConfig = RESOURCE_CACHE[CREDENTIALS_DOMAIN] ?: return@runBlocking false
val domain = req("${jenkinsConfig.url}/job/$username/credentials/store/folder/createDomain") {
POST(HttpRequest.BodyPublishers.ofString(domainConfig))

header("Authorization", "Basic ${client.authValue()}")
header("Content-Type", "application/xml")
}

if (domain.statusCode() != 200) return@runBlocking false
}

val config = (RESOURCE_CACHE[CREDENTIALS] ?: return@runBlocking false)
.replace("{ID}", NEXUS_CREDENTIALS_ID)
.replace("{DESCRIPTION}", NEXUS_CREDENTIALS_DESCRIPTION)
Expand Down

0 comments on commit ef9b935

Please sign in to comment.