1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * 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, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.openstack.swift.blobstore; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | import static org.jclouds.blobstore.util.BlobStoreUtils.cleanRequest; |
23 | |
24 | import java.lang.reflect.Method; |
25 | |
26 | import javax.inject.Inject; |
27 | import javax.inject.Singleton; |
28 | |
29 | import org.jclouds.blobstore.BlobRequestSigner; |
30 | import org.jclouds.blobstore.domain.Blob; |
31 | import org.jclouds.http.HttpRequest; |
32 | import org.jclouds.http.options.GetOptions; |
33 | import org.jclouds.openstack.swift.CommonSwiftAsyncClient; |
34 | import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; |
35 | import org.jclouds.openstack.swift.domain.SwiftObject; |
36 | import org.jclouds.rest.internal.RestAnnotationProcessor; |
37 | |
38 | /** |
39 | * |
40 | * @author Adrian Cole |
41 | */ |
42 | @Singleton |
43 | public class SwiftBlobRequestSigner implements BlobRequestSigner { |
44 | private final RestAnnotationProcessor<CommonSwiftAsyncClient> processor; |
45 | private final BlobToObject blobToObject; |
46 | private final Method getMethod; |
47 | private final Method deleteMethod; |
48 | private final Method createMethod; |
49 | |
50 | @Inject |
51 | public SwiftBlobRequestSigner(RestAnnotationProcessor<CommonSwiftAsyncClient> processor, BlobToObject blobToObject) |
52 | throws SecurityException, NoSuchMethodException { |
53 | this.processor = checkNotNull(processor, "processor"); |
54 | this.blobToObject = checkNotNull(blobToObject, "blobToObject"); |
55 | this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); |
56 | this.deleteMethod = CommonSwiftAsyncClient.class.getMethod("removeObject", String.class, String.class); |
57 | this.createMethod = CommonSwiftAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); |
58 | |
59 | } |
60 | |
61 | @Override |
62 | public HttpRequest signGetBlob(String container, String name) { |
63 | return cleanRequest(processor.createRequest(getMethod, container, name)); |
64 | } |
65 | |
66 | @Override |
67 | public HttpRequest signPutBlob(String container, Blob blob) { |
68 | return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); |
69 | } |
70 | |
71 | @Override |
72 | public HttpRequest signRemoveBlob(String container, String name) { |
73 | return cleanRequest(processor.createRequest(deleteMethod, container, name)); |
74 | } |
75 | |
76 | } |