All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.spinnaker.gate.controllers.ArtifactController Maven / Gradle / Ivy

There is a newer version: 6.64.0
Show newest version
/*
 * 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.gate.controllers;

import com.netflix.spinnaker.gate.services.ArtifactService;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import io.swagger.annotations.ApiOperation;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

@RestController
@RequestMapping("/artifacts")
public class ArtifactController {

  @Autowired private ArtifactService artifactService;

  @ApiOperation(
      value = "Retrieve the list of artifact accounts configured in Clouddriver.",
      response = List.class)
  @RequestMapping(method = RequestMethod.GET, value = "/credentials")
  List all(@RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp) {
    return artifactService.getArtifactCredentials(sourceApp);
  }

  @ApiOperation(value = "Fetch the contents of an artifact", response = StreamingResponseBody.class)
  @RequestMapping(method = RequestMethod.PUT, value = "/fetch")
  StreamingResponseBody fetch(
      @RequestBody Map artifact,
      @RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp) {
    return outputStream -> {
      try (InputStream inputStream = artifactService.getArtifactContents(sourceApp, artifact)) {
        IOUtils.copy(inputStream, outputStream);
      }
    };
  }

  @ApiOperation(value = "Retrieve the list of artifact names that belong to chosen account")
  @RequestMapping(value = "/account/{accountName}/names", method = RequestMethod.GET)
  List artifactNames(
      @PathVariable String accountName,
      @RequestParam String type,
      @RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp) {
    return artifactService.getArtifactNames(sourceApp, accountName, type);
  }

  @ApiOperation(value = "Retrieve the list of artifact versions by account and artifact names")
  @RequestMapping(value = "/account/{accountName}/versions", method = RequestMethod.GET)
  List artifactVersions(
      @PathVariable String accountName,
      @RequestParam String type,
      @RequestParam String artifactName,
      @RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp) {
    return artifactService.getArtifactVersions(sourceApp, accountName, type, artifactName);
  }

  @ApiOperation(
      value = "Retrieve the available artifact versions for an artifact provider and package name",
      notes = "releaseStatus is an optional comma separated list of statuses to filter on.")
  @RequestMapping(value = "/{provider}/{packageName}", method = RequestMethod.GET)
  List getVersionsOfArtifactForProvider(
      @PathVariable String provider,
      @PathVariable String packageName,
      @RequestParam(required = false) String releaseStatus) {
    return artifactService.getVersionsOfArtifactForProvider(provider, packageName, releaseStatus);
  }

  @ApiOperation(
      value = "Retrieve the specified artifact version for an artifact provider and package name")
  @RequestMapping(value = "/{provider}/{packageName}/{version:.+}", method = RequestMethod.GET)
  Map getArtifact(
      @PathVariable String provider,
      @PathVariable String packageName,
      @PathVariable String version) {
    return artifactService.getArtifactByVersion(provider, packageName, version);
  }

  @ApiOperation(value = "Retrieve artifact by content hash")
  @RequestMapping(value = "/content-address/{application}/{hash}", method = RequestMethod.GET)
  Artifact.StoredView getStoredArtifact(
      @PathVariable(value = "application") String application,
      @PathVariable(value = "hash") String hash) {
    return artifactService.getStoredArtifact(application, hash);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy