| 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.aws.s3.config; |
| 20 | |
| 21 | import static org.jclouds.aws.domain.Region.US_STANDARD; |
| 22 | import static org.jclouds.location.reference.LocationConstants.ENDPOINT; |
| 23 | import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; |
| 24 | |
| 25 | import java.net.URI; |
| 26 | |
| 27 | import javax.inject.Named; |
| 28 | import javax.inject.Singleton; |
| 29 | |
| 30 | import org.jclouds.aws.s3.AWSS3AsyncClient; |
| 31 | import org.jclouds.aws.s3.AWSS3Client; |
| 32 | import org.jclouds.aws.s3.binders.AssignCorrectHostnameAndBindAsHostPrefixIfConfigured; |
| 33 | import org.jclouds.http.RequiresHttp; |
| 34 | import org.jclouds.location.Region; |
| 35 | import org.jclouds.rest.ConfiguresRestClient; |
| 36 | import org.jclouds.s3.Bucket; |
| 37 | import org.jclouds.s3.S3AsyncClient; |
| 38 | import org.jclouds.s3.S3Client; |
| 39 | import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured; |
| 40 | import org.jclouds.s3.config.S3RestClientModule; |
| 41 | |
| 42 | import com.google.inject.Provides; |
| 43 | |
| 44 | /** |
| 45 | * Configures the S3 connection. |
| 46 | * |
| 47 | * @author Adrian Cole |
| 48 | */ |
| 49 | @RequiresHttp |
| 50 | @ConfiguresRestClient |
| 51 | public class AWSS3RestClientModule extends S3RestClientModule<AWSS3Client, AWSS3AsyncClient> { |
| 52 | |
| 53 | @Provides |
| 54 | @Singleton |
| 55 | @Bucket |
| 56 | protected URI provideBucketURI(@Named(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT) String endpoint) { |
| 57 | return URI.create(endpoint); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected String defaultRegionForBucket(@Region String defaultRegion) { |
| 62 | return US_STANDARD; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected void configure() { |
| 67 | bind(BindAsHostPrefixIfConfigured.class).to(AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.class); |
| 68 | super.configure(); |
| 69 | } |
| 70 | |
| 71 | public AWSS3RestClientModule() { |
| 72 | super(AWSS3Client.class, AWSS3AsyncClient.class); |
| 73 | } |
| 74 | |
| 75 | @Singleton |
| 76 | @Provides |
| 77 | S3Client provide(AWSS3Client in) { |
| 78 | return in; |
| 79 | } |
| 80 | |
| 81 | @Singleton |
| 82 | @Provides |
| 83 | S3AsyncClient provide(AWSS3AsyncClient in) { |
| 84 | return in; |
| 85 | } |
| 86 | |
| 87 | } |