Google Cloud Storage C++ Client  2.4.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 
30 /**
31  * Represents the metadata for a Google Cloud Storage HmacKeyResource.
32  *
33  * HMAC keys allow applications to authenticate with Google Cloud Storage using
34  * HMAC authentication. Applications can create a limited number of HMAC keys
35  * associated with a service account. The application can use the HMAC keys to
36  * authenticate with GCS. GCS will use the service account permissions to
37  * determine if the request is authorized.
38  *
39  * @see https://cloud.google.com/storage/docs/authentication/hmackeys for
40  * general information on HMAC keys.
41  *
42  * @see https://cloud.google.com/storage/ for general information on Google
43  * Cloud Storage.
44  */
46  public:
47  HmacKeyMetadata() = default;
48 
49  std::string const& access_id() const { return access_id_; }
50  std::string const& etag() const { return etag_; }
51  HmacKeyMetadata& set_etag(std::string v) {
52  etag_ = std::move(v);
53  return *this;
54  }
55 
56  std::string const& id() const { return id_; }
57  std::string const& kind() const { return kind_; }
58 
59  std::string const& project_id() const { return project_id_; }
60  std::string const& service_account_email() const {
61  return service_account_email_;
62  }
63  std::string const& state() const { return state_; }
64  HmacKeyMetadata& set_state(std::string v) {
65  state_ = std::move(v);
66  return *this;
67  }
68  std::chrono::system_clock::time_point time_created() const {
69  return time_created_;
70  }
71  std::chrono::system_clock::time_point updated() const { return updated_; }
72 
73  static std::string state_active() { return "ACTIVE"; }
74  static std::string state_inactive() { return "INACTIVE"; }
75  static std::string state_deleted() { return "DELETED"; }
76 
77  ///@{
78  /**
79  * @name Testing modifiers.
80  *
81  * The following attributes cannot be changed when updating, creating, or
82  * patching an HmacKeyMetadata resource. However, it is useful to change
83  * them in tests, e.g., when mocking the results from the C++ client library.
84  */
85  HmacKeyMetadata& set_access_id(std::string v) {
86  access_id_ = std::move(v);
87  return *this;
88  }
89  HmacKeyMetadata& set_id(std::string v) {
90  id_ = std::move(v);
91  return *this;
92  }
93 
94  HmacKeyMetadata& set_kind(std::string v) {
95  kind_ = std::move(v);
96  return *this;
97  }
98  HmacKeyMetadata& set_project_id(std::string v) {
99  project_id_ = std::move(v);
100  return *this;
101  }
103  service_account_email_ = std::move(v);
104  return *this;
105  }
106  HmacKeyMetadata& set_time_created(std::chrono::system_clock::time_point v) {
107  time_created_ = v;
108  return *this;
109  }
110  HmacKeyMetadata& set_updated(std::chrono::system_clock::time_point v) {
111  updated_ = v;
112  return *this;
113  }
114  ///@}
115 
116  private:
117  friend std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
118 
119  // Keep the fields in alphabetical order.
120  std::string access_id_;
121  std::string etag_;
122  std::string id_;
123  std::string kind_;
124  std::string project_id_;
125  std::string service_account_email_;
126  std::string state_;
127  std::chrono::system_clock::time_point time_created_;
128  std::chrono::system_clock::time_point updated_;
129 };
130 
131 inline bool operator==(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
132  auto lhs_time_created = lhs.time_created();
133  auto rhs_time_created = rhs.time_created();
134  auto lhs_updated = lhs.updated();
135  auto rhs_updated = rhs.updated();
136  return std::tie(lhs.id(), lhs.access_id(), lhs.etag(), lhs.kind(),
138  lhs_time_created, lhs_updated) ==
139  std::tie(rhs.id(), rhs.access_id(), rhs.etag(), rhs.kind(),
141  rhs_time_created, rhs_updated);
142 }
143 
144 inline bool operator!=(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
145  return std::rel_ops::operator!=(lhs, rhs);
146 }
147 
148 std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
149 
151 } // namespace storage
152 } // namespace cloud
153 } // namespace google
154 
155 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H