Skip to content

Commit

Permalink
Restore GET URL for cookie-authed entity TSV download
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthibault79 committed Jun 20, 2018
1 parent 9a4b860 commit a78144b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
30 changes: 30 additions & 0 deletions src/main/resources/swagger/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3534,6 +3534,36 @@ paths:
500:
description: Internal Server Error
security: []
get:
tags:
- Entities
operationId: browserDownloadEntitiesTSVGet
summary: |
TSV file containing workspace entities of the specified type
description: |
swagger-ui seems to not handle file downloads, so this endpoint won't function through the ui.
It is here for documentation purposes only.
produces:
- text/plain
- application/octet-stream
parameters:
- $ref: '#/parameters/workspaceNamespaceParam'
- $ref: '#/parameters/workspaceNameParam'
- $ref: '#/parameters/entityTypeParam'
- name: attributeNames
description: comma separated list of ordered attribute names to be in downloaded tsv
type: string
in: query
responses:
200:
description: Workspace entities of specified type in TSV format
schema:
type: file
404:
description: Workspace or entity type does not exist
500:
description: Internal Server Error
security: []

/duos/autocomplete/{queryTerm}:
get:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.broadinstitute.dsde.firecloud.webservice

import akka.actor.Props
import com.typesafe.scalalogging.LazyLogging
import org.broadinstitute.dsde.firecloud.dataaccess.HttpGoogleServicesDAO
import org.broadinstitute.dsde.firecloud.model.UserInfo
import org.broadinstitute.dsde.firecloud.service._
import spray.http._
Expand All @@ -24,11 +23,11 @@ trait CookieAuthedApiService extends HttpService with PerRequestCreator with Fir
private def dummyUserInfo(tokenStr: String) = UserInfo("dummy", OAuth2BearerToken(tokenStr), -1, "dummy")

val cookieAuthedRoutes: Route =

// download "proxy" for TSV files
// Note that this endpoint works in the same way as ExportEntitiesApiService tsv download.
path( "cookie-authed" / "workspaces" / Segment / Segment/ "entities" / Segment / "tsv" ) {
(workspaceNamespace, workspaceName, entityType) =>
// download "proxies" for TSV files
// Note that these endpoints work in the same way as ExportEntitiesApiService tsv download.
path( "cookie-authed" / "workspaces" / Segment / Segment/ "entities" / Segment / "tsv" ) { (workspaceNamespace, workspaceName, entityType) =>
// this endpoint allows an arbitrary number of attribute names in the POST body (GAWB-1435)
// but the URL cannot be saved for later use (firecloud-app#80)
post {
formFields('FCtoken, 'attributeNames.?) { (tokenValue, attributeNamesString) => requestContext =>
val attributeNames = attributeNamesString.map(_.split(",").toIndexedSeq)
Expand All @@ -37,6 +36,20 @@ trait CookieAuthedApiService extends HttpService with PerRequestCreator with Fir
val exportProps: Props = ExportEntitiesByTypeActor.props(exportEntitiesByTypeConstructor, exportArgs)
actorRefFactory.actorOf(exportProps) ! ExportEntitiesByTypeActor.ExportEntities
}
} ~
// this endpoint allows saving the URL for later use (firecloud-app#80)
// but it's possible to exceed the maximum URI length by specifying too many attributes (GAWB-1435)
get {
cookie("FCtoken") { tokenCookie =>
parameters('attributeNames.?) { attributeNamesString =>
requestContext =>
val attributeNames = attributeNamesString.map(_.split(",").toIndexedSeq)
val userInfo = dummyUserInfo(tokenCookie.content)
val exportArgs = ExportEntitiesByTypeArguments(requestContext, userInfo, workspaceNamespace, workspaceName, entityType, attributeNames)
val exportProps: Props = ExportEntitiesByTypeActor.props(exportEntitiesByTypeConstructor, exportArgs)
actorRefFactory.actorOf(exportProps) ! ExportEntitiesByTypeActor.ExportEntities
}
}
}
} ~
path( "cookie-authed" / "download" / "b" / Segment / "o" / RestPath ) { (bucket, obj) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.broadinstitute.dsde.firecloud.service

import java.net.URLEncoder
import java.nio.charset.StandardCharsets.UTF_8

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.broadinstitute.dsde.firecloud.dataaccess.MockRawlsDAO
Expand Down Expand Up @@ -246,9 +249,9 @@ class ExportEntitiesByTypeServiceSpec extends BaseServiceSpec with ExportEntitie
}
}

"when calling GET, PUT, PATCH, DELETE on export path" - {
"when calling PUT, PATCH, DELETE on export path" - {
"MethodNotAllowed response is returned" in {
List(HttpMethods.GET, HttpMethods.PUT, HttpMethods.DELETE, HttpMethods.PATCH) map { method =>
List(HttpMethods.PUT, HttpMethods.DELETE, HttpMethods.PATCH) map { method =>
new RequestBuilder(method)(invalidCookieFireCloudEntitiesParticipantSetTSVPath) ~> sealRoute(cookieAuthedRoutes) ~> check {
handled should be(true)
withClue(s"Method $method:") {
Expand All @@ -259,6 +262,23 @@ class ExportEntitiesByTypeServiceSpec extends BaseServiceSpec with ExportEntitie
}
}

"when calling GET on exporting a valid entity type with filtered attributes" - {
"OK response is returned and attributes are filtered" in {
Get(s"$validCookieFireCloudEntitiesLargeSampleTSVPath?attributeNames=${filterProps.mkString(",")}") ~>
dummyUserIdHeaders("1234") ~>
dummyCookieAuthHeaders ~>
sealRoute(cookieAuthedRoutes) ~> check {
handled should be(true)
status should be(OK)
entity shouldNot be(empty) // Entity is the first line of content as output by StreamingActor
chunks shouldNot be(empty) // Chunks has all of the rest of the content, as output by StreamingActor
headers.contains(HttpHeaders.Connection("Keep-Alive")) should be(true)
headers.contains(HttpHeaders.`Content-Disposition`.apply("attachment", Map("filename" -> "sample.txt"))) should be(true)
validateLineCount(chunks, MockRawlsDAO.largeSampleSize)
validateProps(entity)
}
}
}
}

private def validateLineCount(chunks: List[MessageChunk], count: Int): Unit = {
Expand Down

0 comments on commit a78144b

Please sign in to comment.