-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify, create and delete integration tests
- Loading branch information
Showing
11 changed files
with
166 additions
and
47 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
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/stabledata/endpoint/AccessDeleteRoute.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,57 @@ | ||
package com.stabledata.endpoint | ||
|
||
import com.stabledata.Ably | ||
import com.stabledata.dao.AccessTable | ||
import com.stabledata.dao.LogsTable | ||
import com.stabledata.endpoint.io.AccessRequest | ||
import com.stabledata.plugins.JWT_NAME | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.auth.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import org.jetbrains.exposed.exceptions.ExposedSQLException | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
|
||
fun Application.configureAccessDeleteRoute() { | ||
|
||
val logger = KotlinLogging.logger {} | ||
|
||
routing { | ||
authenticate(JWT_NAME) { | ||
post("access/delete") { | ||
val (access, user, envelope, logEntry) = contextualize( | ||
"access/manage" | ||
) { postData -> | ||
AccessRequest.fromJSON(postData) | ||
} ?: return@post | ||
|
||
// slightly borrowed, but not crazy use case issues in logs anyway | ||
logEntry.path("delete") | ||
|
||
logger.debug { "All access records removal requested by ${user.id} with event id ${envelope.eventId}" } | ||
|
||
try { | ||
val finalLogEntry = logEntry.build() | ||
transaction { | ||
AccessTable.deleteRulesForOperationAndRole(user.team, access.role, access.path) | ||
LogsTable.insertLogEntry(finalLogEntry) | ||
Ably.publish(user.team, "access/delete", finalLogEntry) | ||
} | ||
|
||
logger.debug {"Access control record deleted for role ${access.role} on path ${access.path}" } | ||
|
||
return@post call.respond( | ||
HttpStatusCode.Created, | ||
finalLogEntry | ||
) | ||
|
||
} catch (e: ExposedSQLException) { | ||
logger.error { "Delete access record failed: ${e.localizedMessage}" } | ||
return@post call.respond(HttpStatusCode.InternalServerError, e.localizedMessage) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"format": "uuid", | ||
"description": "Unique identifier access control record" | ||
}, | ||
"role": { | ||
"type": "string", | ||
"description": "Role associated with this access entry" | ||
}, | ||
"path": { | ||
"type": "string", | ||
"description": "Path to the resource (or operation) for which access is granted or denied" | ||
} | ||
}, | ||
"required": ["id", "role", "path"], | ||
"additionalProperties": false | ||
} |
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