| 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.openstack.swift.config; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.concurrent.Future; |
| 23 | |
| 24 | import javax.inject.Inject; |
| 25 | import javax.inject.Named; |
| 26 | import javax.inject.Singleton; |
| 27 | |
| 28 | import org.jclouds.Constants; |
| 29 | import org.jclouds.http.RequiresHttp; |
| 30 | import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse; |
| 31 | import org.jclouds.openstack.config.OpenStackAuthenticationModule.GetAuthenticationResponse; |
| 32 | import org.jclouds.openstack.reference.AuthHeaders; |
| 33 | import org.jclouds.openstack.swift.CommonSwiftAsyncClient; |
| 34 | import org.jclouds.openstack.swift.CommonSwiftClient; |
| 35 | import org.jclouds.openstack.swift.SwiftAsyncClient; |
| 36 | import org.jclouds.openstack.swift.SwiftClient; |
| 37 | import org.jclouds.rest.AsyncClientFactory; |
| 38 | import org.jclouds.rest.ConfiguresRestClient; |
| 39 | |
| 40 | import com.google.inject.Provides; |
| 41 | |
| 42 | /** |
| 43 | * |
| 44 | * @author Adrian Cole |
| 45 | */ |
| 46 | @ConfiguresRestClient |
| 47 | @RequiresHttp |
| 48 | public class SwiftRestClientModule extends BaseSwiftRestClientModule<SwiftClient, SwiftAsyncClient> { |
| 49 | |
| 50 | public SwiftRestClientModule() { |
| 51 | super(SwiftClient.class, SwiftAsyncClient.class); |
| 52 | } |
| 53 | |
| 54 | @Provides |
| 55 | @Singleton |
| 56 | CommonSwiftClient provideCommonSwiftClient(SwiftClient in) { |
| 57 | return in; |
| 58 | } |
| 59 | |
| 60 | @Provides |
| 61 | @Singleton |
| 62 | CommonSwiftAsyncClient provideCommonSwiftClient(SwiftAsyncClient in) { |
| 63 | return in; |
| 64 | } |
| 65 | |
| 66 | @Singleton |
| 67 | public static class GetAuthenticationResponseForStorage extends GetAuthenticationResponse { |
| 68 | @Inject |
| 69 | public GetAuthenticationResponseForStorage(AsyncClientFactory factory, |
| 70 | @Named(Constants.PROPERTY_IDENTITY) String user, @Named(Constants.PROPERTY_CREDENTIAL) String key) { |
| 71 | super(factory, user, key); |
| 72 | } |
| 73 | |
| 74 | protected Future<AuthenticationResponse> authenticate() { |
| 75 | return client.authenticateStorage(user, key); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | |
| 80 | protected URI provideStorageUrl(AuthenticationResponse response) { |
| 81 | return response.getServices().get(AuthHeaders.STORAGE_URL); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | protected void configure() { |
| 86 | bind(GetAuthenticationResponse.class).to(GetAuthenticationResponseForStorage.class); |
| 87 | super.configure(); |
| 88 | } |
| 89 | } |