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.ec2.options; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | import static com.google.common.base.Preconditions.checkState; |
23 | |
24 | import org.jclouds.ec2.options.internal.BaseEC2RequestOptions; |
25 | import org.jclouds.rest.annotations.Identity; |
26 | |
27 | import com.google.common.collect.Multimap; |
28 | import com.google.inject.Inject; |
29 | |
30 | /** |
31 | * Contains options supported in the Form API for the RegisterImage operation. |
32 | * <h2> |
33 | * Usage</h2> The recommended way to instantiate a |
34 | * BundleInstanceS3StorageOptions object is to statically import |
35 | * BundleInstanceS3StorageOptions.Builder.* and invoke a static creation method |
36 | * followed by an instance mutator (if needed): |
37 | * <p/> |
38 | * <code> |
39 | * import static org.jclouds.ec2.options.BundleInstanceS3StorageOptions.Builder.* |
40 | * <p/> |
41 | * EC2Client connection = // get connection |
42 | * String imageId = connection.getWindowsServices().bundleInstanceInRegion(...bucketOwnedBy(anotherAccessKey)); |
43 | * <code> |
44 | * |
45 | * @author Adrian Cole |
46 | * @see <a |
47 | * href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-BundleInstance.html" |
48 | * /> |
49 | */ |
50 | public class BundleInstanceS3StorageOptions extends BaseEC2RequestOptions { |
51 | |
52 | @Inject(optional = true) |
53 | @Identity |
54 | String currentAwsAccessKeyId; |
55 | |
56 | @Override |
57 | public Multimap<String, String> buildFormParameters() { |
58 | if (getAwsAccessKeyId() == null) { |
59 | checkState(currentAwsAccessKeyId != null, "currentAwsAccessKeyId should have been injected"); |
60 | bucketOwnedBy(currentAwsAccessKeyId); |
61 | } |
62 | return super.buildFormParameters(); |
63 | } |
64 | |
65 | /** |
66 | * |
67 | * @param ccessKeyId |
68 | * The Access Key ID of the owner of the Amazon S3 bucket. |
69 | */ |
70 | public BundleInstanceS3StorageOptions bucketOwnedBy(String ccessKeyId) { |
71 | formParameters.put("Storage.S3.AWSAccessKeyId", checkNotNull(ccessKeyId, "ccessKeyId")); |
72 | return this; |
73 | } |
74 | |
75 | /** |
76 | * |
77 | * @return The Access Key ID of the owner of the Amazon S3 bucket. |
78 | */ |
79 | public String getAwsAccessKeyId() { |
80 | return getFirstFormOrNull("Storage.S3.AWSAccessKeyId"); |
81 | } |
82 | |
83 | public static class Builder { |
84 | /** |
85 | * @see BundleInstanceS3StorageOptions#bucketOwnedBy(ccessKeyId) |
86 | */ |
87 | public static BundleInstanceS3StorageOptions bucketOwnedBy(String ccessKeyId) { |
88 | BundleInstanceS3StorageOptions options = new BundleInstanceS3StorageOptions(); |
89 | return options.bucketOwnedBy(ccessKeyId); |
90 | } |
91 | |
92 | } |
93 | } |