Skip to content

Commit 26cd287

Browse files
committed
Rename object storage API to reflect object nomenclature
1 parent c93c0c1 commit 26cd287

File tree

8 files changed

+46
-44
lines changed

8 files changed

+46
-44
lines changed

console/src/main/kotlin/app/accrescent/parcelo/console/Application.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import app.accrescent.parcelo.console.jobs.configureJobRunr
99
import app.accrescent.parcelo.console.publish.PublishService
1010
import app.accrescent.parcelo.console.publish.S3PublishService
1111
import app.accrescent.parcelo.console.routes.auth.configureAuthentication
12-
import app.accrescent.parcelo.console.storage.FileStorageService
13-
import app.accrescent.parcelo.console.storage.S3FileStorageService
12+
import app.accrescent.parcelo.console.storage.ObjectStorageService
13+
import app.accrescent.parcelo.console.storage.S3ObjectStorageService
1414
import aws.smithy.kotlin.runtime.net.url.Url
1515
import io.ktor.client.HttpClient
1616
import io.ktor.client.plugins.HttpTimeout
@@ -96,9 +96,9 @@ fun Application.module() {
9696

9797
val mainModule = module {
9898
single { config }
99-
single<FileStorageService> {
99+
single<ObjectStorageService> {
100100
when (config.privateStorage) {
101-
is Config.ObjectStorage.S3 -> S3FileStorageService(
101+
is Config.ObjectStorage.S3 -> S3ObjectStorageService(
102102
Url.parse(config.privateStorage.endpointUrl),
103103
config.privateStorage.region,
104104
config.privateStorage.bucket,

console/src/main/kotlin/app/accrescent/parcelo/console/jobs/CleanDeletedFiles.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
package app.accrescent.parcelo.console.jobs
66

7-
import app.accrescent.parcelo.console.storage.FileStorageService
7+
import app.accrescent.parcelo.console.storage.ObjectStorageService
88
import kotlinx.coroutines.runBlocking
99
import org.koin.java.KoinJavaComponent.inject
1010
import kotlin.getValue
@@ -13,9 +13,9 @@ import kotlin.getValue
1313
* Removes all files marked deleted
1414
*/
1515
fun cleanDeletedFiles() {
16-
val storageService: FileStorageService by inject(FileStorageService::class.java)
16+
val storageService: ObjectStorageService by inject(ObjectStorageService::class.java)
1717

1818
runBlocking {
19-
storageService.cleanAllFiles()
19+
storageService.cleanAllObjects()
2020
}
2121
}

console/src/main/kotlin/app/accrescent/parcelo/console/jobs/CleanFile.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
package app.accrescent.parcelo.console.jobs
66

7-
import app.accrescent.parcelo.console.storage.FileStorageService
7+
import app.accrescent.parcelo.console.storage.ObjectStorageService
88
import kotlinx.coroutines.runBlocking
99
import org.koin.java.KoinJavaComponent.inject
1010
import kotlin.getValue
@@ -13,9 +13,9 @@ import kotlin.getValue
1313
* Removes the file with the given ID if it's marked deleted
1414
*/
1515
fun cleanFile(fileId: Int) {
16-
val storageService: FileStorageService by inject(FileStorageService::class.java)
16+
val storageService: ObjectStorageService by inject(ObjectStorageService::class.java)
1717

1818
runBlocking {
19-
storageService.cleanFile(fileId)
19+
storageService.cleanObject(fileId)
2020
}
2121
}

console/src/main/kotlin/app/accrescent/parcelo/console/jobs/Publish.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import app.accrescent.parcelo.console.data.App
1111
import app.accrescent.parcelo.console.data.Icon
1212
import app.accrescent.parcelo.console.data.Listing
1313
import app.accrescent.parcelo.console.publish.PublishService
14-
import app.accrescent.parcelo.console.storage.FileStorageService
14+
import app.accrescent.parcelo.console.storage.ObjectStorageService
1515
import kotlinx.coroutines.runBlocking
1616
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
1717
import org.jetbrains.exposed.sql.transactions.transaction
@@ -23,7 +23,7 @@ import java.util.UUID
2323
* Publishes the draft with the given ID, making it available for download
2424
*/
2525
fun registerPublishAppJob(draftId: UUID) {
26-
val storageService: FileStorageService by inject(FileStorageService::class.java)
26+
val storageService: ObjectStorageService by inject(ObjectStorageService::class.java)
2727
val publishService: PublishService by inject(PublishService::class.java)
2828

2929
val draft = transaction { DraftDao.findById(draftId) } ?: return
@@ -32,8 +32,8 @@ fun registerPublishAppJob(draftId: UUID) {
3232

3333
// Publish to the repository
3434
val metadata = runBlocking {
35-
storageService.loadFile(draft.fileId) { draftStream ->
36-
storageService.loadFile(iconFileId) { iconStream ->
35+
storageService.loadObject(draft.fileId) { draftStream ->
36+
storageService.loadObject(iconFileId) { iconStream ->
3737
publishService.publishDraft(draftStream, iconStream, draft.shortDescription)
3838
}
3939
}
@@ -69,14 +69,14 @@ fun registerPublishAppJob(draftId: UUID) {
6969
* Publishes the update with the given ID, making it available for download
7070
*/
7171
fun registerPublishUpdateJob(updateId: UUID) {
72-
val storageService: FileStorageService by inject(FileStorageService::class.java)
72+
val storageService: ObjectStorageService by inject(ObjectStorageService::class.java)
7373
val publishService: PublishService by inject(PublishService::class.java)
7474

7575
val update = transaction { UpdateDao.findById(updateId) } ?: return
7676

7777
// Publish to the repository
7878
val updatedMetadata = runBlocking {
79-
storageService.loadFile(update.fileId!!) {
79+
storageService.loadObject(update.fileId!!) {
8080
runBlocking { publishService.publishUpdate(it, update.appId.value) }
8181
}
8282
}

console/src/main/kotlin/app/accrescent/parcelo/console/routes/Drafts.kt

+9-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import app.accrescent.parcelo.console.data.User
2222
import app.accrescent.parcelo.console.data.net.ApiError
2323
import app.accrescent.parcelo.console.data.net.toApiError
2424
import app.accrescent.parcelo.console.jobs.cleanFile
25-
import app.accrescent.parcelo.console.storage.FileStorageService
25+
import app.accrescent.parcelo.console.storage.ObjectStorageService
2626
import app.accrescent.parcelo.console.util.TempFile
2727
import app.accrescent.parcelo.console.validation.MIN_TARGET_SDK
2828
import app.accrescent.parcelo.console.validation.REVIEW_ISSUE_BLACKLIST
@@ -95,7 +95,7 @@ fun Route.draftRoutes() {
9595

9696
fun Route.createDraftRoute() {
9797
val config: Config by inject()
98-
val storageService: FileStorageService by inject()
98+
val storageService: ObjectStorageService by inject()
9999

100100
post<Drafts> {
101101
val creatorId = call.principal<Session>()!!.userId
@@ -222,11 +222,13 @@ fun Route.createDraftRoute() {
222222
val iconFileId = iconData.inputStream()
223223
.use {
224224
runBlocking {
225-
storageService.saveFile(it, iconData.size.toLong())
225+
storageService.saveObject(it, iconData.size.toLong())
226226
}
227227
}
228228
val appFileId = tempApkSet.inputStream()
229-
.use { runBlocking { storageService.saveFile(it, tempApkSet.size()) } }
229+
.use {
230+
runBlocking { storageService.saveObject(it, tempApkSet.size()) }
231+
}
230232
val icon = Icon.new { fileId = iconFileId }
231233
Draft.new {
232234
this.label = label
@@ -257,7 +259,7 @@ fun Route.createDraftRoute() {
257259
}
258260

259261
fun Route.deleteDraftRoute() {
260-
val storageService: FileStorageService by inject()
262+
val storageService: ObjectStorageService by inject()
261263

262264
delete<Drafts.Id> { route ->
263265
val userId = call.principal<Session>()!!.userId
@@ -404,7 +406,7 @@ fun Route.getAssignedDraftsRoute() {
404406
* See also [getUpdateApkSetRoute].
405407
*/
406408
fun Route.getDraftApkSetRoute() {
407-
val storageService: FileStorageService by inject()
409+
val storageService: ObjectStorageService by inject()
408410

409411
get<Drafts.Id.ApkSet> { route ->
410412
val userId = call.principal<Session>()!!.userId
@@ -437,7 +439,7 @@ fun Route.getDraftApkSetRoute() {
437439
).toString(),
438440
)
439441
call.respondOutputStream {
440-
storageService.loadFile(draft.fileId) { it.copyTo(this) }
442+
storageService.loadObject(draft.fileId) { it.copyTo(this) }
441443
}
442444
} else {
443445
// Check whether the user has read access to this draft. If they do, tell them they're

console/src/main/kotlin/app/accrescent/parcelo/console/routes/Updates.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import app.accrescent.parcelo.console.data.net.ApiError
2424
import app.accrescent.parcelo.console.data.net.toApiError
2525
import app.accrescent.parcelo.console.jobs.cleanFile
2626
import app.accrescent.parcelo.console.jobs.registerPublishUpdateJob
27-
import app.accrescent.parcelo.console.storage.FileStorageService
27+
import app.accrescent.parcelo.console.storage.ObjectStorageService
2828
import app.accrescent.parcelo.console.util.TempFile
2929
import app.accrescent.parcelo.console.validation.MIN_TARGET_SDK
3030
import app.accrescent.parcelo.console.validation.REVIEW_ISSUE_BLACKLIST
@@ -90,7 +90,7 @@ fun Route.updateRoutes() {
9090

9191
fun Route.createUpdateRoute() {
9292
val config: Config by inject()
93-
val storageService: FileStorageService by inject()
93+
val storageService: ObjectStorageService by inject()
9494

9595
post<Apps.Id.Updates> { route ->
9696
val userId = call.principal<Session>()!!.userId
@@ -169,8 +169,8 @@ fun Route.createUpdateRoute() {
169169
return@post
170170
}
171171

172-
val apkSetFileId =
173-
tempApkSet.inputStream().use { storageService.saveFile(it, tempApkSet.size()) }
172+
val apkSetFileId = tempApkSet.inputStream()
173+
.use { storageService.saveObject(it, tempApkSet.size()) }
174174

175175
// There exists:
176176
//
@@ -343,7 +343,7 @@ fun Route.updateUpdateRoute() {
343343
* the "update" permission for the associated app.
344344
*/
345345
fun Route.deleteUpdateRoute() {
346-
val storageService: FileStorageService by inject()
346+
val storageService: ObjectStorageService by inject()
347347

348348
delete<Updates.Id> { route ->
349349
val userId = call.principal<Session>()!!.userId
@@ -419,7 +419,7 @@ fun Route.getAssignedUpdatesRoute() {
419419
* See also [getDraftApkSetRoute].
420420
*/
421421
fun Route.getUpdateApkSetRoute() {
422-
val storageService: FileStorageService by inject()
422+
val storageService: ObjectStorageService by inject()
423423

424424
get<Updates.Id.ApkSet> { route ->
425425
val userId = call.principal<Session>()!!.userId
@@ -452,7 +452,7 @@ fun Route.getUpdateApkSetRoute() {
452452
).toString(),
453453
)
454454
call.respondOutputStream {
455-
storageService.loadFile(update.fileId!!) { it.copyTo(this) }
455+
storageService.loadObject(update.fileId!!) { it.copyTo(this) }
456456
}
457457
} else {
458458
// Check whether the user has read access to this update. If they do, tell them they're

console/src/main/kotlin/app/accrescent/parcelo/console/storage/FileStorageService.kt renamed to console/src/main/kotlin/app/accrescent/parcelo/console/storage/ObjectStorageService.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import org.jetbrains.exposed.dao.id.EntityID
88
import java.io.InputStream
99

1010
/**
11-
* Abstraction of file storage
11+
* Abstraction of object storage
1212
*/
13-
interface FileStorageService {
13+
interface ObjectStorageService {
1414
/**
1515
* Save a file to the file storage service
1616
*
1717
* @return the database ID of the new file
1818
*/
19-
suspend fun saveFile(inputStream: InputStream, size: Long): EntityID<Int>
19+
suspend fun saveObject(inputStream: InputStream, size: Long): EntityID<Int>
2020

2121
/**
2222
* Marks the given file deleted
2323
*
2424
* This method does not guarantee that the file has been deleted from the underlying storage
25-
* medium. However, all future calls to [loadFile] for the same file with throw
25+
* medium. However, all future calls to [loadObject] for the same file with throw
2626
* [NoSuchFileException], and the file should be considered deleted for all purposes besides
2727
* cleaning.
2828
*/
@@ -34,17 +34,17 @@ interface FileStorageService {
3434
* The file must be previously marked deleted by [markDeleted], otherwise this function does
3535
* nothing.
3636
*/
37-
suspend fun cleanFile(id: Int)
37+
suspend fun cleanObject(id: Int)
3838

3939
/**
4040
* Deletes all files marked deleted from persistent storage
4141
*/
42-
suspend fun cleanAllFiles()
42+
suspend fun cleanAllObjects()
4343

4444
/**
4545
* Load the file with the given ID
4646
*
4747
* @return the file's data stream
4848
*/
49-
suspend fun <T> loadFile(id: EntityID<Int>, block: suspend (InputStream) -> T): T
49+
suspend fun <T> loadObject(id: EntityID<Int>, block: suspend (InputStream) -> T): T
5050
}

console/src/main/kotlin/app/accrescent/parcelo/console/storage/S3FileStorageService.kt renamed to console/src/main/kotlin/app/accrescent/parcelo/console/storage/S3ObjectStorageService.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ import java.io.InputStream
3030
import java.util.UUID
3131

3232
/**
33-
* Implementation of [FileStorageService] using S3-compatible storage as the backing store
33+
* Implementation of [ObjectStorageService] using S3-compatible storage as the backing store
3434
*/
35-
class S3FileStorageService(
35+
class S3ObjectStorageService(
3636
private val s3EndpointUrl: Url,
3737
private val s3Region: String,
3838
private val s3Bucket: String,
3939
private val s3AccessKeyId: String,
4040
private val s3SecretAccessKey: String,
41-
) : FileStorageService {
42-
override suspend fun saveFile(inputStream: InputStream, size: Long): EntityID<Int> {
41+
) : ObjectStorageService {
42+
override suspend fun saveObject(inputStream: InputStream, size: Long): EntityID<Int> {
4343
S3Client {
4444
endpointUrl = s3EndpointUrl
4545
region = s3Region
@@ -67,7 +67,7 @@ class S3FileStorageService(
6767
transaction { findFile(id)?.apply { deleted = true } } ?: return
6868
}
6969

70-
override suspend fun cleanFile(id: Int) {
70+
override suspend fun cleanObject(id: Int) {
7171
val file = transaction { File.findById(id) } ?: return
7272
val s3ObjectKey = file.s3ObjectKey
7373

@@ -89,7 +89,7 @@ class S3FileStorageService(
8989
transaction { file.delete() }
9090
}
9191

92-
override suspend fun cleanAllFiles() {
92+
override suspend fun cleanAllObjects() {
9393
val files = transaction { File.find { deleted eq true } }
9494

9595
val deleteObjectsRequest = transaction {
@@ -118,7 +118,7 @@ class S3FileStorageService(
118118
}
119119
}
120120

121-
override suspend fun <T> loadFile(id: EntityID<Int>, block: suspend (InputStream) -> T): T {
121+
override suspend fun <T> loadObject(id: EntityID<Int>, block: suspend (InputStream) -> T): T {
122122
val s3ObjectKey =
123123
transaction { findFile(id.value)?.s3ObjectKey } ?: throw FileNotFoundException()
124124

0 commit comments

Comments
 (0)