Google Cloud Storage C++ Client  1.32.1
A C++ Client Library for Google Cloud Storage
policy_document.cc
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 #include "google/cloud/storage/policy_document.h"
16 #include "google/cloud/internal/absl_str_join_quiet.h"
17 #include "google/cloud/internal/format_time_point.h"
18 #include <algorithm>
19 #include <iostream>
20 #include <numeric>
21 
22 namespace google {
23 namespace cloud {
24 namespace storage {
25 inline namespace STORAGE_CLIENT_NS {
26 std::ostream& operator<<(std::ostream& os, PolicyDocumentCondition const& rhs) {
27  return os << "PolicyDocumentCondition=["
28  << absl::StrJoin(rhs.elements(), ", ") << "]";
29 }
30 
31 std::ostream& operator<<(std::ostream& os, PolicyDocument const& rhs) {
32  os << "PolicyDocument={";
33  os << "expiration=" << google::cloud::internal::FormatRfc3339(rhs.expiration)
34  << ", ";
35  os << "conditions=[";
36  os << absl::StrJoin(rhs.conditions, ", ", absl::StreamFormatter());
37  return os << "]}";
38 }
39 
40 std::ostream& operator<<(std::ostream& os, PolicyDocumentV4 const& rhs) {
41  os << "PolicyDocumentV4={";
42 
43  os << "bucket=" << rhs.bucket << ", object=" << rhs.object
44  << ", expiration=" << rhs.expiration.count()
45  << ", timestamp=" << google::cloud::internal::FormatRfc3339(rhs.timestamp)
46  << ", ";
47  os << "conditions=[";
48  os << absl::StrJoin(rhs.conditions, ", ", absl::StreamFormatter());
49  return os << "]}";
50 }
51 
52 std::ostream& operator<<(std::ostream& os, PolicyDocumentResult const& rhs) {
53  return os << "PolicyDocumentResult={"
54  << "access_id=" << rhs.access_id << ", expiration="
55  << google::cloud::internal::FormatRfc3339(rhs.expiration)
56  << ", policy=" << rhs.policy << ", signature=" << rhs.signature
57  << "}";
58 }
59 
61  // The V4 signed URL format for timestamps and the format for dates in the V4
62  // policy docs are fortunately the same, so we can just call the existing
63  // function and truncate the sub-day parts.
64  auto constexpr kDateLength = sizeof("YYYYMMDD");
65  return google::cloud::internal::FormatV4SignedUrlTimestamp(
66  std::chrono::system_clock::now())
67  .substr(0, kDateLength);
68 }
69 
70 std::ostream& operator<<(std::ostream& os, PolicyDocumentV4Result const& rhs) {
71  return os << "PolicyDocumentV4Result={"
72  << "url=" << rhs.url << ", access_id=" << rhs.access_id
73  << ", expiration="
74  << google::cloud::internal::FormatRfc3339(rhs.expiration)
75  << ", policy=" << rhs.policy << ", signature=" << rhs.signature
76  << ", signing_algorithm=" << rhs.signing_algorithm << "}";
77 }
78 } // namespace STORAGE_CLIENT_NS
79 } // namespace storage
80 } // namespace cloud
81 } // namespace google