use of ch.cyberduck.core.features.Location in project cyberduck by iterate-ch.
the class RegionController method getAccessoryView.
public NSView getAccessoryView(final NSAlert alert) {
view = NSView.create(new NSRect(alert.window().frame().size.width.doubleValue(), 0));
regionPopup = NSPopUpButton.buttonWithFrame(new NSRect(alert.window().frame().size.width.doubleValue(), 26));
regionPopup.setFrameOrigin(new NSPoint(0, 0));
for (Location.Name region : regions) {
regionPopup.addItemWithTitle(region.toString());
regionPopup.itemWithTitle(region.toString()).setRepresentedObject(region.getIdentifier());
if (region.equals(defaultRegion)) {
regionPopup.selectItem(regionPopup.lastItem());
}
}
// Override accessory view with location menu added
view.addSubview(regionPopup);
return view;
}
use of ch.cyberduck.core.features.Location in project cyberduck by iterate-ch.
the class S3BucketListService method list.
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
if (log.isDebugEnabled()) {
log.debug(String.format("List containers for %s", session));
}
try {
final AttributedList<Path> buckets = new AttributedList<>();
// List all buckets owned
for (StorageBucket b : session.getClient().listAllBuckets()) {
final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory));
if (b.getOwner() != null) {
// Null if the owner is not available
bucket.attributes().setOwner(b.getOwner().getId());
}
bucket.attributes().setCreationDate(b.getCreationDate().getTime());
if (b.isLocationKnown()) {
bucket.attributes().setRegion(b.getLocation());
}
if (region.getIdentifier() != null) {
final String location;
if (!b.isLocationKnown()) {
location = session.getFeature(Location.class).getLocation(bucket).getIdentifier();
} else {
location = b.getLocation();
}
if (!StringUtils.equals(location, region.getIdentifier())) {
log.warn(String.format("Skip bucket %s in region %s", bucket, location));
continue;
}
bucket.attributes().setRegion(location);
}
buckets.add(bucket);
listener.chunk(directory, buckets);
}
return buckets;
} catch (ServiceException e) {
throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory);
}
}
use of ch.cyberduck.core.features.Location in project cyberduck by iterate-ch.
the class WebsiteCloudFrontDistributionConfiguration method getWebsiteHostname.
/**
* The website endpoint given the location of the bucket. When you configure a bucket as a website, the website is
* available via the region-specific website endpoint. The website endpoint you use must be in the same region that
* your bucket resides. These website endpoints are different than the REST API endpoints (see Request Endpoints).
* Amazon S3 supports the following website endpoint.
*
* @param bucket Bucket name
* @return Website distribution hostname
*/
protected String getWebsiteHostname(final Path bucket) throws BackgroundException {
// Geographical location
final Location.Name location = new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(bucket);
// US Standard
final String endpoint;
if (Location.unknown == location) {
endpoint = "s3-website-us-east-1.amazonaws.com";
} else if ("US".equals(location.getIdentifier())) {
endpoint = "s3-website-us-east-1.amazonaws.com";
} else if ("EU".equals(location.getIdentifier())) {
endpoint = "s3-website-eu-west-1.amazonaws.com";
} else {
endpoint = String.format("s3-website-%s.amazonaws.com", location.getIdentifier());
}
return String.format("%s.%s", bucket.getName(), endpoint);
}
use of ch.cyberduck.core.features.Location in project cyberduck by iterate-ch.
the class RequestEntityRestStorageService method setupConnection.
@Override
protected HttpUriRequest setupConnection(final HTTP_METHOD method, final String bucketName, final String objectKey, final Map<String, String> requestParameters) throws S3ServiceException {
final Host host = session.getHost();
// Apply default configuration
final PreferencesReader preferences = new HostPreferences(session.getHost());
if (S3Session.isAwsHostname(host.getHostname(), false)) {
// Check if not already set to accelerated endpoint
if (properties.getStringProperty("s3service.s3-endpoint", preferences.getProperty("s3.hostname.default")).matches("s3-accelerate(\\.dualstack)?\\.amazonaws\\.com")) {
log.debug("Skip adjusting endpoint with transfer acceleration");
} else {
// Only for AWS set endpoint to region specific
if (StringUtils.isNotBlank(bucketName) && (requestParameters == null || !requestParameters.containsKey("location"))) {
try {
// Determine region for bucket using cache
final Location.Name region = new S3LocationFeature(session, regionEndpointCache).getLocation(bucketName);
if (Location.unknown == region) {
log.warn(String.format("Failure determining bucket location for %s", bucketName));
} else {
final String endpoint;
if (preferences.getBoolean("s3.endpoint.dualstack.enable")) {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv6"), region.getIdentifier());
} else {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv4"), region.getIdentifier());
}
if (log.isDebugEnabled()) {
log.debug(String.format("Set endpoint to %s", endpoint));
}
properties.setProperty("s3service.s3-endpoint", endpoint);
}
} catch (BackgroundException e) {
// Ignore failure reading location for bucket
log.error(String.format("Failure %s determining bucket location for %s", e, bucketName));
}
} else {
if (StringUtils.isNotBlank(host.getRegion())) {
// Use default region
final String endpoint;
if (preferences.getBoolean("s3.endpoint.dualstack.enable")) {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv6"), host.getRegion());
} else {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv4"), host.getRegion());
}
if (log.isDebugEnabled()) {
log.debug(String.format("Set endpoint to %s", endpoint));
}
properties.setProperty("s3service.s3-endpoint", endpoint);
}
if (StringUtils.isBlank(bucketName)) {
if (log.isDebugEnabled()) {
log.debug(String.format("Determine bucket from hostname %s", host.getHostname()));
}
final String bucketNameInHostname = RequestEntityRestStorageService.findBucketInHostname(host);
if (bucketNameInHostname != null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Determined bucket %s from hostname %s", bucketNameInHostname, host.getHostname()));
}
if (!StringUtils.startsWith(properties.getStringProperty("s3service.s3-endpoint", host.getProtocol().getDefaultHostname()), bucketNameInHostname)) {
final String endpoint = String.format("%s.%s", bucketNameInHostname, properties.getStringProperty("s3service.s3-endpoint", host.getProtocol().getDefaultHostname()));
if (log.isDebugEnabled()) {
log.debug(String.format("Set endpoint to %s", endpoint));
}
properties.setProperty("s3service.s3-endpoint", endpoint);
}
}
}
}
}
}
final HttpUriRequest request = super.setupConnection(method, bucketName, objectKey, requestParameters);
if (preferences.getBoolean("s3.upload.expect-continue")) {
if ("PUT".equals(request.getMethod())) {
// #7621
if (!properties.getBoolProperty("s3service.disable-expect-continue", false)) {
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
}
}
if (preferences.getBoolean("s3.bucket.requesterpays")) {
// Only for AWS
if (S3Session.isAwsHostname(host.getHostname())) {
// Downloading Objects in Requester Pays Buckets
if ("GET".equals(request.getMethod()) || "POST".equals(request.getMethod())) {
if (!properties.getBoolProperty("s3service.disable-request-payer", false)) {
// For GET and POST requests, include x-amz-request-payer : requester in the header
request.addHeader("x-amz-request-payer", "requester");
}
}
}
}
return request;
}
use of ch.cyberduck.core.features.Location in project cyberduck by iterate-ch.
the class QloudsonicTransferAcceleration method configure.
@Override
public void configure(final boolean enable, final Path file) throws BackgroundException {
final Location.Name location = session.getFeature(Location.class).getLocation(file);
if (Location.unknown.equals(location)) {
throw new AccessDeniedException("Cannot read bucket location");
}
final UDTProxyConfigurator configurator = new UDTProxyConfigurator(location, this.provider(), new KeychainX509TrustManager(new DisabledCertificateTrustCallback(), new DefaultTrustManagerHostnameCallback(session.getHost()), new DisabledCertificateStore()), new KeychainX509KeyManager(new DisabledCertificateIdentityCallback(), session.getHost(), new DisabledCertificateStore()));
configurator.configure(session);
}
Aggregations