Skip to content

Commit

Permalink
Merge branch 'bugfix/MD-18905-bucketinhostname'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Oct 10, 2023
2 parents 8587db1 + 5d11f4c commit 5318a73
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
24 changes: 15 additions & 9 deletions s3/src/main/java/ch/cyberduck/core/s3/S3LoggingFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ch.cyberduck.core.exception.AccessDeniedException;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.InteroperabilityException;
import ch.cyberduck.core.features.Home;
import ch.cyberduck.core.features.Logging;
import ch.cyberduck.core.logging.LoggingConfiguration;
import ch.cyberduck.core.preferences.HostPreferences;
Expand Down Expand Up @@ -63,14 +64,19 @@ public LoggingConfiguration getConfiguration(final Path file) throws BackgroundE
}
final LoggingConfiguration configuration = new LoggingConfiguration(status.isLoggingEnabled(),
status.getTargetBucketName());
try {
configuration.setContainers(new S3BucketListService(session).list(
new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)),
new DisabledListProgressListener()).toList());
if(bucket.isRoot()) {
configuration.setContainers(Collections.singletonList(
new Path(RequestEntityRestStorageService.findBucketInHostname(session.getHost()), EnumSet.of(Path.Type.volume, Path.Type.directory)))
);
}
catch(AccessDeniedException | InteroperabilityException e) {
log.warn(String.format("Failure listing buckets. %s", e.getMessage()));
configuration.setContainers(Collections.singletonList(bucket));
else {
try {
configuration.setContainers(new S3BucketListService(session).list(Home.ROOT, new DisabledListProgressListener()).toList());
}
catch(AccessDeniedException | InteroperabilityException e) {
log.warn(String.format("Failure listing buckets. %s", e.getMessage()));
configuration.setContainers(Collections.singletonList(bucket));
}
}
return configuration;
}
Expand All @@ -93,11 +99,11 @@ public void setConfiguration(final Path file, final LoggingConfiguration configu
try {
final S3BucketLoggingStatus status = new S3BucketLoggingStatus(
StringUtils.isNotBlank(configuration.getLoggingTarget()) ? configuration.getLoggingTarget() :
bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), null);
bucket.isRoot() ? RequestEntityRestStorageService.findBucketInHostname(session.getHost()) : bucket.getName(), null);
if(configuration.isEnabled()) {
status.setLogfilePrefix(new HostPreferences(session.getHost()).getProperty("s3.logging.prefix"));
}
session.getClient().setBucketLoggingStatus(bucket.getName(), status, true);
session.getClient().setBucketLoggingStatus(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), status, true);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public MultipartPart call() throws BackgroundException {
final HttpRange range = HttpRange.byLength(offset, length);
final Path bucket = containerService.getContainer(source);
final MultipartPart part = session.getClient().multipartUploadPartCopy(multipart, partNumber,
bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), containerService.getKey(source),
bucket.isRoot() ? RequestEntityRestStorageService.findBucketInHostname(session.getHost()) : bucket.getName(), containerService.getKey(source),
null, null, null, null, range.getStart(), range.getEnd(), source.attributes().getVersionId());
if(log.isInfoEnabled()) {
log.info(String.format("Received response %s for part number %d", part, partNumber));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ public void revert(final Path file) throws BackgroundException {
catch(AccessDeniedException | InteroperabilityException e) {
log.warn(String.format("Ignore failure %s", e));
}
final Path bucket = containerService.getContainer(file);
final String bucketname = bucket.isRoot() ? RequestEntityRestStorageService.findBucketInHostname(session.getHost()) : bucket.getName();
session.getClient().copyVersionedObject(file.attributes().getVersionId(),
containerService.getContainer(file).getName(), containerService.getKey(file), containerService.getContainer(file).getName(), destination, false);
bucketname, containerService.getKey(file), bucketname, destination, false);
if(file.getParent().attributes().getCustom().containsKey(S3VersionedObjectListService.KEY_DELETE_MARKER)) {
// revert placeholder
session.getClient().deleteVersionedObject(
file.getParent().attributes().getVersionId(),
containerService.getContainer(file).getName(), containerService.getKey(file.getParent()));
bucketname, containerService.getKey(file.getParent()));
}
}
catch(ServiceException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class S3ListServiceTest extends AbstractS3Test {

@Test
public void testListBucketNameInHostname() throws Exception {
new S3ListService(virtualhost, new S3AccessControlListFeature(session)).list(
new S3ListService(virtualhost, new S3AccessControlListFeature(virtualhost)).list(
new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), new DisabledListProgressListener());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Bug fixes, suggestions and comments should be sent to [email protected]
*/

import ch.cyberduck.core.AlphanumericRandomStringService;
import ch.cyberduck.core.DisabledConnectionCallback;
import ch.cyberduck.core.DisabledLoginCallback;
import ch.cyberduck.core.Path;
Expand Down Expand Up @@ -66,6 +67,28 @@ public void testCopy() throws Exception {
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

@Test
public void testCopyBucketNameInHostname() throws Exception {
final Path test = new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final byte[] content = RandomUtils.nextBytes(1023);
final TransferStatus status = new TransferStatus().withLength(content.length);
status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
final OutputStream out = new S3WriteFeature(virtualhost, new S3AccessControlListFeature(virtualhost)).write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
out.close();
test.attributes().setSize(content.length);
final Path copy = new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final S3MultipartCopyFeature feature = new S3MultipartCopyFeature(virtualhost, new S3AccessControlListFeature(virtualhost));
feature.copy(test, copy, status, new DisabledConnectionCallback(), new DisabledStreamListener());
assertTrue(new S3FindFeature(virtualhost, new S3AccessControlListFeature(virtualhost)).find(test));
assertEquals(content.length, new S3AttributesFinderFeature(virtualhost, new S3AccessControlListFeature(virtualhost)).find(test).getSize());
new S3DefaultDeleteFeature(virtualhost).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new S3FindFeature(virtualhost, new S3AccessControlListFeature(virtualhost)).find(copy));
assertEquals(content.length, new S3AttributesFinderFeature(virtualhost, new S3AccessControlListFeature(virtualhost)).find(copy).getSize());
new S3DefaultDeleteFeature(virtualhost).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

@Test
public void testCopyAWS4Signature() throws Exception {
final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
Expand Down

0 comments on commit 5318a73

Please sign in to comment.