Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify storage code #8312

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions utils/ort/src/main/kotlin/storage/HttpFileStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@
}
}

override fun exists(path: String): Boolean {
val request = Request.Builder()
private fun requestBuilder(): Request.Builder =
Request.Builder()

Check warning on line 84 in utils/ort/src/main/kotlin/storage/HttpFileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/HttpFileStorage.kt#L84

Added line #L84 was not covered by tests
.headers(headers.toHeaders())
.cacheControl(CacheControl.Builder().maxAge(cacheMaxAgeInSeconds, TimeUnit.SECONDS).build())

override fun exists(path: String): Boolean {
val request = requestBuilder()

Check warning on line 89 in utils/ort/src/main/kotlin/storage/HttpFileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/HttpFileStorage.kt#L89

Added line #L89 was not covered by tests
.head()
.url(urlForPath(path))
.build()
Expand All @@ -92,9 +95,7 @@
}

override fun read(path: String): InputStream {
val request = Request.Builder()
.headers(headers.toHeaders())
.cacheControl(CacheControl.Builder().maxAge(cacheMaxAgeInSeconds, TimeUnit.SECONDS).build())
val request = requestBuilder()

Check warning on line 98 in utils/ort/src/main/kotlin/storage/HttpFileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/HttpFileStorage.kt#L98

Added line #L98 was not covered by tests
.get()
.url(urlForPath(path))
.build()
Expand All @@ -117,8 +118,7 @@

override fun write(path: String, inputStream: InputStream) {
inputStream.use {
val request = Request.Builder()
.headers(headers.toHeaders())
val request = requestBuilder()

Check warning on line 121 in utils/ort/src/main/kotlin/storage/HttpFileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/HttpFileStorage.kt#L121

Added line #L121 was not covered by tests
.put(it.readBytes().toRequestBody())
.url(urlForPath(path))
.build()
Expand Down
34 changes: 17 additions & 17 deletions utils/ort/src/main/kotlin/storage/S3FileStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
}

if (awsRegion != null && provider != null) {
S3Client.builder().apply {
region(Region.of(awsRegion))
credentialsProvider(provider)
endpointOverride(if (customEndpoint != null) URI.create(customEndpoint) else null)
}.build()
S3Client.builder()
.region(Region.of(awsRegion))
.credentialsProvider(provider)

Check warning on line 77 in utils/ort/src/main/kotlin/storage/S3FileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/S3FileStorage.kt#L75-L77

Added lines #L75 - L77 were not covered by tests
.endpointOverride(if (customEndpoint != null) URI.create(customEndpoint) else null)
.build()

Check warning on line 79 in utils/ort/src/main/kotlin/storage/S3FileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/S3FileStorage.kt#L79

Added line #L79 was not covered by tests
} else {
if (awsRegion != null) {
S3Client.builder().region(Region.of(awsRegion)).build()
Expand All @@ -87,10 +87,10 @@
}

override fun exists(path: String): Boolean {
val request = HeadObjectRequest.builder().apply {
key(path)
bucket(bucketName)
}.build()
val request = HeadObjectRequest.builder()
.key(path)
.bucket(bucketName)
.build()

Check warning on line 93 in utils/ort/src/main/kotlin/storage/S3FileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/S3FileStorage.kt#L90-L93

Added lines #L90 - L93 were not covered by tests

return runCatching { s3Client.headObject(request) }.onFailure { exception ->
if (exception !is NoSuchKeyException) {
Expand All @@ -100,10 +100,10 @@
}

override fun read(path: String): InputStream {
val request = GetObjectRequest.builder().apply {
key(path)
bucket(bucketName)
}.build()
val request = GetObjectRequest.builder()
.key(path)
.bucket(bucketName)
.build()

Check warning on line 106 in utils/ort/src/main/kotlin/storage/S3FileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/S3FileStorage.kt#L103-L106

Added lines #L103 - L106 were not covered by tests

return runCatching {
val response = s3Client.getObjectAsBytes(request)
Expand All @@ -115,10 +115,10 @@
}

override fun write(path: String, inputStream: InputStream) {
val request = PutObjectRequest.builder().apply {
key(path)
bucket(bucketName)
}.build()
val request = PutObjectRequest.builder()
.key(path)
.bucket(bucketName)
.build()

Check warning on line 121 in utils/ort/src/main/kotlin/storage/S3FileStorage.kt

View check run for this annotation

Codecov / codecov/patch

utils/ort/src/main/kotlin/storage/S3FileStorage.kt#L118-L121

Added lines #L118 - L121 were not covered by tests

val body = inputStream.use {
if (compression) {
Expand Down
Loading