Google Cloud Storage C++ Client  1.42.0
A C++ Client Library for Google Cloud Storage
hmac_key_metadata.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 // 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_HMAC_KEY_METADATA_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H
17 
18 #include "google/cloud/storage/version.h"
19 #include "google/cloud/status_or.h"
20 #include <chrono>
21 #include <iosfwd>
22 #include <string>
23 #include <tuple>
24 
25 namespace google {
26 namespace cloud {
27 namespace storage {
29 namespace internal {
30 struct HmacKeyMetadataParser;
31 struct GrpcHmacKeyMetadataParser;
32 } // namespace internal
33 
34 /**
35  * Represents the metadata for a Google Cloud Storage HmacKeyResource.
36  *
37  * HMAC keys allow applications to authenticate with Google Cloud Storage using
38  * HMAC authentication. Applications can create a limited number of HMAC keys
39  * associated with a service account. The application can use the HMAC keys to
40  * authenticate with GCS. GCS will use the service account permissions to
41  * determine if the request is authorized.
42  *
43  * @see https://cloud.google.com/storage/docs/authentication/hmackeys for
44  * general information on HMAC keys.
45  *
46  * @see https://cloud.google.com/storage/ for general information on Google
47  * Cloud Storage.
48  */
50  public:
51  HmacKeyMetadata() = default;
52 
53  std::string const& access_id() const { return access_id_; }
54  std::string const& etag() const { return etag_; }
55  HmacKeyMetadata& set_etag(std::string v) {
56  etag_ = std::move(v);
57  return *this;
58  }
59 
60  std::string const& id() const { return id_; }
61  std::string const& kind() const { return kind_; }
62 
63  std::string const& project_id() const { return project_id_; }
64  std::string const& service_account_email() const {
65  return service_account_email_;
66  }
67  std::string const& state() const { return state_; }
68  HmacKeyMetadata& set_state(std::string v) {
69  state_ = std::move(v);
70  return *this;
71  }
72  std::chrono::system_clock::time_point time_created() const {
73  return time_created_;
74  }
75  std::chrono::system_clock::time_point updated() const { return updated_; }
76 
77  static std::string state_active() { return "ACTIVE"; }
78  static std::string state_inactive() { return "INACTIVE"; }
79  static std::string state_deleted() { return "DELETED"; }
80 
81  private:
82  friend struct internal::HmacKeyMetadataParser;
83  friend struct internal::GrpcHmacKeyMetadataParser;
84  friend std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
85 
86  // Keep the fields in alphabetical order.
87  std::string access_id_;
88  std::string etag_;
89  std::string id_;
90  std::string kind_;
91  std::string project_id_;
92  std::string service_account_email_;
93  std::string state_;
94  std::chrono::system_clock::time_point time_created_;
95  std::chrono::system_clock::time_point updated_;
96 };
97 
98 inline bool operator==(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
99  auto lhs_time_created = lhs.time_created();
100  auto rhs_time_created = rhs.time_created();
101  auto lhs_updated = lhs.updated();
102  auto rhs_updated = rhs.updated();
103  return std::tie(lhs.id(), lhs.access_id(), lhs.etag(), lhs.kind(),
105  lhs_time_created, lhs_updated) ==
106  std::tie(rhs.id(), rhs.access_id(), rhs.etag(), rhs.kind(),
108  rhs_time_created, rhs_updated);
109 }
110 
111 inline bool operator!=(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
112  return std::rel_ops::operator!=(lhs, rhs);
113 }
114 
115 std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
116 
118 } // namespace storage
119 } // namespace cloud
120 } // namespace google
121 
122 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H