Search in sources :

Example 1 with HostWebUrlProvider

use of ch.cyberduck.core.HostWebUrlProvider in project cyberduck by iterate-ch.

the class DefaultUrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.attributes().getLink() != DescriptiveUrl.EMPTY) {
        list.add(file.attributes().getLink());
    }
    list.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(host), URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), host.getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))));
    list.addAll(new HostWebUrlProvider(host).toUrl(file));
    return list;
}
Also used : HostWebUrlProvider(ch.cyberduck.core.HostWebUrlProvider) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) HostUrlProvider(ch.cyberduck.core.HostUrlProvider) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag)

Example 2 with HostWebUrlProvider

use of ch.cyberduck.core.HostWebUrlProvider in project cyberduck by iterate-ch.

the class SwiftUrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.isFile()) {
        Region region = null;
        try {
            region = regionService.lookup(file);
        } catch (BackgroundException e) {
            log.warn(String.format("Failure looking up region for %s %s", file, e.getMessage()));
        }
        if (null == region) {
            list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file));
        } else {
            list.addAll(new HostWebUrlProvider(session.getHost()).toUrl(file));
            list.add(new DescriptiveUrl(URI.create(region.getStorageUrl(containerService.getContainer(file).getName(), containerService.getKey(file)).toString()), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().name().toUpperCase(Locale.ROOT))));
            // In one hour
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.HOURS.toSeconds(1))));
            // Default signed URL expiring in 24 hours.
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.SECONDS.toSeconds(new HostPreferences(session.getHost()).getInteger("s3.url.expire.seconds")))));
            // 1 Week
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(7))));
            // 1 Month
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(30))));
            // 1 Year
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(365))));
        }
    }
    // Filter by matching container name
    final Optional<Set<Distribution>> filtered = distributions.entrySet().stream().filter(entry -> new SimplePathPredicate(containerService.getContainer(file)).test(entry.getKey())).map(Map.Entry::getValue).findFirst();
    if (filtered.isPresent()) {
        // Add CloudFront distributions
        for (Distribution distribution : filtered.get()) {
            list.addAll(new DistributionUrlProvider(distribution).toUrl(file));
        }
    }
    return list;
}
Also used : HostWebUrlProvider(ch.cyberduck.core.HostWebUrlProvider) Set(java.util.Set) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DefaultUrlProvider(ch.cyberduck.core.shared.DefaultUrlProvider) Distribution(ch.cyberduck.core.cdn.Distribution) Region(ch.iterate.openstack.swift.model.Region) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) Map(java.util.Map) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DistributionUrlProvider(ch.cyberduck.core.cdn.DistributionUrlProvider)

Example 3 with HostWebUrlProvider

use of ch.cyberduck.core.HostWebUrlProvider in project cyberduck by iterate-ch.

the class S3UrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (session.getClient().getConfiguration().getBoolProperty("s3service.disable-dns-buckets", false)) {
        list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file));
    } else {
        list.add(this.toUrl(file, session.getHost().getProtocol().getScheme(), session.getHost().getPort()));
        list.add(this.toUrl(file, Scheme.http, 80));
        if (StringUtils.isNotBlank(session.getHost().getWebURL())) {
            // Only include when custom domain is configured
            list.addAll(new HostWebUrlProvider(session.getHost()).toUrl(file));
        }
    }
    if (file.isFile()) {
        if (!session.getHost().getCredentials().isAnonymousLogin()) {
            // X-Amz-Expires must be less than a week (in seconds); that is, the given X-Amz-Expires must be less
            // than 604800 seconds
            // In one hour
            list.add(this.toSignedUrl(file, (int) TimeUnit.HOURS.toSeconds(1)));
            // Default signed URL expiring in 24 hours.
            list.add(this.toSignedUrl(file, (int) TimeUnit.SECONDS.toSeconds(new HostPreferences(session.getHost()).getInteger("s3.url.expire.seconds"))));
            // 1 Week
            list.add(this.toSignedUrl(file, (int) TimeUnit.DAYS.toSeconds(7)));
            switch(session.getSignatureVersion()) {
                case AWS2:
                    // 1 Month
                    list.add(this.toSignedUrl(file, (int) TimeUnit.DAYS.toSeconds(30)));
                    // 1 Year
                    list.add(this.toSignedUrl(file, (int) TimeUnit.DAYS.toSeconds(365)));
                    break;
                case AWS4HMACSHA256:
                    break;
            }
        }
    }
    // AWS services require specifying an Amazon S3 bucket using S3://bucket
    list.add(new DescriptiveUrl(URI.create(String.format("s3://%s%s", containerService.getContainer(file).getName(), file.isRoot() ? Path.DELIMITER : containerService.isContainer(file) ? Path.DELIMITER : String.format("/%s", URIEncoder.encode(containerService.getKey(file))))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), "S3")));
    // Filter by matching container name
    final Optional<Set<Distribution>> filtered = distributions.entrySet().stream().filter(entry -> new SimplePathPredicate(containerService.getContainer(file)).test(entry.getKey())).map(Map.Entry::getValue).findFirst();
    if (filtered.isPresent()) {
        // Add CloudFront distributions
        for (Distribution distribution : filtered.get()) {
            list.addAll(new DistributionUrlProvider(distribution).toUrl(file));
        }
    }
    return list;
}
Also used : HostWebUrlProvider(ch.cyberduck.core.HostWebUrlProvider) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) Set(java.util.Set) DefaultUrlProvider(ch.cyberduck.core.shared.DefaultUrlProvider) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag) Distribution(ch.cyberduck.core.cdn.Distribution) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) Map(java.util.Map) DistributionUrlProvider(ch.cyberduck.core.cdn.DistributionUrlProvider) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Aggregations

DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)3 DescriptiveUrlBag (ch.cyberduck.core.DescriptiveUrlBag)3 HostWebUrlProvider (ch.cyberduck.core.HostWebUrlProvider)3 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)2 Distribution (ch.cyberduck.core.cdn.Distribution)2 DistributionUrlProvider (ch.cyberduck.core.cdn.DistributionUrlProvider)2 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)2 DefaultUrlProvider (ch.cyberduck.core.shared.DefaultUrlProvider)2 Map (java.util.Map)2 Set (java.util.Set)2 HostUrlProvider (ch.cyberduck.core.HostUrlProvider)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Region (ch.iterate.openstack.swift.model.Region)1