/*
 * Copyright 2017 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.config;

import com.netflix.spinnaker.clouddriver.artifacts.ArtifactCredentialsRepository;
import com.netflix.spinnaker.clouddriver.artifacts.config.ArtifactAccount;
import com.netflix.spinnaker.clouddriver.artifacts.config.ArtifactCredentials;
import com.netflix.spinnaker.credentials.CredentialsTypeBaseConfiguration;
import com.netflix.spinnaker.credentials.CredentialsTypeProperties;
import com.squareup.okhttp.OkHttpClient;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

@Configuration
@EnableConfigurationProperties
@EnableScheduling
@Component
@ComponentScan("com.netflix.spinnaker.clouddriver.artifacts")
public class ArtifactConfiguration {
  @Bean
  OkHttpClient okHttpClient() {
    return new OkHttpClient();
  }

  @Bean
  public ArtifactCredentialsRepository artifactCredentialsRepository(
      ApplicationContext applicationContext,
      List<CredentialsTypeProperties<? extends ArtifactCredentials, ? extends ArtifactAccount>>
          credentialsTypes) {
    return new ArtifactCredentialsRepository(
        credentialsTypes.stream()
            .map(c -> new CredentialsTypeBaseConfiguration<>(applicationContext, c))
            .peek(CredentialsTypeBaseConfiguration::afterPropertiesSet)
            .map(CredentialsTypeBaseConfiguration::getCredentialsRepository)
            .collect(Collectors.toList()));
  }
}

@@ -862,16 +862,80 @@
 ntials;%0A
+import com.netflix.spinnaker.credentials.CredentialsRepository;%0A
 import c
@@ -2092,34 +2092,146 @@
 alsTypes
-) %7B%0A    return new
+,%0A      List%3CCredentialsRepository%3C? extends ArtifactCredentials%3E%3E defaultRepositories) %7B%0A    List%3CCredentialsRepository%3C? extends
  Artifac
@@ -2238,33 +2238,36 @@
 tCredentials
-R
+%3E%3E r
 epositor
 y(%0A        c
@@ -2250,26 +2250,29 @@
 %3E%3E repositor
-y(
+ies =
 %0A        cre
@@ -2569,16 +2569,122 @@
 oList())
+;%0A%0A    repositories.addAll(defaultRepositories);%0A    return new ArtifactCredentialsRepository(repositories
 );%0A  %7D%0A%7D

Fix default artifact credentials repositories (#5203)