Skip to content

Commit 7934127

Browse files
committed
chore(openapi): add new objects endpoint
1 parent 2db8b16 commit 7934127

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

api/model-server.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ paths:
5454
responses:
5555
"200":
5656
$ref: '#/components/responses/200'
57+
/v2/repositories/{repository}/objects:
58+
put:
59+
operationId: putRepositoryObjects
60+
parameters:
61+
- name: repository
62+
in: "path"
63+
required: true
64+
schema:
65+
type: string
66+
responses:
67+
"403":
68+
$ref: '#/components/responses/403'
69+
"401":
70+
$ref: '#/components/responses/401'
71+
"500":
72+
$ref: '#/components/responses/500'
73+
"200":
74+
$ref: '#/components/responses/200json'
5775
/v2/repositories/{repository}/branches:
5876
get:
5977
operationId: getRepositoryBranches

model-server/src/main/kotlin/org/modelix/model/server/handlers/ModelReplicationServer.kt

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,32 +275,30 @@ class ModelReplicationServer(val repositoriesManager: RepositoriesManager) {
275275
ModelQLServer.handleCall(call, branch.getRootNode(), branch.getArea())
276276
}
277277

278-
// route("objects") {
279-
// put {
280-
// val writtenEntries = withContext(Dispatchers.IO) {
281-
// val entries = call.receiveStream().bufferedReader().use { reader ->
282-
// reader.lineSequence().windowed(2, 2).map {
283-
// val key = it[0]
284-
// val value = it[1]
285-
//
286-
// require(HashUtil.isSha256(key)) {
287-
// "This API cannot be used to store other entries than serialized objects." +
288-
// " The key is expected to be a SHA256 hash over the value: $key -> $value"
289-
// }
290-
// val expectedKey = HashUtil.sha256(value)
291-
// require(expectedKey == key) { "Hash mismatch. Expected $expectedKey, but $key was provided. Value: $value" }
292-
//
293-
// key to value
294-
// }.toMap()
295-
// }
296-
//
297-
// storeClient.putAll(entries, true)
298-
//
299-
// entries.size
300-
// }
301-
// call.respondText("$writtenEntries objects received")
302-
// }
303-
// }
278+
put<Paths.putRepositoryObjects> {
279+
val writtenEntries = withContext(Dispatchers.IO) {
280+
val entries = call.receiveStream().bufferedReader().use { reader ->
281+
reader.lineSequence().windowed(2, 2).map {
282+
val key = it[0]
283+
val value = it[1]
284+
285+
require(HashUtil.isSha256(key)) {
286+
"This API cannot be used to store other entries than serialized objects." +
287+
" The key is expected to be a SHA256 hash over the value: $key -> $value"
288+
}
289+
val expectedKey = HashUtil.sha256(value)
290+
require(expectedKey == key) { "Hash mismatch. Expected $expectedKey, but $key was provided. Value: $value" }
291+
292+
key to value
293+
}.toMap()
294+
}
295+
296+
storeClient.putAll(entries, true)
297+
298+
entries.size
299+
}
300+
call.respondText("$writtenEntries objects received")
301+
}
304302

305303
get<Paths.getVersionHash> {
306304
// TODO versions should be stored inside a repository with permission checks.

0 commit comments

Comments
 (0)