Skip to content

Commit c1e3cae

Browse files
committed
fix: Bucket name is not required
1 parent f703d99 commit c1e3cae

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

server/src/main/kotlin/com/adobe/testing/s3mock/dto/Bucket.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data class Bucket(
3131
@param:JsonProperty("CreationDate", namespace = "http://s3.amazonaws.com/doc/2006-03-01/")
3232
val creationDate: String?,
3333
@param:JsonProperty("Name", namespace = "http://s3.amazonaws.com/doc/2006-03-01/")
34-
val name: String,
34+
val name: String?,
3535
@JsonIgnore
3636
val path: Path?
3737
) {

server/src/main/kotlin/com/adobe/testing/s3mock/service/BucketService.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import com.adobe.testing.s3mock.util.AwsHttpHeaders.X_AMZ_BUCKET_LOCATION_TYPE
4343
import software.amazon.awssdk.utils.http.SdkHttpUtils.urlEncodeIgnoreSlashes
4444
import java.util.UUID
4545
import java.util.concurrent.ConcurrentHashMap
46+
import kotlin.let
4647

4748
open class BucketService(
4849
private val bucketStore: BucketStore,
@@ -92,7 +93,9 @@ open class BucketService(
9293
if (buckets.size > maxBuckets) {
9394
nextContinuationToken = UUID.randomUUID().toString()
9495
buckets = buckets.subList(0, maxBuckets)
95-
listBucketsPagingStateCache[nextContinuationToken] = buckets[maxBuckets - 1].name
96+
buckets[maxBuckets - 1].name?.let {
97+
listBucketsPagingStateCache[nextContinuationToken] = it
98+
}
9699
}
97100

98101
return ListAllMyBucketsResult(Owner.DEFAULT_OWNER, Buckets(buckets), prefix, nextContinuationToken)

server/src/main/kotlin/com/adobe/testing/s3mock/service/ServiceBase.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,12 @@ abstract class ServiceBase {
9393

9494
fun <T> filterBy(
9595
contents: List<T>,
96-
selector: (T) -> String,
96+
selector: (T) -> String?,
9797
compareTo: String?
98-
): List<T> {
99-
return if (!compareTo.isNullOrEmpty()) {
100-
contents.filter { selector(it) > compareTo }
101-
} else {
102-
contents
103-
}
104-
}
98+
): List<T> =
99+
compareTo?.let { threshold ->
100+
contents.filter { selector(it)?.let { candidate -> candidate > threshold } == true }
101+
} ?: contents
105102

106103
fun <T> filterBy(
107104
contents: List<T>,
@@ -117,11 +114,11 @@ abstract class ServiceBase {
117114

118115
fun <T> filterBy(
119116
contents: List<T>,
120-
selector: (T) -> String,
117+
selector: (T) -> String?,
121118
prefixes: List<String>?
122119
): List<T> {
123120
return if (!prefixes.isNullOrEmpty()) {
124-
contents.filter { content -> prefixes.none { prefix -> selector(content).startsWith(prefix) } }
121+
contents.filter { content -> prefixes.none { prefix -> selector(content)?.startsWith(prefix) ?: false } }
125122
} else {
126123
contents
127124
}

0 commit comments

Comments
 (0)