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