Skip to content

Commit

Permalink
feat: add access key parameter to /sample/info and remove downloadAsFile
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Feb 12, 2024
1 parent 1402019 commit 340f2ac
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.genspectrum.lapis.openApi

import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.parameters.Parameter
import org.genspectrum.lapis.config.DatabaseConfig
import org.genspectrum.lapis.config.OpennessLevel
import org.genspectrum.lapis.controller.ACCESS_KEY_PROPERTY
import org.genspectrum.lapis.controller.INFO_ROUTE
import org.springdoc.core.customizers.OpenApiCustomizer
import org.springframework.stereotype.Component

@Component
class AccessKeyParameterCustomizer(
private val databaseConfig: DatabaseConfig,
) : OpenApiCustomizer {
companion object {
private val PATH_WITH_ACCESS_KEY_PARAMETER = listOf(
"/sample$INFO_ROUTE",
)
}

override fun customise(openApi: OpenAPI) {
if (databaseConfig.schema.opennessLevel == OpennessLevel.OPEN) {
return
}

for ((_, path) in openApi.paths.filter { (url, _) ->
PATH_WITH_ACCESS_KEY_PARAMETER.any {
url.startsWith(it)
}
}) {
path.get.addParametersItem(
Parameter()
.`in`("query")
.name(ACCESS_KEY_PROPERTY)
.description(ACCESS_KEY_DESCRIPTION)
.schema(accessKeySchema()),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ package org.genspectrum.lapis.openApi
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.parameters.Parameter
import org.genspectrum.lapis.controller.DOWNLOAD_AS_FILE_PROPERTY
import org.genspectrum.lapis.controller.INFO_ROUTE
import org.springdoc.core.customizers.OpenApiCustomizer
import org.springframework.stereotype.Component

@Component
class DownloadAsFileParameterCustomizer : OpenApiCustomizer {
companion object {
private val PATH_WITHOUT_DOWNLOAD_AS_FILE = listOf(
"/sample$INFO_ROUTE",
)
}

override fun customise(openApi: OpenAPI) {
for ((_, path) in openApi.paths.filter { (url, _) -> url.startsWith("/sample") }) {
for ((_, path) in openApi.paths.filter { (url, _) ->
url.startsWith("/sample") && !PATH_WITHOUT_DOWNLOAD_AS_FILE.any {
url.startsWith(it)
}
}) {
path.get.addParametersItem(
Parameter()
.`in`("query")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,7 @@ private fun getAggregatedResponseProperties(filterProperties: Map<SequenceFilter
COUNT_PROPERTY to IntegerSchema().description("The number of sequences matching the filters."),
)

private fun accessKeySchema() =
StringSchema()
.description(
"An access key that grants access to the protected data that this instance serves. " +
"There are two types or access keys: One only grants access to aggregated data, " +
"the other also grants access to detailed data.",
)
fun accessKeySchema() = StringSchema().description(ACCESS_KEY_DESCRIPTION)

private fun nucleotideMutationProportionSchema() =
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ Set to true to make your browser trigger a download instead of showing the respo
'Content-Disposition' header to 'attachment'.
"""

const val ACCESS_KEY_DESCRIPTION = """
An access key that grants access to the protected data that this instance serves.
There are two types or access keys: One only grants access to aggregated data,
the other also grants access to detailed data.
"""

@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Operation
Expand Down

0 comments on commit 340f2ac

Please sign in to comment.