-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implemented an endpoint to handle file uploads #117
Open
this-Aditya
wants to merge
27
commits into
main
Choose a base branch
from
file-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d80f24e
Config files for s3 storage added
this-Aditya ab3fc8b
Gateway config merged with storage config and added conditional config
this-Aditya eee2d9c
Custom exception classes added
this-Aditya 9b28499
New dependencies for min-io and multipart form handling
this-Aditya 6c8f2a1
Resource enhancers for file storage created
this-Aditya 9be4953
Path utils added
this-Aditya e5e0211
Minio loader created
this-Aditya 7257a34
FileUploadResource added
this-Aditya dd95ffe
Filter created for blocking requests when file uploading is disabled
this-Aditya f3f0f3e
Added storage path
this-Aditya 1bb7b1c
Created test case for storage path test
this-Aditya b4aa35a
Storage service and its test class added
this-Aditya 23c6245
Updates to configuration files
this-Aditya 7264ff9
Misc changes
this-Aditya be49bde
Changes for passing checks
this-Aditya dbeebf0
Fix ktlint
this-Aditya e63e4a8
Fix deprecated GitHub Action in workflow
this-Aditya f58350c
Using config values from environment variables if null
this-Aditya a5d26a4
Refactored builder pattern of StoragePath to data class
this-Aditya 0284dda
RadarMinioClientLoader transformed to disposable supplier
this-Aditya 8165dee
Misc changes
this-Aditya 0e3e757
Using form params instead of path params
this-Aditya e72feca
Upated path annotation
this-Aditya 1f60698
Added authentication and permissions on resource
this-Aditya f92588a
Handling aws regions for minio-client
this-Aditya 11dba32
Corrected environment variables
this-Aditya 3274ed0
Codestyle fix
this-Aditya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
radar-gateway/src/main/kotlin/org/radarbase/gateway/config/S3StorageConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.radarbase.gateway.config | ||
|
||
import org.radarbase.gateway.utils.Env.AWS_ACCESS_KEY_ID | ||
import org.radarbase.gateway.utils.Env.AWS_DEFAULT_REGION | ||
import org.radarbase.gateway.utils.Env.AWS_ENDPOINT_URL_S3 | ||
import org.radarbase.gateway.utils.Env.AWS_S3_BUCKET_NAME | ||
import org.radarbase.gateway.utils.Env.AWS_SECRET_ACCESS_KEY | ||
|
||
data class S3StorageConfig( | ||
var url: String? = null, | ||
var accessKey: String? = null, | ||
var secretKey: String? = null, | ||
var bucketName: String? = null, | ||
var region: String? = null, | ||
var path: S3StoragePathConfig = S3StoragePathConfig(), | ||
) { | ||
fun checkEnvironmentVars() { | ||
url ?: run { | ||
url = System.getenv(AWS_ENDPOINT_URL_S3) | ||
} | ||
accessKey ?: run { | ||
accessKey = System.getenv(AWS_ACCESS_KEY_ID) | ||
} | ||
secretKey ?: run { | ||
secretKey = System.getenv(AWS_SECRET_ACCESS_KEY) | ||
} | ||
bucketName ?: run { | ||
bucketName = System.getenv(AWS_S3_BUCKET_NAME) | ||
} | ||
region ?: run { | ||
region = System.getenv(AWS_DEFAULT_REGION) | ||
} | ||
path.checkEnvironmentVars() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
radar-gateway/src/main/kotlin/org/radarbase/gateway/config/S3StoragePathConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.radarbase.gateway.config | ||
|
||
import org.radarbase.gateway.utils.Env.AWS_S3_PATH_PREFIX | ||
|
||
data class S3StoragePathConfig( | ||
var prefix: String? = null, | ||
var collectPerDay: Boolean = true, | ||
) { | ||
fun checkEnvironmentVars() { | ||
prefix ?: run { | ||
prefix = System.getenv(AWS_S3_PATH_PREFIX) | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
radar-gateway/src/main/kotlin/org/radarbase/gateway/config/StorageConditionConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.radarbase.gateway.config | ||
|
||
data class StorageConditionConfig( | ||
val fileUploadEnabled: Boolean = true, | ||
val radarStorageType: String = "s3", | ||
) |
11 changes: 11 additions & 0 deletions
11
radar-gateway/src/main/kotlin/org/radarbase/gateway/exception/FileStorageException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.radarbase.gateway.exception | ||
|
||
import jakarta.ws.rs.core.Response | ||
import org.radarbase.jersey.exception.HttpApplicationException | ||
|
||
class FileStorageException(message: String) : | ||
HttpApplicationException( | ||
Response.Status.INTERNAL_SERVER_ERROR, | ||
Response.Status.INTERNAL_SERVER_ERROR.name.lowercase(), | ||
message, | ||
) |
11 changes: 11 additions & 0 deletions
11
radar-gateway/src/main/kotlin/org/radarbase/gateway/exception/InvalidFileDetailsException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.radarbase.gateway.exception | ||
|
||
import jakarta.ws.rs.core.Response | ||
import org.radarbase.jersey.exception.HttpApplicationException | ||
|
||
class InvalidFileDetailsException(message: String) : | ||
HttpApplicationException( | ||
Response.Status.EXPECTATION_FAILED, | ||
Response.Status.EXPECTATION_FAILED.name.lowercase(), | ||
message, | ||
) |
11 changes: 11 additions & 0 deletions
11
radar-gateway/src/main/kotlin/org/radarbase/gateway/exception/InvalidPathDetailsException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.radarbase.gateway.exception | ||
|
||
import jakarta.ws.rs.core.Response | ||
import org.radarbase.jersey.exception.HttpApplicationException | ||
|
||
class InvalidPathDetailsException(message: String) : | ||
HttpApplicationException( | ||
Response.Status.EXPECTATION_FAILED, | ||
Response.Status.EXPECTATION_FAILED.name.lowercase(), | ||
message, | ||
) |
31 changes: 31 additions & 0 deletions
31
radar-gateway/src/main/kotlin/org/radarbase/gateway/filter/FileUploadFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.radarbase.gateway.filter | ||
|
||
import jakarta.annotation.Priority | ||
import jakarta.inject.Singleton | ||
import jakarta.ws.rs.Priorities | ||
import jakarta.ws.rs.container.ContainerRequestContext | ||
import jakarta.ws.rs.container.ContainerRequestFilter | ||
import jakarta.ws.rs.core.Context | ||
import jakarta.ws.rs.core.Response | ||
import jakarta.ws.rs.ext.Provider | ||
import org.radarbase.gateway.config.GatewayConfig | ||
import org.radarbase.gateway.inject.ProcessFileUpload | ||
|
||
@Provider | ||
@Singleton | ||
@Priority(Priorities.USER) | ||
@ProcessFileUpload | ||
class FileUploadFilter( | ||
@Context private val config: GatewayConfig, | ||
) : ContainerRequestFilter { | ||
|
||
override fun filter(requestContext: ContainerRequestContext?) { | ||
if (!config.storageCondition.fileUploadEnabled) { | ||
requestContext?.abortWith( | ||
Response.status(Response.Status.FORBIDDEN) | ||
.entity("File uploading is not configured") | ||
.build(), | ||
) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
radar-gateway/src/main/kotlin/org/radarbase/gateway/inject/FileStorageEnhancer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.radarbase.gateway.inject | ||
|
||
import jakarta.inject.Singleton | ||
import org.glassfish.jersey.internal.inject.AbstractBinder | ||
import org.glassfish.jersey.media.multipart.MultiPartFeature | ||
import org.radarbase.gateway.config.GatewayConfig | ||
import org.radarbase.gateway.config.S3StorageConfig | ||
import org.radarbase.gateway.service.storage.RadarMinioClient | ||
import org.radarbase.gateway.service.storage.RadarMinioClientFactory | ||
import org.radarbase.gateway.service.storage.S3StorageService | ||
import org.radarbase.gateway.service.storage.StorageService | ||
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer | ||
|
||
class FileStorageEnhancer( | ||
private val config: GatewayConfig, | ||
) : JerseyResourceEnhancer { | ||
|
||
override val classes: Array<Class<*>> = buildList(1) { | ||
add(MultiPartFeature::class.java) | ||
}.toTypedArray() | ||
|
||
override fun AbstractBinder.enhance() { | ||
bind(config.s3) | ||
.to(S3StorageConfig::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
if (config.storageCondition.radarStorageType == "s3") { | ||
bindFactory(RadarMinioClientFactory::class.java) | ||
.to(RadarMinioClient::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
bind(S3StorageService::class.java) | ||
.to(StorageService::class.java) | ||
.`in`(Singleton::class.java) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
radar-gateway/src/main/kotlin/org/radarbase/gateway/inject/ProcessFileUpload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.radarbase.gateway.inject | ||
|
||
import jakarta.ws.rs.NameBinding | ||
|
||
@NameBinding | ||
@Target( | ||
AnnotationTarget.CLASS, | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.PROPERTY_SETTER, | ||
) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class ProcessFileUpload |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wondered if we should utilise functionality from radar-output's path factory (it would be good to harmonise across components). We can likely extract that bit of functionality from radar output to the radar-commons library and re-use in both components. Let's discuss in the next meeting
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.
And this can be tackled in a separate issue and PR
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.
Okay