Add simple handler for GetBucketPolicy

Fixes #301.
pull/305/head
Andrew Gaul 2019-05-10 19:18:48 +07:00
rodzic 21ea62ec93
commit c8d8126b3f
3 zmienionych plików z 23 dodań i 1 usunięć

Wyświetl plik

@ -75,6 +75,8 @@ enum S3ErrorCode {
"The specified bucket does not exist"),
NO_SUCH_KEY(HttpServletResponse.SC_NOT_FOUND,
"The specified key does not exist."),
NO_SUCH_POLICY(HttpServletResponse.SC_NOT_FOUND,
"The specified bucket does not have a bucket policy."),
NO_SUCH_UPLOAD(HttpServletResponse.SC_NOT_FOUND, "Not Found"),
NOT_IMPLEMENTED(HttpServletResponse.SC_NOT_IMPLEMENTED,
"A header you provided implies functionality that is not" +

Wyświetl plik

@ -146,7 +146,6 @@ public class S3ProxyHandler {
"logging",
"metrics",
"notification",
"policy",
"replication",
"requestPayment",
"restore",
@ -657,6 +656,9 @@ public class S3ProxyHandler {
} else if ("".equals(request.getParameter("location"))) {
handleContainerLocation(response);
return;
} else if ("".equals(request.getParameter("policy"))) {
handleBucketPolicy(response, blobStore, path[1]);
return;
} else if ("".equals(request.getParameter("uploads"))) {
handleListMultipartUploads(request, response, blobStore,
path[1]);
@ -1135,6 +1137,14 @@ public class S3ProxyHandler {
}
}
private static void handleBucketPolicy(HttpServletResponse response,
BlobStore blobStore, String containerName) throws S3Exception {
if (!blobStore.containerExists(containerName)) {
throw new S3Exception(S3ErrorCode.NO_SUCH_BUCKET);
}
throw new S3Exception(S3ErrorCode.NO_SUCH_POLICY);
}
private void handleListMultipartUploads(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore,
String container) throws IOException, S3Exception {

Wyświetl plik

@ -1443,6 +1443,16 @@ public final class AwsSdkTest {
}
}
@Test
public void testGetBucketPolicy() throws Exception {
try {
client.getBucketPolicy(containerName);
Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class);
} catch (AmazonS3Exception e) {
assertThat(e.getErrorCode()).isEqualTo("NoSuchPolicy");
}
}
@Test
public void testUnknownParameter() throws Exception {
try {