/*
 * 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.clouddriver.controllers;

import com.netflix.spinnaker.clouddriver.artifacts.ArtifactCredentialsRepository;
import com.netflix.spinnaker.clouddriver.artifacts.config.ArtifactCredentials;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/artifacts")
public class ArtifactController {
  private ArtifactCredentialsRepository artifactCredentialsRepository;

  @Autowired(required = false)
  public ArtifactController(ArtifactCredentialsRepository artifactCredentialsRepository) {
    this.artifactCredentialsRepository = artifactCredentialsRepository;
  }

  @RequestMapping(method = RequestMethod.GET, value = "/credentials")
  List<ArtifactCredentials> list() {
    return artifactCredentialsRepository.getAllCredentials();
  }
}

@@ -1112,20 +1112,75 @@
 va.util.
-List
+ArrayList;%0Aimport java.util.List;%0Aimport java.util.Optional
 ;%0A%0A@Slf4
@@ -1349,26 +1349,8 @@
 ired
-(required = false)
 %0A  p
@@ -1374,16 +1374,25 @@
 troller(
+Optional%3C
 Artifact
@@ -1404,32 +1404,33 @@
 ntialsRepository
+%3E
  artifactCredent
@@ -1517,16 +1517,29 @@
 pository
+.orElse(null)
 ;%0A  %7D%0A%0A 
@@ -1640,24 +1640,120 @@
 s%3E list() %7B%0A
+    if (artifactCredentialsRepository == null) %7B%0A      return new ArrayList%3C%3E();%0A    %7D else %7B%0A  
     return a
@@ -1802,14 +1802,20 @@
 ials();%0A
+    %7D%0A
   %7D%0A%7D%0A

make constructor bean optional (#2247)