Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
signed_url_options.h
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// https://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
24namespace google {
25namespace cloud {
26namespace storage {
27GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
28/**
29 * Define the expiration time for a signed URL.
30 */
31struct ExpirationTime
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
52 AddExtensionHeaderOption() = default;
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
58inline 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
73 AddQueryParameterOption() = default;
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
81inline AddQueryParameterOption WithGeneration(std::uint64_t generation) {
82 return AddQueryParameterOption("generation", std::to_string(generation));
83}
84
85inline AddQueryParameterOption WithGenerationMarker(std::uint64_t generation) {
86 return AddQueryParameterOption("generation-marker",
87 std::to_string(generation));
88}
89
90inline AddQueryParameterOption WithUserProject(std::string user_project) {
91 return AddQueryParameterOption("userProject", std::move(user_project));
92}
93
94inline 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
121inline SubResourceOption WithAcl() { return SubResourceOption("acl"); }
122
123inline SubResourceOption WithBilling() { return SubResourceOption("billing"); }
124
125inline SubResourceOption WithCompose() { return SubResourceOption("compose"); }
126
127inline 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
145inline SubResourceOption WithLogging() { return SubResourceOption("logging"); }
146
148 return SubResourceOption("storageClass");
149}
150
151inline 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 */
185struct SigningAccount
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
208 SigningAccountDelegates() = default;
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 */
219struct 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.
243struct 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
261 AddExtensionFieldOption() = default;
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
267inline AddExtensionFieldOption AddExtensionField(std::string field,
268 std::string value) {
269 return AddExtensionFieldOption(std::move(field), std::move(value));
270}
271
272GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
273} // namespace storage
274} // namespace cloud
275} // namespace google
276
277#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_SIGNED_URL_OPTIONS_H
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
AddQueryParameterOption WithGenerationMarker(std::uint64_t generation)
Definition: signed_url_options.h:85
SubResourceOption WithLocation()
Definition: signed_url_options.h:141
AddExtensionHeaderOption AddExtensionHeader(std::string header, std::string value)
Definition: signed_url_options.h:58
AddQueryParameterOption WithResponseContentDisposition(std::string disposition)
Definition: signed_url_options.h:98
SubResourceOption WithTagging()
Definition: signed_url_options.h:151
AddQueryParameterOption WithMarker(std::string marker)
Definition: signed_url_options.h:94
SubResourceOption WithLogging()
Definition: signed_url_options.h:145
SubResourceOption WithLifecycle()
Definition: signed_url_options.h:137
AddQueryParameterOption WithResponseContentType(std::string const &type)
Definition: signed_url_options.h:104
SubResourceOption WithAcl()
Definition: signed_url_options.h:121
AddQueryParameterOption WithGeneration(std::uint64_t generation)
Definition: signed_url_options.h:81
AddExtensionFieldOption AddExtensionField(std::string field, std::string value)
Definition: signed_url_options.h:267
SubResourceOption WithEncryptionConfig()
Definition: signed_url_options.h:133
SubResourceOption WithStorageClass()
Definition: signed_url_options.h:147
SubResourceOption WithEncryption()
Definition: signed_url_options.h:129
AddQueryParameterOption WithUserProject(std::string user_project)
Definition: signed_url_options.h:90
SubResourceOption WithCors()
Definition: signed_url_options.h:127
SubResourceOption WithCompose()
Definition: signed_url_options.h:125
SubResourceOption WithBilling()
Definition: signed_url_options.h:123
Add a extension header to a POST policy.
Definition: signed_url_options.h:256
AddExtensionFieldOption(std::string field, std::string value)
Definition: signed_url_options.h:262
static char const * name()
Definition: signed_url_options.h:264
Add a extension header to a signed URL.
Definition: signed_url_options.h:47
AddExtensionHeaderOption(std::string header, std::string value)
Definition: signed_url_options.h:53
static char const * name()
Definition: signed_url_options.h:55
Add a extension header to a signed URL.
Definition: signed_url_options.h:68
AddQueryParameterOption(char const *key, std::string value)
Definition: signed_url_options.h:76
AddQueryParameterOption(std::string key, std::string value)
Definition: signed_url_options.h:74
static char const * name()
Definition: signed_url_options.h:78
Use domain-named bucket in a V4 signed URL.
Definition: signed_url_options.h:234
static char const * option_name()
Definition: signed_url_options.h:239
Define the expiration time for a signed URL.
Definition: signed_url_options.h:33
static char const * name()
Definition: signed_url_options.h:39
Use the specified scheme (e.g. "http") in a V4 signed URL.
Definition: signed_url_options.h:243
static char const * option_name()
Definition: signed_url_options.h:248
Define the duration for a V4 signed URL.
Definition: signed_url_options.h:171
static char const * name()
Definition: signed_url_options.h:176
Define the timestamp duration for a V4 signed URL.
Definition: signed_url_options.h:158
static char const * name()
Definition: signed_url_options.h:164
Specify the sequence of delegates used to sign a blob.
Definition: signed_url_options.h:203
static char const * name()
Definition: signed_url_options.h:209
Specify the service account used to sign a blob.
Definition: signed_url_options.h:186
static char const * name()
Definition: signed_url_options.h:191
Specify a sub-resource in a signed URL.
Definition: signed_url_options.h:113
static char const * name()
Definition: signed_url_options.h:118
Indicate that the bucket should be a part of hostname in the URL.
Definition: signed_url_options.h:219
static char const * option_name()
Definition: signed_url_options.h:224