From c8e075ef4b26a94c24f52d168b11357b1aa93779 Mon Sep 17 00:00:00 2001 From: Olivier Clavel Date: Fri, 7 May 2021 17:13:24 +0200 Subject: [PATCH] Fix authentication for created proxy repos --- files/groovy/create_repos_from_list.groovy | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/files/groovy/create_repos_from_list.groovy b/files/groovy/create_repos_from_list.groovy index 1a9c9533..3980def7 100644 --- a/files/groovy/create_repos_from_list.groovy +++ b/files/groovy/create_repos_from_list.groovy @@ -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 currentResult = [name: currentRepo.name, format: currentRepo.format, type: currentRepo.type] @@ -104,14 +107,7 @@ 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 : [ @@ -119,6 +115,14 @@ parsed_args.each { currentRepo -> ] ] + 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), @@ -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)