-
Notifications
You must be signed in to change notification settings - Fork 80
Make expiration of URLs configurable #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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 { | ||
| return toExternalURL(blob, httpMethod, Duration.ofSeconds(SystemProperties.getInteger(BlobStoreProvider.class.getName() + ".DEFAULT_DURATION_SECONDS", 3600))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| } | ||
|
|
||
| public abstract URL toExternalURL(Blob blob, HttpMethod httpMethod, Duration duration) throws IOException; | ||
|
|
||
| @Override | ||
| public BlobStoreProviderDescriptor getDescriptor() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()) { | ||
| throw new IllegalArgumentException("Expiration time must be greater than zero for PUT"); | ||
| } | ||
| // 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) | ||
|
|
@@ -259,6 +261,9 @@ | |
| .putObjectRequest(putObjectRequest).build(); | ||
| return presigner.presignPutObject(putObjectPresignRequest).url(); | ||
| case GET: | ||
| if (expiration.isZero()) { | ||
| return blob.getMetadata().getUri().toURL(); | ||
| } | ||
|
Comment on lines
+264
to
+266
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(container).key(name).build(); | ||
| GetObjectPresignRequest getObjectPresignRequest = GetObjectPresignRequest.builder() | ||
| .signatureDuration(expiration) | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this duration? Why is it not configurable? |
||
| } | ||
| } | ||
| return artifactUrls; | ||
|
|
||
There was a problem hiding this comment.
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.