| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.s3; |
| 20 | |
| 21 | import static org.jclouds.Constants.PROPERTY_API_VERSION; |
| 22 | import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; |
| 23 | import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; |
| 24 | import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; |
| 25 | import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER; |
| 26 | import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX; |
| 27 | import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; |
| 28 | import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH; |
| 29 | import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS; |
| 30 | |
| 31 | import java.util.Properties; |
| 32 | |
| 33 | import org.jclouds.PropertiesBuilder; |
| 34 | import org.jclouds.s3.reference.S3Headers; |
| 35 | |
| 36 | /** |
| 37 | * Builds properties used in S3 Connections |
| 38 | * |
| 39 | * @author Adrian Cole |
| 40 | */ |
| 41 | public class S3PropertiesBuilder extends PropertiesBuilder { |
| 42 | @Override |
| 43 | protected Properties defaultProperties() { |
| 44 | Properties properties = super.defaultProperties(); |
| 45 | properties.setProperty(PROPERTY_API_VERSION, S3AsyncClient.VERSION); |
| 46 | properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); |
| 47 | properties.setProperty(PROPERTY_HEADER_TAG, S3Headers.DEFAULT_AMAZON_HEADERTAG); |
| 48 | properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/"); |
| 49 | properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true"); |
| 50 | properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); |
| 51 | properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, DIRECTORY_SUFFIX_FOLDER); |
| 52 | return properties; |
| 53 | } |
| 54 | |
| 55 | public S3PropertiesBuilder(Properties properties) { |
| 56 | super(properties); |
| 57 | } |
| 58 | |
| 59 | public S3PropertiesBuilder() { |
| 60 | super(); |
| 61 | } |
| 62 | |
| 63 | protected S3PropertiesBuilder withMetaPrefix(String prefix) { |
| 64 | properties.setProperty(PROPERTY_USER_METADATA_PREFIX, prefix); |
| 65 | return this; |
| 66 | } |
| 67 | |
| 68 | protected void setMetaPrefix() { |
| 69 | if (properties.getProperty(PROPERTY_USER_METADATA_PREFIX) == null) { |
| 70 | properties.setProperty(PROPERTY_USER_METADATA_PREFIX, String.format("x-%s-meta-", properties |
| 71 | .getProperty(PROPERTY_HEADER_TAG))); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public Properties build() { |
| 77 | setMetaPrefix(); |
| 78 | return super.build(); |
| 79 | } |
| 80 | } |