Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.io.Serializable;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

import jenkins.util.SystemProperties;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
Expand Down Expand Up @@ -95,7 +97,11 @@ public enum HttpMethod {
* @throws IOException
*/
@NonNull
public abstract URL toExternalURL(@NonNull Blob blob, @NonNull HttpMethod httpMethod) throws IOException;
public URL toExternalURL(@NonNull Blob blob, @NonNull HttpMethod httpMethod) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not implemented externally, no need to offer a compat layer.

return toExternalURL(blob, httpMethod, Duration.ofSeconds(SystemProperties.getInteger(BlobStoreProvider.class.getName() + ".DEFAULT_DURATION_SECONDS", 3600)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SystemProperties.getDuration.

}

public abstract URL toExternalURL(Blob blob, HttpMethod httpMethod, Duration duration) throws IOException;

@Override
public BlobStoreProviderDescriptor getDescriptor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -43,6 +44,7 @@
import java.util.logging.Logger;
import java.util.stream.StreamSupport;

import jenkins.util.SystemProperties;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStores;
Expand Down Expand Up @@ -150,7 +152,7 @@ public URI toURI() {

@Override
public URL toExternalURL() throws IOException {
return provider.toExternalURL(getBlob(), HttpMethod.GET);
return provider.toExternalURL(getBlob(), HttpMethod.GET, Duration.ofSeconds(SystemProperties.getInteger(JCloudsVirtualFile.class.getName() + ".EXPIRATION_SECONDS", 60)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,17 @@
return presignerBuilder.build();
}

private URL toExternalURL(@NonNull Blob blob, @NonNull HttpMethod httpMethod, S3Presigner presigner) throws IOException {
Duration expiration = Duration.ofHours(1);
private URL toExternalURL(@NonNull Blob blob, @NonNull HttpMethod httpMethod, S3Presigner presigner, @NonNull Duration expiration) throws IOException {
String container = blob.getMetadata().getContainer();
String name = blob.getMetadata().getName();
LOGGER.log(Level.FINE, "Generating presigned URL for {0} / {1} for method {2}",
new Object[]{container, name, httpMethod});
String contentType;
switch (httpMethod) {
case PUT:
if (expiration.isZero()) {

Check warning on line 250 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStore.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 250 is only partially covered, one branch is missing
throw new IllegalArgumentException("Expiration time must be greater than zero for PUT");

Check warning on line 251 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStore.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 251 is not covered by tests
}
// Only set content type for upload URLs, so that the right S3 metadata gets set
contentType = blob.getMetadata().getContentMetadata().getContentType();
PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(container)
Expand All @@ -259,6 +261,9 @@
.putObjectRequest(putObjectRequest).build();
return presigner.presignPutObject(putObjectPresignRequest).url();
case GET:
if (expiration.isZero()) {

Check warning on line 264 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStore.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 264 is only partially covered, one branch is missing
return blob.getMetadata().getUri().toURL();

Check warning on line 265 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStore.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 265 is not covered by tests
}
Comment on lines +264 to +266
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#660 / #781 I guess? I would rather not include this here as it does not seem necessary and would require dedicated testing with a public bucket.

GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(container).key(name).build();
GetObjectPresignRequest getObjectPresignRequest = GetObjectPresignRequest.builder()
.signatureDuration(expiration)
Expand All @@ -274,10 +279,10 @@
* Pre-signed Object URL using AWS SDK for Java</a>
*/
@Override
public URL toExternalURL(@NonNull Blob blob, @NonNull HttpMethod httpMethod) throws IOException {
public URL toExternalURL(@NonNull Blob blob, @NonNull HttpMethod httpMethod, Duration expiration) throws IOException {
try (S3Client s3Client = getConfiguration().getAmazonS3ClientBuilderWithCredentials().build();
S3Presigner presigner = getS3Presigner(s3Client)) {
return toExternalURL(blob, httpMethod, presigner);
return toExternalURL(blob, httpMethod, presigner, expiration);
}
}

Expand All @@ -293,7 +298,7 @@
Blob blob = blobStore.blobBuilder(blobPath).build();
blob.getMetadata().setContainer(this.getContainer());
blob.getMetadata().getContentMetadata().setContentType(contentTypes.get(entry.getValue()));
artifactUrls.put(entry.getValue(), this.toExternalURL(blob, HttpMethod.PUT, s3Presigner));
artifactUrls.put(entry.getValue(), this.toExternalURL(blob, HttpMethod.PUT, s3Presigner, Duration.ofHours(1)));

Check warning on line 301 in src/main/java/io/jenkins/plugins/artifact_manager_jclouds/s3/S3BlobStore.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 301 is not covered by tests
Copy link
Member

@jglick jglick Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this duration? Why is it not configurable?

}
}
return artifactUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
Expand Down Expand Up @@ -153,7 +154,7 @@ public URI toURI(String container, String key) {
}

@Override
public URL toExternalURL(Blob blob, HttpMethod httpMethod) throws IOException {
public URL toExternalURL(Blob blob, HttpMethod httpMethod, Duration expiration) throws IOException {
return new URL(baseURL, blob.getMetadata().getContainer() + "/" + blob.getMetadata().getName() + "?method=" + httpMethod);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;

Expand Down Expand Up @@ -78,6 +79,11 @@ public URL toExternalURL(Blob blob, BlobStoreProvider.HttpMethod httpMethod) thr
return delegate.toExternalURL(blob, httpMethod);
}

@Override
public URL toExternalURL(Blob blob, HttpMethod httpMethod, Duration duration) throws IOException {
return delegate.toExternalURL(blob, httpMethod, duration);
}

@Override
public BlobStoreProviderDescriptor getDescriptor() {
return delegate.getDescriptor();
Expand Down
Loading