kopia lustrzana https://github.com/gaul/s3proxy
Fix anonymous bucket listing bug
If the bucket locator is used with anonymous access, listing a container results in a null-pointer exception, as there are no blobstores in the locator. In that case, we should use the globLocator structure and return the first available blobstore.pull/383/head
rodzic
939acd950f
commit
512c926b6e
|
@ -41,6 +41,7 @@ public final class GlobBlobStoreLocator implements BlobStoreLocator {
|
||||||
Map.Entry<String, BlobStore> locatorEntry =
|
Map.Entry<String, BlobStore> locatorEntry =
|
||||||
locator.get(identity);
|
locator.get(identity);
|
||||||
Map.Entry<String, BlobStore> globEntry = null;
|
Map.Entry<String, BlobStore> globEntry = null;
|
||||||
|
if (container != null) {
|
||||||
for (Map.Entry<PathMatcher, Map.Entry<String, BlobStore>>
|
for (Map.Entry<PathMatcher, Map.Entry<String, BlobStore>>
|
||||||
entry : globLocator.entrySet()) {
|
entry : globLocator.entrySet()) {
|
||||||
if (entry.getKey().matches(FileSystems.getDefault()
|
if (entry.getKey().matches(FileSystems.getDefault()
|
||||||
|
@ -48,11 +49,17 @@ public final class GlobBlobStoreLocator implements BlobStoreLocator {
|
||||||
globEntry = entry.getValue();
|
globEntry = entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (globEntry == null) {
|
if (globEntry == null) {
|
||||||
if (identity == null) {
|
if (identity == null) {
|
||||||
|
if (!locator.isEmpty()) {
|
||||||
return locator.entrySet().iterator().next()
|
return locator.entrySet().iterator().next()
|
||||||
.getValue();
|
.getValue();
|
||||||
}
|
}
|
||||||
|
return Maps.immutableEntry(null,
|
||||||
|
globLocator.entrySet().iterator().next().getValue()
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
return locatorEntry;
|
return locatorEntry;
|
||||||
}
|
}
|
||||||
if (identity == null) {
|
if (identity == null) {
|
||||||
|
|
|
@ -128,4 +128,26 @@ public final class GlobBlobStoreLocatorTest {
|
||||||
assertThat(locator.locateBlobStore("id2", "cont5X.extra", null)
|
assertThat(locator.locateBlobStore("id2", "cont5X.extra", null)
|
||||||
.getValue()).isSameAs(blobStoreTwo);
|
.getValue()).isSameAs(blobStoreTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGlobLocatorAnonymous() {
|
||||||
|
ImmutableMap<PathMatcher, Map.Entry<String, BlobStore>> globMap =
|
||||||
|
ImmutableMap.of(
|
||||||
|
FileSystems.getDefault().getPathMatcher(
|
||||||
|
"glob:one"),
|
||||||
|
Maps.immutableEntry(null, blobStoreOne),
|
||||||
|
FileSystems.getDefault().getPathMatcher(
|
||||||
|
"glob:two"),
|
||||||
|
Maps.immutableEntry(null, blobStoreTwo)
|
||||||
|
);
|
||||||
|
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(
|
||||||
|
ImmutableMap.of(), globMap);
|
||||||
|
|
||||||
|
assertThat(locator.locateBlobStore(null, null, null)
|
||||||
|
.getValue()).isSameAs(blobStoreOne);
|
||||||
|
assertThat(locator.locateBlobStore(null, "one", null)
|
||||||
|
.getValue()).isSameAs(blobStoreOne);
|
||||||
|
assertThat(locator.locateBlobStore(null, "two", null)
|
||||||
|
.getValue()).isSameAs(blobStoreTwo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue