Skip to content

Commit

Permalink
Merge pull request #13 from Ferlab-Ste-Justine/feat/441-sub-folders-g…
Browse files Browse the repository at this point in the history
…et-file

feat: CLIN-441 - allow sub-folders GET file
  • Loading branch information
creativeyann17 authored Nov 16, 2021
2 parents e33ac4f + aa11d53 commit 01c1c76
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
5 changes: 2 additions & 3 deletions app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents,pe
}

private val bucket = config.get[String]("aws.bucket")
private val prefix = config.get[String]("aws.prefix")

def get(file: String): Action[AnyContent] = authAction { implicit request: UserRequest[AnyContent] =>
val (_, unauthorized) = perms.checkPermissions(request, Set(file))
if (unauthorized.nonEmpty) {
Forbidden(file)
} else {
val url = s3.presignedUrl(bucket, prefix, file)
val url = s3.presignedUrl(bucket, file)
request.getQueryString("format") match {
case Some("json") =>
Ok(Json.toJson(Map("url" -> url.toString)))
Expand All @@ -56,7 +55,7 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents,pe
if (unauthorized.nonEmpty) {
Forbidden(unauthorized.mkString("\n"))
} else {
val urls = authorized.map(file => (file, s3.presignedUrl(bucket, prefix, file).toString)).toMap
val urls = authorized.map(file => (file, s3.presignedUrl(bucket, file).toString)).toMap
Ok(toJson(urls))
}
}
Expand Down
6 changes: 2 additions & 4 deletions app/services/aws/S3Service.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ class S3Service @Inject()(config: Configuration) {
.build()


def presignedUrl(bucket: String, prefix: String, file: String, expiration: Duration = Duration.ofHours(1)): URL = {

val key = if (prefix.isEmpty) file else s"$prefix/$file"
def presignedUrl(bucket: String, file: String, expiration: Duration = Duration.ofHours(1)): URL = {

val getObjectRequest =
GetObjectRequest.builder()
.bucket(bucket)
.key(key)
.key(file)
.build()

val getObjectPresignRequest = GetObjectPresignRequest.builder
Expand Down
2 changes: 0 additions & 2 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ aws{
path_style_access=${?AWS_PATH_ACCESS_STYLE}
bucket="clin-repository"
bucket=${?AWS_BUCKET}
prefix="files"
prefix=${?AWS_PREFIX}
}
auth {
url="https://auth.qa.cqdg.ferlab.bio/auth"
Expand Down
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ GET /config controllers.ConfigController.configu
POST /downloadLinks controllers.HomeController.downloadLinks()
POST /createPermissions/:userName controllers.HomeController.createPermissions(userName:String)
# always at the end of routing otherwise will be always true
GET /:file controllers.HomeController.get(file: String)
GET /*file controllers.HomeController.get(file: String)

0 comments on commit 01c1c76

Please sign in to comment.