@Test public void testTempUrl() { final Region region = new Region("DFW", URI.create("http: Map<Region, AccountInfo> accounts = new HashMap<Region, AccountInfo>(); accounts.put(region, new AccountInfo(1L, 1, "k")); final Path container = new Path("test w.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path file = new Path(container, "key f", EnumSet.of(Path.Type.file)); final Path file2 = new Path(file, "key2", EnumSet.of(Path.Type.file)); final SwiftUrlProvider provider = new SwiftUrlProvider(session, accounts); final Iterator<DescriptiveUrl> iterator = provider.sign(region, file2, 1379500716).iterator(); assertEquals("http: iterator.next().getUrl()); }
protected DescriptiveUrlBag sign(final Region region, final Path file, final long expiry) { if(!accounts.containsKey(region)) { log.warn(String.format("No account info for region %s available required to sign temporary URL", region)); return DescriptiveUrlBag.empty(); } final AccountInfo info = accounts.get(region); if(StringUtils.isBlank(info.getTempUrlKey())) { log.warn("Missing X-Account-Meta-Temp-URL-Key header value to sign temporary URL"); return DescriptiveUrlBag.empty(); } if(log.isInfoEnabled()) { log.info(String.format("Using X-Account-Meta-Temp-URL-Key header value %s to sign", info.getTempUrlKey())); } final String signature = this.sign(info.getTempUrlKey(), 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)))); final DescriptiveUrlBag list = new DescriptiveUrlBag(); for(Scheme scheme : Collections.singletonList(Scheme.valueOf(region.getStorageUrl().getScheme()))) { final int port = region.getStorageUrl().getPort(); list.add(new DescriptiveUrl(URI.create(String.format("%s: scheme.name(), region.getStorageUrl().getHost(), port == -1 ? StringUtils.EMPTY : port == scheme.getPort() ? StringUtils.EMPTY : String.format(":%d", port), region.getStorageUrl( containerService.getContainer(file).getName(), containerService.getKey(file)).getRawPath(), signature, expiry)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000)) )); } return list; }
SwiftUrlProvider implements UrlProvider { protected DescriptiveUrlBag sign(final Region region, final Path file, final long expiry) { if(!accounts.containsKey(region)) { log.warn(String.format("No account info for region %s available required to sign temporary URL", region)); return DescriptiveUrlBag.empty(); } final AccountInfo info = accounts.get(region); if(StringUtils.isBlank(info.getTempUrlKey())) { log.warn("Missing X-Account-Meta-Temp-URL-Key header value to sign temporary URL"); return DescriptiveUrlBag.empty(); } if(log.isInfoEnabled()) { log.info(String.format("Using X-Account-Meta-Temp-URL-Key header value %s to sign", info.getTempUrlKey())); } final String signature = this.sign(info.getTempUrlKey(), 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)))); final DescriptiveUrlBag list = new DescriptiveUrlBag(); for(Scheme scheme : Collections.singletonList(Scheme.valueOf(region.getStorageUrl().getScheme()))) { final int port = region.getStorageUrl().getPort(); list.add(new DescriptiveUrl(URI.create(String.format("%s: scheme.name(), region.getStorageUrl().getHost(), port == -1 ? StringUtils.EMPTY : port == scheme.getPort() ? StringUtils.EMPTY : String.format(":%d", port), region.getStorageUrl( containerService.getContainer(file).getName(), containerService.getKey(file)).getRawPath(), signature, expiry)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000)) )); } return list; } }
SwiftUrlProvider implements UrlProvider { protected DescriptiveUrlBag sign(final Region region, final Path file, final long expiry) { if(!accounts.containsKey(region)) { log.warn(String.format("No account info for region %s available required to sign temporary URL", region)); return DescriptiveUrlBag.empty(); } final AccountInfo info = accounts.get(region); if(StringUtils.isBlank(info.getTempUrlKey())) { log.warn("Missing X-Account-Meta-Temp-URL-Key header value to sign temporary URL"); return DescriptiveUrlBag.empty(); } if(log.isInfoEnabled()) { log.info(String.format("Using X-Account-Meta-Temp-URL-Key header value %s to sign", info.getTempUrlKey())); } final String signature = this.sign(info.getTempUrlKey(), 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)))); final DescriptiveUrlBag list = new DescriptiveUrlBag(); for(Scheme scheme : Collections.singletonList(Scheme.valueOf(region.getStorageUrl().getScheme()))) { final int port = region.getStorageUrl().getPort(); list.add(new DescriptiveUrl(URI.create(String.format("%s: scheme.name(), region.getStorageUrl().getHost(), port == -1 ? StringUtils.EMPTY : port == scheme.getPort() ? StringUtils.EMPTY : String.format(":%d", port), region.getStorageUrl( containerService.getContainer(file).getName(), containerService.getKey(file)).getRawPath(), signature, expiry)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000)) )); } return list; } SwiftUrlProvider(final SwiftSession session);  SwiftUrlProvider(final SwiftSession session, final Map<Region, AccountInfo> accounts);  SwiftUrlProvider(final SwiftSession session, final Map<Region, AccountInfo> accounts, final SwiftRegionService regionService); }
SwiftUrlProvider implements UrlProvider { protected DescriptiveUrlBag sign(final Region region, final Path file, final long expiry) { if(!accounts.containsKey(region)) { log.warn(String.format("No account info for region %s available required to sign temporary URL", region)); return DescriptiveUrlBag.empty(); } final AccountInfo info = accounts.get(region); if(StringUtils.isBlank(info.getTempUrlKey())) { log.warn("Missing X-Account-Meta-Temp-URL-Key header value to sign temporary URL"); return DescriptiveUrlBag.empty(); } if(log.isInfoEnabled()) { log.info(String.format("Using X-Account-Meta-Temp-URL-Key header value %s to sign", info.getTempUrlKey())); } final String signature = this.sign(info.getTempUrlKey(), 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)))); final DescriptiveUrlBag list = new DescriptiveUrlBag(); for(Scheme scheme : Collections.singletonList(Scheme.valueOf(region.getStorageUrl().getScheme()))) { final int port = region.getStorageUrl().getPort(); list.add(new DescriptiveUrl(URI.create(String.format("%s: scheme.name(), region.getStorageUrl().getHost(), port == -1 ? StringUtils.EMPTY : port == scheme.getPort() ? StringUtils.EMPTY : String.format(":%d", port), region.getStorageUrl( containerService.getContainer(file).getName(), containerService.getKey(file)).getRawPath(), signature, expiry)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000)) )); } return list; } SwiftUrlProvider(final SwiftSession session);  SwiftUrlProvider(final SwiftSession session, final Map<Region, AccountInfo> accounts);  SwiftUrlProvider(final SwiftSession session, final Map<Region, AccountInfo> accounts, final SwiftRegionService regionService); @Override DescriptiveUrlBag toUrl(final Path file); }
SwiftUrlProvider implements UrlProvider { protected DescriptiveUrlBag sign(final Region region, final Path file, final long expiry) { if(!accounts.containsKey(region)) { log.warn(String.format("No account info for region %s available required to sign temporary URL", region)); return DescriptiveUrlBag.empty(); } final AccountInfo info = accounts.get(region); if(StringUtils.isBlank(info.getTempUrlKey())) { log.warn("Missing X-Account-Meta-Temp-URL-Key header value to sign temporary URL"); return DescriptiveUrlBag.empty(); } if(log.isInfoEnabled()) { log.info(String.format("Using X-Account-Meta-Temp-URL-Key header value %s to sign", info.getTempUrlKey())); } final String signature = this.sign(info.getTempUrlKey(), 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)))); final DescriptiveUrlBag list = new DescriptiveUrlBag(); for(Scheme scheme : Collections.singletonList(Scheme.valueOf(region.getStorageUrl().getScheme()))) { final int port = region.getStorageUrl().getPort(); list.add(new DescriptiveUrl(URI.create(String.format("%s: scheme.name(), region.getStorageUrl().getHost(), port == -1 ? StringUtils.EMPTY : port == scheme.getPort() ? StringUtils.EMPTY : String.format(":%d", port), region.getStorageUrl( containerService.getContainer(file).getName(), containerService.getKey(file)).getRawPath(), signature, expiry)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000)) )); } return list; } SwiftUrlProvider(final SwiftSession session);  SwiftUrlProvider(final SwiftSession session, final Map<Region, AccountInfo> accounts);  SwiftUrlProvider(final SwiftSession session, final Map<Region, AccountInfo> accounts, final SwiftRegionService regionService); @Override DescriptiveUrlBag toUrl(final Path file);  }