Google Cloud Storage C++ Client  1.24.0
A C++ Client Library for Google Cloud Storage
policy_document.h
Go to the documentation of this file.
1 // Copyright 2019 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_POLICY_DOCUMENT_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_POLICY_DOCUMENT_H
17 
19 #include <chrono>
20 #include <map>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 namespace google {
26 namespace cloud {
27 namespace storage {
28 inline namespace STORAGE_CLIENT_NS {
33  public:
35  // NOLINTNEXTLINE(google-explicit-constructor)
36  PolicyDocumentCondition(std::vector<std::string> elements)
37  : elements_(std::move(elements)) {}
38 
39  std::vector<std::string> const& elements() const { return elements_; }
40 
42 
46  static std::vector<std::string> ExactMatch(std::string const& field,
48  std::string const& value) {
49  std::vector<std::string> result;
50  result.emplace_back("eq");
51  result.emplace_back(std::string("$") + field);
52  result.emplace_back(value);
53  return result;
54  }
55 
57  static std::vector<std::string> ExactMatchObject(std::string const& field,
58  std::string const& value) {
59  std::vector<std::string> result;
60  result.emplace_back(field);
61  result.emplace_back(value);
62  return result;
63  }
64 
65  static std::vector<std::string> StartsWith(std::string const& field,
66  std::string const& value) {
67  std::vector<std::string> result;
68  result.emplace_back("starts-with");
69  result.emplace_back(std::string("$") + field);
70  result.emplace_back(value);
71  return result;
72  }
73 
74  static std::vector<std::string> ContentLengthRange(std::int32_t min_range,
75  std::int32_t max_range) {
76  std::vector<std::string> result;
77  result.emplace_back("content-length-range");
78  result.emplace_back(std::to_string(min_range));
79  result.emplace_back(std::to_string(max_range));
80  return result;
81  }
83 
84  private:
85  std::vector<std::string> elements_;
86 };
87 
88 inline bool operator==(PolicyDocumentCondition const& lhs,
89  PolicyDocumentCondition const& rhs) {
90  return lhs.elements() == rhs.elements();
91 }
92 
93 inline bool operator<(PolicyDocumentCondition const& lhs,
94  PolicyDocumentCondition const& rhs) {
95  return lhs.elements() < rhs.elements();
96 }
97 
98 inline bool operator!=(PolicyDocumentCondition const& lhs,
99  PolicyDocumentCondition const& rhs) {
100  return std::rel_ops::operator!=(lhs, rhs);
101 }
102 
103 inline bool operator>(PolicyDocumentCondition const& lhs,
104  PolicyDocumentCondition const& rhs) {
105  return std::rel_ops::operator>(lhs, rhs);
106 }
107 
108 inline bool operator<=(PolicyDocumentCondition const& lhs,
109  PolicyDocumentCondition const& rhs) {
110  return std::rel_ops::operator<=(lhs, rhs);
111 }
112 
113 inline bool operator>=(PolicyDocumentCondition const& lhs,
114  PolicyDocumentCondition const& rhs) {
115  return std::rel_ops::operator>=(lhs, rhs);
116 }
117 
118 std::ostream& operator<<(std::ostream& os, PolicyDocumentCondition const& rhs);
119 
131  std::chrono::system_clock::time_point expiration;
132  std::vector<PolicyDocumentCondition> conditions;
133 };
134 
135 std::ostream& operator<<(std::ostream& os, PolicyDocument const& rhs);
136 
148  PolicyDocumentV4() = default;
149  PolicyDocumentV4(std::string bucket, std::string object,
150  std::chrono::seconds expiration,
151  std::chrono::system_clock::time_point timestamp =
152  std::chrono::system_clock::now(),
153  std::vector<PolicyDocumentCondition> conditions = {})
154  : bucket(std::move(bucket)),
155  object(std::move(object)),
156  expiration(std::move(expiration)),
157  timestamp(std::move(timestamp)),
158  conditions(std::move(conditions)) {}
159 
160  std::string bucket;
161  std::string object;
162  std::chrono::seconds expiration;
163  std::chrono::system_clock::time_point timestamp;
164  std::vector<PolicyDocumentCondition> conditions;
165 };
166 
167 std::ostream& operator<<(std::ostream& os, PolicyDocumentV4 const& rhs);
168 
177  std::string access_id;
178  std::chrono::system_clock::time_point expiration;
179  std::string policy;
180  std::string signature;
181 };
182 
183 std::ostream& operator<<(std::ostream& os, PolicyDocumentResult const& rhs);
184 
193  std::string url;
194  std::string access_id;
195  std::chrono::system_clock::time_point expiration;
196  std::string policy;
197  std::string signature;
198  std::string signing_algorithm;
199  std::map<std::string, std::string> required_form_fields;
200 };
201 
203 std::string FormatDateForForm(PolicyDocumentV4Result const&);
204 
205 std::ostream& operator<<(std::ostream& os, PolicyDocumentV4Result const& rhs);
206 
207 } // namespace STORAGE_CLIENT_NS
208 } // namespace storage
209 } // namespace cloud
210 } // namespace google
211 
212 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_POLICY_DOCUMENT_H
google::cloud::storage::v1::PolicyDocumentV4Result::policy
std::string policy
Definition: policy_document.h:196
google::cloud::storage::v1::PolicyDocumentCondition::StartsWith
static std::vector< std::string > StartsWith(std::string const &field, std::string const &value)
Creates an exact match condition, in the list form syntax.
Definition: policy_document.h:65
google::cloud::storage::v1::PolicyDocumentResult::signature
std::string signature
Definition: policy_document.h:180
google::cloud::storage::v1::PolicyDocumentV4Result
Define a policy document result V4.
Definition: policy_document.h:192
google::cloud::storage::v1::operator<
bool operator<(BucketBilling const &lhs, BucketBilling const &rhs)
Definition: bucket_metadata.h:57
google::cloud::storage::v1::operator<<
std::ostream & operator<<(std::ostream &os, BucketAccessControl const &rhs)
Definition: bucket_access_control.cc:27
google::cloud::storage::v1::operator!=
bool operator!=(PolicyDocumentCondition const &lhs, PolicyDocumentCondition const &rhs)
Definition: policy_document.h:98
google::cloud::storage::v1::PolicyDocumentV4
Define a policy document V4.
Definition: policy_document.h:147
google::cloud::storage::v1::PolicyDocument::conditions
std::vector< PolicyDocumentCondition > conditions
Definition: policy_document.h:132
google::cloud::storage::v1::operator>
bool operator>(PolicyDocumentCondition const &lhs, PolicyDocumentCondition const &rhs)
Definition: policy_document.h:103
google::cloud::storage::v1::PolicyDocumentV4Result::url
std::string url
Definition: policy_document.h:193
google::cloud::storage::v1::PolicyDocumentCondition::PolicyDocumentCondition
PolicyDocumentCondition()=default
google::cloud::storage::v1::PolicyDocumentV4Result::signature
std::string signature
Definition: policy_document.h:197
google::cloud::storage::v1::operator>
bool operator>(BucketBilling const &lhs, BucketBilling const &rhs)
Definition: bucket_metadata.h:65
version.h
google::cloud::storage::v1::PolicyDocumentV4Result::access_id
std::string access_id
Definition: policy_document.h:194
google::cloud::storage::v1::PolicyDocumentV4Result::expiration
std::chrono::system_clock::time_point expiration
Definition: policy_document.h:195
google::cloud::storage::v1::PolicyDocumentV4::expiration
std::chrono::seconds expiration
Definition: policy_document.h:162
google::cloud::storage::v1::operator!=
bool operator!=(BucketBilling const &lhs, BucketBilling const &rhs)
Definition: bucket_metadata.h:61
google::cloud::storage::v1::PolicyDocumentV4::PolicyDocumentV4
PolicyDocumentV4(std::string bucket, std::string object, std::chrono::seconds expiration, std::chrono::system_clock::time_point timestamp=std::chrono::system_clock::now(), std::vector< PolicyDocumentCondition > conditions={})
Definition: policy_document.h:149
google::cloud::storage::v1::PolicyDocumentV4::object
std::string object
Definition: policy_document.h:161
google::cloud::storage::v1::FormatDateForForm
std::string FormatDateForForm(PolicyDocumentV4Result const &)
Format the current date in the format expected by a POST form.
Definition: policy_document.cc:60
google::cloud::storage::v1::PolicyDocumentCondition
Define a condition for a policy document.
Definition: policy_document.h:32
google::cloud::storage::v1::PolicyDocumentV4::timestamp
std::chrono::system_clock::time_point timestamp
Definition: policy_document.h:163
google::cloud::storage::v1::PolicyDocumentCondition::ExactMatchObject
static std::vector< std::string > ExactMatchObject(std::string const &field, std::string const &value)
Creates an exact match condition, but in object form syntax.
Definition: policy_document.h:57
google::cloud::storage::v1::operator<=
bool operator<=(PolicyDocumentCondition const &lhs, PolicyDocumentCondition const &rhs)
Definition: policy_document.h:108
google::cloud::storage::v1::PolicyDocument::expiration
std::chrono::system_clock::time_point expiration
Definition: policy_document.h:131
google::cloud::storage::v1::PolicyDocumentV4::bucket
std::string bucket
Definition: policy_document.h:160
google::cloud::storage::v1::PolicyDocumentCondition::elements
std::vector< std::string > const & elements() const
Definition: policy_document.h:39
google::cloud::storage::v1::PolicyDocumentV4Result::required_form_fields
std::map< std::string, std::string > required_form_fields
Definition: policy_document.h:199
google::cloud::storage::v1::PolicyDocumentCondition::PolicyDocumentCondition
PolicyDocumentCondition(std::vector< std::string > elements)
Definition: policy_document.h:36
google::cloud::storage::v1::operator>=
bool operator>=(PolicyDocumentCondition const &lhs, PolicyDocumentCondition const &rhs)
Definition: policy_document.h:113
STORAGE_CLIENT_NS
#define STORAGE_CLIENT_NS
Definition: version.h:22
google::cloud::storage::v1::PolicyDocument
Define a policy document.
Definition: policy_document.h:130
google::cloud::storage::v1::PolicyDocumentResult::policy
std::string policy
Definition: policy_document.h:179
google::cloud::storage::v1::PolicyDocumentV4::conditions
std::vector< PolicyDocumentCondition > conditions
Definition: policy_document.h:164
google::cloud::storage::v1::PolicyDocumentCondition::ContentLengthRange
static std::vector< std::string > ContentLengthRange(std::int32_t min_range, std::int32_t max_range)
Creates an exact match condition, in the list form syntax.
Definition: policy_document.h:74
google::cloud::storage::v1::PolicyDocumentResult::access_id
std::string access_id
Definition: policy_document.h:177
google::cloud::storage::v1::operator>=
bool operator>=(BucketBilling const &lhs, BucketBilling const &rhs)
Definition: bucket_metadata.h:73
google::cloud::storage::v1::operator==
bool operator==(BucketAccessControl const &lhs, BucketAccessControl const &rhs)
Definition: bucket_access_control.cc:22
google::cloud::storage::v1::PolicyDocumentResult::expiration
std::chrono::system_clock::time_point expiration
Definition: policy_document.h:178
google
google::cloud::storage::v1::PolicyDocumentV4Result::signing_algorithm
std::string signing_algorithm
Definition: policy_document.h:198
google::cloud::storage::v1::operator<=
bool operator<=(BucketBilling const &lhs, BucketBilling const &rhs)
Definition: bucket_metadata.h:69
google::cloud::storage::v1::PolicyDocumentV4::PolicyDocumentV4
PolicyDocumentV4()=default
google::cloud::storage::v1::PolicyDocumentResult
Define a policy document result.
Definition: policy_document.h:176