Skip to content

Commit

Permalink
fix: Secure all the endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
andacata committed Jan 9, 2024
1 parent 312ebfc commit 0b179cf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class CredentialsServer(
override suspend fun registerOn(transportServer: TransportServer) {
transportServer.handle(
method = HttpMethod.GET,
path = basePathSegments,
secured = false
path = basePathSegments
) { req ->
req.httpResponse {
service.get(
Expand All @@ -25,8 +24,7 @@ class CredentialsServer(

transportServer.handle(
method = HttpMethod.POST,
path = basePathSegments,
secured = false
path = basePathSegments
) { req ->
req.httpResponse {
service.post(
Expand All @@ -39,8 +37,7 @@ class CredentialsServer(

transportServer.handle(
method = HttpMethod.PUT,
path = basePathSegments,
secured = false
path = basePathSegments
) { req ->
req.httpResponse {
service.put(
Expand All @@ -53,8 +50,7 @@ class CredentialsServer(

transportServer.handle(
method = HttpMethod.DELETE,
path = basePathSegments,
secured = false
path = basePathSegments
) { req ->
req.httpResponse {
service.delete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Http4kTransportServer(
method: HttpMethod,
path: List<PathSegment>,
queryParams: List<String>,
secured: Boolean,
filters: List<(request: HttpRequest) -> Unit>,
callback: suspend (request: HttpRequest) -> HttpResponse
) {
Expand Down Expand Up @@ -60,7 +59,7 @@ class Http4kTransportServer(
body = req.bodyString()
)
.also { httpRequest ->
if (secured) runBlocking { secureFilter(httpRequest) }
runBlocking { secureFilter(httpRequest) }
}
.also { httpRequest -> filters.forEach { filter -> filter(httpRequest) } }
.let { httpRequest ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface TransportServer {
method: HttpMethod,
path: List<PathSegment>,
queryParams: List<String> = emptyList(),
secured: Boolean = true,
filters: List<(request: HttpRequest) -> Unit> = emptyList(),
callback: suspend (request: HttpRequest) -> HttpResponse
)
Expand Down

0 comments on commit 0b179cf

Please sign in to comment.