-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get access key from request and read valid access keys from file
issue: #218
- Loading branch information
1 parent
aff116c
commit 4e07a6b
Showing
14 changed files
with
395 additions
and
48 deletions.
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
23 changes: 23 additions & 0 deletions
23
lapis2/src/main/kotlin/org/genspectrum/lapis/config/AccessKeys.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,23 @@ | ||
package org.genspectrum.lapis.config | ||
|
||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import org.genspectrum.lapis.util.YamlObjectMapper | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
import java.io.File | ||
|
||
@Component | ||
class AccessKeysReader( | ||
@Value("\${lapis.accessKeys.path:#{null}}") private val accessKeysFile: String?, | ||
private val yamlObjectMapper: YamlObjectMapper, | ||
) { | ||
fun read(): AccessKeys { | ||
if (accessKeysFile == null) { | ||
throw IllegalArgumentException("Cannot read LAPIS access keys, lapis.accessKeys.path was not set.") | ||
} | ||
|
||
return yamlObjectMapper.objectMapper.readValue(File(accessKeysFile)) | ||
} | ||
} | ||
|
||
data class AccessKeys(val fullAccessKey: String, val aggregatedDataAccessKey: String) |
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
46 changes: 46 additions & 0 deletions
46
lapis2/src/main/kotlin/org/genspectrum/lapis/util/CachedBodyHttpServletRequest.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,46 @@ | ||
package org.genspectrum.lapis.util | ||
|
||
import jakarta.servlet.ReadListener | ||
import jakarta.servlet.ServletInputStream | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletRequestWrapper | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import java.io.IOException | ||
import java.io.InputStream | ||
|
||
class CachedBodyHttpServletRequest(request: HttpServletRequest) : HttpServletRequestWrapper(request) { | ||
private val cachedBody: ByteArray by lazy { | ||
val inputStream: InputStream = request.inputStream | ||
val byteArrayOutputStream = ByteArrayOutputStream() | ||
|
||
inputStream.copyTo(byteArrayOutputStream) | ||
byteArrayOutputStream.toByteArray() | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun getInputStream(): ServletInputStream { | ||
return CachedBodyServletInputStream(ByteArrayInputStream(cachedBody)) | ||
} | ||
|
||
private inner class CachedBodyServletInputStream(private val cachedInputStream: ByteArrayInputStream) : | ||
ServletInputStream() { | ||
|
||
override fun isFinished(): Boolean { | ||
return cachedInputStream.available() == 0 | ||
} | ||
|
||
override fun isReady(): Boolean { | ||
return true | ||
} | ||
|
||
override fun setReadListener(listener: ReadListener) { | ||
throw UnsupportedOperationException("setReadListener is not supported") | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun read(): Int { | ||
return cachedInputStream.read() | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lapis2/src/main/kotlin/org/genspectrum/lapis/util/YamlObjectMapper.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.genspectrum.lapis.util | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
object YamlObjectMapper { | ||
val objectMapper: ObjectMapper = ObjectMapper(YAMLFactory()).registerKotlinModule() | ||
} |
Oops, something went wrong.