public InputStream getContent()

in s3-artifact-storage-server/src/main/java/jetbrains/buildServer/artifacts/s3/S3ArtifactContentProvider.java [44:83]


  public InputStream getContent(@NotNull StoredBuildArtifactInfo storedBuildArtifactInfo) throws IOException {
    final Map<String, String> params;
    final ArtifactData artifactData = storedBuildArtifactInfo.getArtifactData();
    if (artifactData == null) {
      throw new IOException("Invalid artifact data: S3 object path property is not set");
    }

    final String artifactPath = artifactData.getPath();
    try {
      params = S3Util.validateParameters(storedBuildArtifactInfo.getStorageSettings());
    } catch (IllegalArgumentException e) {
      throw new IOException("Failed to get artifact " + artifactPath + " content: Invalid storage settings " + e.getMessage(), e);
    }

    final String bucketName = S3Util.getBucketName(params);
    final String key = S3Util.getPathPrefix(storedBuildArtifactInfo.getCommonProperties()) + artifactPath;

    try {
      String projectId = storedBuildArtifactInfo.getBuildPromotion().getProjectId();
      if (projectId == null) {
        throw new ConnectionCredentialsException("There is no project information in the build : " + storedBuildArtifactInfo.getBuildPromotion().getBuildTypeExternalId() + " S3 bucket: " + bucketName);
      }

      return myAmazonS3Provider.withCorrectingRegionAndAcceleration(
        ParamUtil.putSslValues(myServerPaths, params),
        projectId,
        client -> client.getObject(b -> b.bucket(bucketName).key(key)), false);
    } catch (Throwable t) {
      final AWSException awsException = new AWSException(t);
      final String details = awsException.getDetails();
      if (StringUtil.isNotEmpty(details)) {
        final String message = awsException.getMessage() + details;
        LOG.warn(message);
      }
      throw new IOException(String.format(
        "Failed to get artifact '%s' content in bucket '%s': %s",
        artifactPath, bucketName, awsException.getMessage()
      ), awsException);
    }
  }