Created
February 14, 2019 18:28
-
-
Save robzienert/0a1a999e8a7e02df879d67b4fb170bf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface JenkinsServiceFactory { | |
fun build(jenkinsHostId: String, | |
jenkinsClient: JenkinsClient, | |
csrf: Boolean): JenkinsService | |
} | |
interface JenkinsClientFactory { | |
fun build(): JenkinsClient | |
} | |
class DefaultJenkinsServiceFactory : JenkinsServiceFactory { | |
override fun build(jenkinsHostId: String, | |
jenkinsClient: JenkinsClient, | |
csrf: Boolean): JenkinsService { | |
return JenkinsService(jenkinsHostId, jenkinsClient, csrf) | |
} | |
} | |
@Configuration | |
class JenkinsConfig { | |
@Bean | |
@ConditionalOnMissingBean(JenkinsClientFactory::class) | |
fun jenkinsClientFactory(): JenkinsClientFactory = | |
DefaultJenkinsClientFactory() | |
@Bean | |
@ConditionalOnMissingBean(JenkinsServiceFactory::class) | |
fun jenkinsServiceFactory(): JenkinsServiceFactory = | |
DefaultJenkinsServiceFactory() | |
@Bean | |
fun jenkinsMasters(buildMasters: BuildMasters, | |
igorConfigurationProperties: IgorConfigurationProperties, | |
@Valid jenkinsProperties: JenkinsProperties, | |
jenkinsClientFactory: JenkinsClientFactory, | |
jenkinsServiceFactory: JenkinsServiceFactory, | |
registry: Registry): Map<String, JenkinsService> { | |
log.info("creating jenkinsMasters") | |
return jenkinsProperties?.masters | |
?.map { host -> | |
val client = Proxy.newProxyInstance( | |
JenkinsClient.classLoader, | |
[JenkinsClient] as Class[], | |
InstrumentedProxy( | |
registry, | |
jenkinsClientFactory.build( | |
host, | |
jenkinsOkHttpClientProvider.provide(host), | |
jenkinsRetrofitRequestInterceptorProvider.provide(host), | |
igorConfigurationProperties.client.timeout | |
), | |
"jenkinsClient", | |
mapOf("master" to host.name) | |
) | |
) | |
Pair( | |
host.name, | |
jenkinsServiceFactory.build( | |
host.name, | |
client, | |
host.csrf | |
) | |
) | |
} | |
.toMap() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment