public String get(final Scheme scheme, final int port, final String username, final String hostname, final String path) { final String base = String.format("%s://%s%s%s", scheme, includeUsername && StringUtils.isNotEmpty(username) ? String.format("%s@", URIEncoder.encode(username)) : "", new PunycodeConverter().convert(hostname), port != scheme.getPort() ? String.format(":%d", port) : ""); if(includePath) { if(StringUtils.isNotBlank(path)) { return String.format("%s%s", base, PathNormalizer.normalize(path)); } } return base; } }
/** * @param file File in origin container * @param origin Distribution URL * @return URL to file in distribution */ private URI toUrl(final Path file, final URI origin) { final StringBuilder b = new StringBuilder(String.format("%s://%s", origin.getScheme(), origin.getHost())); if(distribution.getMethod().equals(Distribution.CUSTOM)) { b.append(Path.DELIMITER).append(URIEncoder.encode(PathRelativizer.relativize(origin.getRawPath(), file.getAbsolute()))); } else { if(StringUtils.isNotEmpty(origin.getRawPath())) { b.append(origin.getRawPath()); } if(StringUtils.isNotEmpty(containerService.getKey(file))) { b.append(Path.DELIMITER).append(URIEncoder.encode(containerService.getKey(file))); } } return URI.create(b.toString()).normalize(); }
public String encode(final Path file) { final String encoded = URIEncoder.encode(file.getAbsolute()); if(file.isDirectory()) { if(file.isRoot()) { return encoded; } return String.format("%s/", encoded); } return encoded; } }
/** * @param file File in origin container * @return CNAME to distribution */ private List<DescriptiveUrl> toCnameUrl(final Path file) { final List<DescriptiveUrl> urls = new ArrayList<DescriptiveUrl>(); for(String cname : distribution.getCNAMEs()) { final StringBuilder b = new StringBuilder(); b.append(String.format("%s://%s", distribution.getMethod().getScheme(), cname)).append(distribution.getMethod().getContext()); if(StringUtils.isNotEmpty(containerService.getKey(file))) { b.append(Path.DELIMITER).append(URIEncoder.encode(containerService.getKey(file))); } urls.add(new DescriptiveUrl(URI.create(b.toString()).normalize(), DescriptiveUrl.Type.cname, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))); } return urls; } }
@Override public URI toURI(final boolean includePassword) throws JargonException { try { return new URI(String.format("irods://%s.%s%s@%s:%d%s", this.getUserName(), this.getZone(), includePassword ? String.format(":%s", this.getPassword()) : StringUtils.EMPTY, this.getHost(), this.getPort(), URIEncoder.encode(this.getHomeDirectory()))); } catch(URISyntaxException e) { throw new JargonException(e.getMessage()); } }
/** * Properly URI encode and prepend the bucket name. * * @param scheme Protocol * @return URL to be displayed in browser */ protected DescriptiveUrl toUrl(final Path file, final Scheme scheme) { final StringBuilder url = new StringBuilder(scheme.name()); url.append("://"); if(file.isRoot()) { url.append(session.getHost().getHostname()); } else { final String hostname = this.getHostnameForContainer(containerService.getContainer(file)); if(hostname.startsWith(containerService.getContainer(file).getName())) { url.append(hostname); if(!containerService.isContainer(file)) { url.append(Path.DELIMITER); url.append(URIEncoder.encode(containerService.getKey(file))); } } else { url.append(session.getHost().getHostname()); url.append(URIEncoder.encode(file.getAbsolute())); } } return new DescriptiveUrl(URI.create(url.toString()), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), scheme.name().toUpperCase(Locale.ROOT))); }
@Override public DescriptiveUrlBag toUrl(final Path file) { if(file.isVolume()) { return DescriptiveUrlBag.empty(); } final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.isFile()) { final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file))); list.add(new DescriptiveUrl(URI.create(download), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT)))); } return list; } }
/** * This creates an URL that uses Cookie-based Authentication. The ACLs for the given Google user account * has to be setup first. * <p> * Google Storage lets you provide browser-based authenticated downloads to users who do not have * Google Storage accounts. To do this, you apply Google account-based ACLs to the object and then * you provide users with a URL that is scoped to the object. */ @Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DefaultUrlProvider(session.getHost()).toUrl(file); if(file.isFile()) { // Authenticated browser download using cookie-based Google account authentication in conjunction with ACL list.add(new DescriptiveUrl(URI.create(String.format("https://storage.cloud.google.com%s", URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.authenticated, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Authenticated")))); } return list; } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); final DescriptiveUrl base = this.toUrl(); list.add(new DescriptiveUrl(URI.create(String.format("%s%s", base.getUrl(), URIEncoder.encode( PathNormalizer.normalize(PathRelativizer.relativize(PathNormalizer.normalize(host.getDefaultPath(), true), file.getAbsolute())) ))).normalize(), base.getType(), base.getHelp()) ); return list; }
String.format("GET\n%d\n%s", expiry, String.format("%s/%s/%s", region.getStorageUrl().getRawPath(), URIEncoder.encode(containerService.getContainer(file).getName()), containerService.getKey(file))));
@Override public DescriptiveUrlBag toUrl(final Path file) { try { final DescriptiveUrlBag set = delegate.toUrl(file); final Path encrypt = vault.encrypt(session, file); set.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode(encrypt.getAbsolute()))), DescriptiveUrl.Type.encrypted, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Encrypted", "Cryptomator"))) ); return set; } catch(BackgroundException e) { log.warn(String.format("Failure encrypting filename. %s", e.getMessage())); return DescriptiveUrlBag.empty(); } }
@Override public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException { if(file.isFile()) { final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file))); try { final int seconds = 604800; // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String token = session.getClient().getDownloadAuthorization(fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), StringUtils.EMPTY, seconds); return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } return DescriptiveUrl.EMPTY; }
@Override public DescriptiveUrlBag toUrl(final Path file) { final String nodeid = file.isDirectory() ? file.attributes().getVersionId() : file.getParent().attributes().getVersionId(); if(StringUtils.isBlank(nodeid)) { return DescriptiveUrlBag.empty(); } return new DescriptiveUrlBag(Collections.singletonList( new DescriptiveUrl(URI.create(String.format("%s/#/node/%s", new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode( nodeid ))), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))) )); } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.attributes().getLink() != null) { 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 WebUrlProvider(host).toUrl(file)); return list; } }
PathNormalizer.name(URIEncoder.encode(bucket.getName())), prefix, delimiter, chunksize, priorLastKey);
null, String.format("type:eq:%s|name:cn:%s", type, URIEncoder.encode(file.getName())), null, null, null, StringUtils.EMPTY, null); for(Node node : nodes.getItems()) {
private DescriptiveUrl createSignedUrl(final Path file, int seconds) { final CloudBlob blob; try { if(!session.isConnected()) { return DescriptiveUrl.EMPTY; } blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); } catch(URISyntaxException | StorageException e) { return DescriptiveUrl.EMPTY; } final String token; try { token = blob.generateSharedAccessSignature(this.getPolicy(seconds), null); } catch(InvalidKeyException | StorageException e) { return DescriptiveUrl.EMPTY; } return new DescriptiveUrl(URI.create(String.format("%s://%s%s?%s", Scheme.https.name(), session.getHost().getHostname(), URIEncoder.encode(file.getAbsolute()), token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(this.getExpiry(seconds)))); }
public void create(final Path bucket, final String location) throws BackgroundException { if(!session.configure().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { final String region; if("us-east-1".equals(location)) { region = "US"; } else { region = location; } // Create bucket session.getClient().createBucket(URIEncoder.encode(containerService.getContainer(bucket).getName()), region, acl); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot create folder {0}", e, bucket); } } }
final String joinedPath = new WebUrlProvider(session.getHost()).toUrl() + URIEncoder.encode(object.getPath()); try { final URI link = new URI(joinedPath);