Skip to content

Commit

Permalink
Merge pull request #183 from scireum/develop
Browse files Browse the repository at this point in the history
Prepares release of version 7.2
  • Loading branch information
jakobvogel authored Aug 17, 2021
2 parents 2c9825c + 1ea50a5 commit 9e7fd6b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 23 deletions.
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ steps:
settings:
repo: scireum/s3-ninja
tags:
- latest
- "${DRONE_TAG}"
environment:
DOCKER_PASSWORD:
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<url>http://s3ninja.net</url>

<properties>
<sirius.kernel>dev-23.0.0</sirius.kernel>
<sirius.web>dev-35.0.0</sirius.web>
<sirius.kernel>dev-23.5.0</sirius.kernel>
<sirius.web>dev-39.8.0</sirius.web>
</properties>

<repositories>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ninja/Aws4HashCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public boolean supports(final WebContext webContext) {
* Computes the authentication hash as specified by the AWS SDK for verification purposes.
*
* @param webContext the current request to fetch parameters from
* @param pathPrefix the path prefix to preped to the {@link S3Dispatcher#getEffectiveURI(WebContext) effective URI}
* @param pathPrefix the path prefix to preped to the {@link S3Dispatcher#getEffectiveURI(String) effective URI}
* of the request
* @return the computes hash value
* @throws Exception when hashing fails
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ninja/AwsLegacyHashCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class AwsLegacyHashCalculator {
* Computes the authentication hash as specified by the AWS SDK for verification purposes.
*
* @param webContext the current request to fetch parameters from
* @param pathPrefix the path prefix to preped to the {@link S3Dispatcher#getEffectiveURI(WebContext) effective URI}
* @param pathPrefix the path prefix to preped to the {@link S3Dispatcher#getEffectiveURI(String) effective URI}
* of the request
* @return the computes hash value
* @throws Exception when hashing fails
Expand Down Expand Up @@ -95,7 +95,7 @@ public String computeHash(WebContext webContext, String pathPrefix) throws Excep
stringToSign.append("\n");
}

stringToSign.append(pathPrefix).append('/').append(S3Dispatcher.getEffectiveURI(webContext));
stringToSign.append(pathPrefix).append('/').append(S3Dispatcher.getEffectiveURI(webContext.getRawRequestedURI()));

char separator = '?';
for (String parameterName : webContext.getParameterNames().stream().sorted().collect(Collectors.toList())) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ninja/ListFileTreeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ protected ListFileTreeVisitor(XMLStructuredOutput output,
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
File file = path.toFile();
String name = file.getName();
String name = StoredObject.decodeKey(file.getName());

if (!file.isFile() || name.startsWith("$")) {
if (!file.isFile() || file.getName().startsWith("$")) {
return FileVisitResult.CONTINUE;
}
if (!markerReached) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/ninja/NinjaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void buckets(WebContext webContext) {
try {
buckets = storage.getBuckets();
} catch (HandledException e) {
UserContext.message(Message.error(e.getMessage()));
UserContext.message(Message.error().withTextMessage(e.getMessage()));
}
webContext.respondWith()
.template("/templates/index.html.pasta",
Expand Down Expand Up @@ -151,21 +151,21 @@ public void bucket(WebContext webContext, String bucketName) {
// handle /ui/[bucket]?create
if (webContext.hasParameter("create")) {
if (bucket.exists()) {
UserContext.message(Message.error("Bucket does already exist."));
UserContext.message(Message.error().withTextMessage("Bucket does already exist."));
webContext.respondWith().redirectTemporarily("/ui/" + bucket.getEncodedName());
return;
}

bucket.create();

UserContext.message(Message.info("Bucket successfully created."));
UserContext.message(Message.info().withTextMessage("Bucket successfully created."));
webContext.respondWith().redirectTemporarily("/ui/" + bucket.getEncodedName());
return;
}

// from this point on, make sure that the bucket exists
if (!bucket.exists()) {
UserContext.message(Message.error("Bucket does not exist."));
UserContext.message(Message.error().withTextMessage("Bucket does not exist."));
webContext.respondWith().redirectTemporarily("/ui");
return;
}
Expand All @@ -174,7 +174,7 @@ public void bucket(WebContext webContext, String bucketName) {
if (webContext.hasParameter("make-public")) {
bucket.makePublic();

UserContext.message(Message.info("ACLs successfully changed"));
UserContext.message(Message.info().withTextMessage("ACLs successfully changed"));
webContext.respondWith().redirectTemporarily("/ui/" + bucket.getEncodedName());
return;
}
Expand All @@ -183,7 +183,7 @@ public void bucket(WebContext webContext, String bucketName) {
if (webContext.hasParameter("make-private")) {
bucket.makePrivate();

UserContext.message(Message.info("ACLs successfully changed"));
UserContext.message(Message.info().withTextMessage("ACLs successfully changed"));
webContext.respondWith().redirectTemporarily("/ui/" + bucket.getEncodedName());
return;
}
Expand All @@ -192,7 +192,7 @@ public void bucket(WebContext webContext, String bucketName) {
if (webContext.hasParameter("delete")) {
bucket.delete();

UserContext.message(Message.info("Bucket successfully deleted."));
UserContext.message(Message.info().withTextMessage("Bucket successfully deleted."));
webContext.respondWith().redirectTemporarily("/ui");
return;
}
Expand Down Expand Up @@ -274,15 +274,15 @@ private void objects(WebContext webContext, Bucket bucket) {
public void object(WebContext webContext, String bucketName, List<String> idParts) {
Bucket bucket = storage.getBucket(bucketName);
if (!bucket.exists()) {
UserContext.message(Message.error("Bucket does not exist."));
UserContext.message(Message.error().withTextMessage("Bucket does not exist."));
webContext.respondWith().redirectTemporarily("/ui");
return;
}

String id = String.join("/", idParts);
StoredObject object = bucket.getObject(id);
if (!object.exists()) {
UserContext.message(Message.error("Object does not exist."));
UserContext.message(Message.error().withTextMessage("Object does not exist."));
webContext.respondWith().redirectTemporarily("/ui/" + bucket.getEncodedName());
return;
}
Expand All @@ -291,7 +291,7 @@ public void object(WebContext webContext, String bucketName, List<String> idPart
if (webContext.hasParameter("delete")) {
object.delete();

UserContext.message(Message.info("Object successfully deleted."));
UserContext.message(Message.info().withTextMessage("Object successfully deleted."));
webContext.respondWith().redirectTemporarily("/ui/" + bucket.getEncodedName());
return;
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/ninja/S3Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,18 @@ public DispatchDecision dispatch(WebContext webContext) throws Exception {
* As we have to support legacy URIs which have an <tt>/s3</tt> prefix, we cut this here, and
* also the first "/" and only return the effective URI to process.
*
* @param webContext the current request
* @param uri the requested URI
* @return the effective URI to process
*/
public static String getEffectiveURI(WebContext webContext) {
String uri = webContext.getRequestedURI();
public static String getEffectiveURI(String uri) {
if (uri.startsWith("/s3")) {
uri = uri.substring(3);
}
if (uri.startsWith("/")) {
uri = uri.substring(1);
}

return Strings.urlEncode(uri).replace("+", "%20").replace("%2F", "/");
return uri;
}

/**
Expand All @@ -280,7 +279,7 @@ public static String getEffectiveURI(WebContext webContext) {
* @return a structured {@link S3Request}.
*/
private static S3Request parseRequest(WebContext webContext) {
String uri = getEffectiveURI(webContext);
String uri = getEffectiveURI(webContext.getRequestedURI());

// we treat the first parameter without value as query string
Iterator<String> parameterIterator = webContext.getParameterNames().iterator();
Expand Down
2 changes: 1 addition & 1 deletion src/site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h1>S3 ninja</h1>
<div class="well">
<ol>
<li>A readily packaged docker image is available at <a href="https://hub.docker.com/r/scireum/s3-ninja/">scireum/s3-ninja</a></li>
<li>Run like <b>docker run -p 9444:9000 scireum/s3-ninja:7</b></li>
<li>Run like <b>docker run -p 9444:9000 scireum/s3-ninja:latest</b></li>
<li>Navigate to <a href="http://localhost:9444/ui" target="_blank">http://localhost:9444/ui</a></li>
<li>Run S3 API-Calls against <b>http://localhost:9444/</b> (e.g. http://localhost:9444/test-bucket/test-object)</li>
<li>Provide an volume for <b>/home/sirius/data</b> to persist data accross restarts.<br/>S3Ninja runs as user id 2000 inside the container. If you link a existing directory into your container, change the user/group id to 2000.</li>
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/BaseAWSSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,43 @@ abstract class BaseAWSSpec extends BaseSpecification {
summaries.get(1).getKey() == key2
}

// reported in https://github.com/scireum/s3ninja/issues/180
def "PUT and then LIST with prefix work as expected"() {
given:
def bucketName = DEFAULT_BUCKET_NAME
def key1 = DEFAULT_KEY + "/Eins"
def key2 = DEFAULT_KEY + "/Zwei"
def key3 = "a/key/with a different/prefix/Drei"
def client = getClient()
when:
if (client.doesBucketExist(bucketName)) {
client.deleteBucket(bucketName)
}
client.createBucket(bucketName)
and:
client.putObject(
bucketName,
key1,
new ByteArrayInputStream("Eins".getBytes(Charsets.UTF_8)),
new ObjectMetadata())
client.putObject(
bucketName,
key2,
new ByteArrayInputStream("Zwei".getBytes(Charsets.UTF_8)),
new ObjectMetadata())
client.putObject(
bucketName,
key3,
new ByteArrayInputStream("Drei".getBytes(Charsets.UTF_8)),
new ObjectMetadata())
then:
def listing = client.listObjects(bucketName, DEFAULT_KEY + '/')
def summaries = listing.getObjectSummaries()
summaries.size() == 2
summaries.get(0).getKey() == key1
summaries.get(1).getKey() == key2
}

def "PUT and then DELETE work as expected"() {
given:
def bucketName = DEFAULT_BUCKET_NAME
Expand Down

0 comments on commit 9e7fd6b

Please sign in to comment.