Google Cloud Storage C++ Client  1.32.1
A C++ Client Library for Google Cloud Storage
signed_url_options.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_SIGNED_URL_OPTIONS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_SIGNED_URL_OPTIONS_H
17 
18 #include "google/cloud/storage/internal/complex_option.h"
19 #include "google/cloud/storage/version.h"
20 #include <chrono>
21 #include <string>
22 #include <vector>
23 
24 namespace google {
25 namespace cloud {
26 namespace storage {
27 inline namespace STORAGE_CLIENT_NS {
28 /**
29  * Define the expiration time for a signed URL.
30  */
32  : public internal::ComplexOption<ExpirationTime,
33  std::chrono::system_clock::time_point> {
34  using ComplexOption<ExpirationTime,
35  std::chrono::system_clock::time_point>::ComplexOption;
36  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
37  // explicitly
38  ExpirationTime() = default;
39  static char const* name() { return "expiration_time"; }
40 };
41 
42 /**
43  * Add a extension header to a signed URL.
44  */
46  : public internal::ComplexOption<AddExtensionHeaderOption,
47  std::pair<std::string, std::string>> {
48  using ComplexOption<AddExtensionHeaderOption,
49  std::pair<std::string, std::string>>::ComplexOption;
50  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
51  // explicitly
53  AddExtensionHeaderOption(std::string header, std::string value)
54  : ComplexOption(std::make_pair(std::move(header), std::move(value))) {}
55  static char const* name() { return "expiration_time"; }
56 };
57 
58 inline AddExtensionHeaderOption AddExtensionHeader(std::string header,
59  std::string value) {
60  return AddExtensionHeaderOption(std::move(header), std::move(value));
61 }
62 
63 /**
64  * Add a extension header to a signed URL.
65  */
67  : public internal::ComplexOption<AddQueryParameterOption,
68  std::pair<std::string, std::string>> {
69  using ComplexOption<AddQueryParameterOption,
70  std::pair<std::string, std::string>>::ComplexOption;
71  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
72  // explicitly
74  AddQueryParameterOption(std::string key, std::string value)
75  : ComplexOption(std::make_pair(std::move(key), std::move(value))) {}
76  AddQueryParameterOption(char const* key, std::string value)
77  : ComplexOption(std::make_pair(std::string(key), std::move(value))) {}
78  static char const* name() { return "query-parameter"; }
79 };
80 
81 inline AddQueryParameterOption WithGeneration(std::uint64_t generation) {
82  return AddQueryParameterOption("generation", std::to_string(generation));
83 }
84 
85 inline AddQueryParameterOption WithGenerationMarker(std::uint64_t generation) {
86  return AddQueryParameterOption("generation-marker",
87  std::to_string(generation));
88 }
89 
90 inline AddQueryParameterOption WithUserProject(std::string user_project) {
91  return AddQueryParameterOption("userProject", std::move(user_project));
92 }
93 
94 inline AddQueryParameterOption WithMarker(std::string marker) {
95  return AddQueryParameterOption("marker", std::move(marker));
96 }
97 
99  std::string disposition) {
100  return AddQueryParameterOption("response-content-disposition",
101  std::move(disposition));
102 }
103 
105  std::string const& type) {
106  return AddQueryParameterOption("response-content-type", type);
107 }
108 
109 /**
110  * Specify a sub-resource in a signed URL.
111  */
113  : public internal::ComplexOption<SubResourceOption, std::string> {
114  using ComplexOption<SubResourceOption, std::string>::ComplexOption;
115  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
116  // explicitly
117  SubResourceOption() = default;
118  static char const* name() { return "query-parameter"; }
119 };
120 
121 inline SubResourceOption WithAcl() { return SubResourceOption("acl"); }
122 
123 inline SubResourceOption WithBilling() { return SubResourceOption("billing"); }
124 
125 inline SubResourceOption WithCompose() { return SubResourceOption("compose"); }
126 
127 inline SubResourceOption WithCors() { return SubResourceOption("cors"); }
128 
130  return SubResourceOption("encryption");
131 }
132 
134  return SubResourceOption("encryptionConfig");
135 }
136 
138  return SubResourceOption("lifecycle");
139 }
140 
142  return SubResourceOption("location");
143 }
144 
145 inline SubResourceOption WithLogging() { return SubResourceOption("logging"); }
146 
148  return SubResourceOption("storageClass");
149 }
150 
151 inline SubResourceOption WithTagging() { return SubResourceOption("tagging"); }
152 
153 /**
154  * Define the timestamp duration for a V4 signed URL.
155  */
157  : public internal::ComplexOption<SignedUrlTimestamp,
158  std::chrono::system_clock::time_point> {
159  using ComplexOption<SignedUrlTimestamp,
160  std::chrono::system_clock::time_point>::ComplexOption;
161  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
162  // explicitly
163  SignedUrlTimestamp() = default;
164  static char const* name() { return "x-goog-date"; }
165 };
166 
167 /**
168  * Define the duration for a V4 signed URL.
169  */
171  : public internal::ComplexOption<SignedUrlDuration, std::chrono::seconds> {
172  using ComplexOption<SignedUrlDuration, std::chrono::seconds>::ComplexOption;
173  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
174  // explicitly
175  SignedUrlDuration() = default;
176  static char const* name() { return "x-goog-expires"; }
177 };
178 
179 /**
180  * Specify the service account used to sign a blob.
181  *
182  * With this option the application can sign a URL or policy document using a
183  * different account than the account associated with the current credentials.
184  */
186  : public internal::ComplexOption<SigningAccount, std::string> {
187  using ComplexOption<SigningAccount, std::string>::ComplexOption;
188  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
189  // explicitly
190  SigningAccount() = default;
191  static char const* name() { return "signing-account"; }
192 };
193 
194 /**
195  * Specify the sequence of delegates used to sign a blob.
196  *
197  * With this option the application can sign a URL even if the account
198  * associated with the current credentials does not have direct
199  * `roles/iam.serviceAccountTokenCreator` on the target service account.
200  */
202  : public internal::ComplexOption<SigningAccountDelegates,
203  std::vector<std::string>> {
204  using ComplexOption<SigningAccountDelegates,
205  std::vector<std::string>>::ComplexOption;
206  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
207  // explicitly
209  static char const* name() { return "signing-account-delegates"; }
210 };
211 
212 /**
213  * Indicate that the bucket should be a part of hostname in the URL.
214  *
215  * If this option is set, the resulting URL is in the format:
216  * 'https://mybucket.storage.googleapis.com'. Otherwise, it is in the format:
217  * 'https://storage.googleapis.com/mybucket'
218  */
219 struct VirtualHostname : public internal::ComplexOption<VirtualHostname, bool> {
220  using ComplexOption<VirtualHostname, bool>::ComplexOption;
221  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
222  // explicitly
223  VirtualHostname() = default;
224  static char const* option_name() { return "virtual-hostname"; }
225 };
226 
227 /**
228  * Use domain-named bucket in a V4 signed URL.
229  *
230  * The resulting URL will use the provided domain to address objects like this:
231  * 'https://mydomain.tld/my-object'
232  */
234  : public internal::ComplexOption<BucketBoundHostname, std::string> {
235  using ComplexOption<BucketBoundHostname, std::string>::ComplexOption;
236  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
237  // explicitly
238  BucketBoundHostname() = default;
239  static char const* option_name() { return "domain-named-bucket"; }
240 };
241 
242 /// Use the specified scheme (e.g. "http") in a V4 signed URL.
243 struct Scheme : public internal::ComplexOption<Scheme, std::string> {
244  using ComplexOption<Scheme, std::string>::ComplexOption;
245  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
246  // explicitly
247  Scheme() = default;
248  static char const* option_name() { return "scheme"; }
249 };
250 
251 /**
252  * Add a extension header to a POST policy.
253  */
255  : public internal::ComplexOption<AddExtensionFieldOption,
256  std::pair<std::string, std::string>> {
257  using ComplexOption<AddExtensionFieldOption,
258  std::pair<std::string, std::string>>::ComplexOption;
259  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
260  // explicitly
262  AddExtensionFieldOption(std::string field, std::string value)
263  : ComplexOption(std::make_pair(std::move(field), std::move(value))) {}
264  static char const* name() { return "extension_field"; }
265 };
266 
268  std::string value) {
269  return AddExtensionFieldOption(std::move(field), std::move(value));
270 }
271 
272 } // namespace STORAGE_CLIENT_NS
273 } // namespace storage
274 } // namespace cloud
275 } // namespace google
276 
277 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_SIGNED_URL_OPTIONS_H