Skip to content

Commit

Permalink
Fix authentication for created proxy repos
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitounator committed May 7, 2021
1 parent 3c9ef78 commit c8e075e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions files/groovy/create_repos_from_list.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ private Configuration newConfiguration(Map map) {
}

private boolean configurationChanged(Configuration oldConfig, Configuration newConfig) {
if (oldConfig.attributes.httpclient)
if (oldConfig.attributes.httpclient.authentication == [:])
if (oldConfig.attributes.httpclient) {
if (oldConfig.attributes.httpclient.authentication == [:]) {
oldConfig.attributes.httpclient.authentication = null
return oldConfig.properties == newConfig.properties
}
}
return oldConfig.properties != newConfig.properties
}


parsed_args.each { currentRepo ->

Map<String, String> currentResult = [name: currentRepo.name, format: currentRepo.format, type: currentRepo.type]
Expand Down Expand Up @@ -104,21 +107,22 @@ parsed_args.each { currentRepo ->

// Configs for all proxy repos
if (currentRepo.type == 'proxy') {
authentication = currentRepo.remote_username == null ? null : [
type : 'username',
username: currentRepo.remote_username,
password: currentRepo.remote_password
]

configuration.attributes['httpclient'] = [
authentication: authentication,
blocked : false,
autoBlock : true,
connection : [
useTrustStore: false
]
]

if (currentRepo.remote_username) {
configuration.attributes['httpclient']['authentication'] = [
type : 'username',
username: currentRepo.remote_username,
password: currentRepo.remote_password
]
}

configuration.attributes['proxy'] = [
remoteUrl : currentRepo.remote_url,
contentMaxAge : currentRepo.get('maximum_component_age', 1440.0),
Expand Down Expand Up @@ -175,7 +179,7 @@ parsed_args.each { currentRepo ->
scriptResults['changed'] = true
log.info('Configuration for repo {} created', currentRepo.name)
} else {
if (!configurationChanged(existingRepository.configuration, configuration)) {
if (configurationChanged(existingRepository.configuration, configuration)) {
repositoryManager.update(configuration)
currentResult.put('status', 'updated')
log.info('Configuration for repo {} saved', currentRepo.name)
Expand Down

0 comments on commit c8e075e

Please sign in to comment.