From c98ce48a0f09cb60e907d5a4807ab725017dd3fe Mon Sep 17 00:00:00 2001 From: David Kocher Date: Wed, 1 Dec 2010 23:30:24 +0000 Subject: [PATCH] Add default HTTP headers support for uploads in S3, Azure and Cloud Files. #5364. --- source/ch/cyberduck/core/Preferences.java | 10 ++++++- source/ch/cyberduck/core/azure/AzurePath.java | 26 +++++++++++++++++++ source/ch/cyberduck/core/cf/CFPath.java | 23 ++++++++++++++++ source/ch/cyberduck/core/s3/S3Path.java | 2 +- 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/source/ch/cyberduck/core/Preferences.java b/source/ch/cyberduck/core/Preferences.java index 74c149d05d6..4d94756b582 100644 --- a/source/ch/cyberduck/core/Preferences.java +++ b/source/ch/cyberduck/core/Preferences.java @@ -533,6 +533,8 @@ protected void setDefaults() { * Default metadata for uploads. Format must be "key1=value1 key2=value2" */ defaults.put("s3.metadata.default", ""); + defaults.put("cf.metadata.default", ""); + defaults.put("azure.metadata.default", ""); defaults.put("webdav.followRedirects", String.valueOf(true)); @@ -671,6 +673,10 @@ protected void setDefaults() { defaults.put("ssh.publickey", "ssh-rsa"); defaults.put("ssh.compression", "none"); //zlib + defaults.put("ssh.authentication.publikey.default.enable", String.valueOf(true)); + defaults.put("ssh.authentication.publickey.default.rsa", "~/.ssh/id_rsa"); + defaults.put("ssh.authentication.publickey.default.dsa", "~/.ssh/id_dsa"); + defaults.put("archive.default", "tar.gz"); /** @@ -723,7 +729,9 @@ public String getDefault(String property) { * @param property * @return */ - public abstract List getList(String property); + public List getList(String property) { + return Arrays.asList(this.getProperty(property).split("\\p{javaWhitespace}+")); + } /** * Give value in user settings or default value if not customized. diff --git a/source/ch/cyberduck/core/azure/AzurePath.java b/source/ch/cyberduck/core/azure/AzurePath.java index bb8fbf74373..e191a176453 100644 --- a/source/ch/cyberduck/core/azure/AzurePath.java +++ b/source/ch/cyberduck/core/azure/AzurePath.java @@ -26,6 +26,7 @@ import ch.cyberduck.ui.DateFormatterFactory; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.log4j.Logger; @@ -470,6 +471,31 @@ protected void upload(final BandwidthThrottle throttle, final StreamListener lis AzureSession.AzureContainer container = this.getSession().getContainer(this.getContainerName()); final BlobProperties properties = new BlobProperties(this.getKey()); properties.setContentType(this.getLocal().getMimeType()); + NameValueCollection metadata = new NameValueCollection(); + // Default metadata for new files + for(String m : Preferences.instance().getList("azure.metadata.default")) { + if(StringUtils.isBlank(m)) { + log.warn("Invalid header " + m); + continue; + } + if(!m.contains("=")) { + log.warn("Invalid header " + m); + continue; + } + int split = m.indexOf('='); + String name = m.substring(0, split); + if(StringUtils.isBlank(name)) { + log.warn("Missing key in " + m); + continue; + } + String value = m.substring(split + 1); + if(StringUtils.isEmpty(value)) { + log.warn("Missing value in " + m); + continue; + } + metadata.put(name, value); + } + properties.setMetadata(metadata); boolean blob = container.createBlob(properties, new HttpEntity() { public boolean isRepeatable() { return false; diff --git a/source/ch/cyberduck/core/cf/CFPath.java b/source/ch/cyberduck/core/cf/CFPath.java index 63fec982175..de97c424a64 100644 --- a/source/ch/cyberduck/core/cf/CFPath.java +++ b/source/ch/cyberduck/core/cf/CFPath.java @@ -319,6 +319,29 @@ protected void upload(final BandwidthThrottle throttle, final StreamListener lis String etag = null; try { final HashMap metadata = new HashMap(); + // Default metadata for new files + for(String m : Preferences.instance().getList("cf.metadata.default")) { + if(StringUtils.isBlank(m)) { + log.warn("Invalid header " + m); + continue; + } + if(!m.contains("=")) { + log.warn("Invalid header " + m); + continue; + } + int split = m.indexOf('='); + String name = m.substring(0, split); + if(StringUtils.isBlank(name)) { + log.warn("Missing key in " + m); + continue; + } + String value = m.substring(split + 1); + if(StringUtils.isEmpty(value)) { + log.warn("Missing value in " + m); + continue; + } + metadata.put(name, value); + } etag = this.getSession().getClient().storeObjectAs(this.getContainerName(), this.getKey(), new InputStreamRequestEntity(in, this.getLocal().attributes().getSize() - status.getCurrent(), diff --git a/source/ch/cyberduck/core/s3/S3Path.java b/source/ch/cyberduck/core/s3/S3Path.java index a26833dba27..ebded673730 100644 --- a/source/ch/cyberduck/core/s3/S3Path.java +++ b/source/ch/cyberduck/core/s3/S3Path.java @@ -546,7 +546,7 @@ else if(acl.equals(this.getSession().getPublicAcl(this.getContainerName(), true, // Storage class object.setStorageClass(Preferences.instance().getProperty("s3.storage.class")); // Default metadata for new files - for(String m : Preferences.instance().getProperty("s3.metadata.default").split("\\p{javaWhitespace}+")) { + for(String m : Preferences.instance().getList("s3.metadata.default")) { if(StringUtils.isBlank(m)) { log.warn("Invalid header " + m); continue;