Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
hmac_key_metadata.h
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
25namespace google {
26namespace cloud {
27namespace storage {
28GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
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 */
45class HmacKeyMetadata {
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
131inline 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
144inline bool operator!=(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
145 return std::rel_ops::operator!=(lhs, rhs);
146}
147
148std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
149
150GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
151} // namespace storage
152} // namespace cloud
153} // namespace google
154
155#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H
Represents the metadata for a Google Cloud Storage HmacKeyResource.
Definition: hmac_key_metadata.h:45
static std::string state_inactive()
Definition: hmac_key_metadata.h:74
std::string const & etag() const
Definition: hmac_key_metadata.h:50
HmacKeyMetadata & set_service_account_email(std::string v)
Definition: hmac_key_metadata.h:102
std::string const & state() const
Definition: hmac_key_metadata.h:63
std::string const & id() const
Definition: hmac_key_metadata.h:56
std::chrono::system_clock::time_point time_created() const
Definition: hmac_key_metadata.h:68
HmacKeyMetadata & set_access_id(std::string v)
Definition: hmac_key_metadata.h:85
std::chrono::system_clock::time_point updated() const
Definition: hmac_key_metadata.h:71
HmacKeyMetadata & set_state(std::string v)
Definition: hmac_key_metadata.h:64
std::string const & service_account_email() const
Definition: hmac_key_metadata.h:60
HmacKeyMetadata & set_project_id(std::string v)
Definition: hmac_key_metadata.h:98
HmacKeyMetadata & set_id(std::string v)
Definition: hmac_key_metadata.h:89
HmacKeyMetadata & set_etag(std::string v)
Definition: hmac_key_metadata.h:51
static std::string state_deleted()
Definition: hmac_key_metadata.h:75
std::string const & access_id() const
Definition: hmac_key_metadata.h:49
HmacKeyMetadata & set_time_created(std::chrono::system_clock::time_point v)
Definition: hmac_key_metadata.h:106
HmacKeyMetadata & set_kind(std::string v)
Definition: hmac_key_metadata.h:94
std::string const & kind() const
Definition: hmac_key_metadata.h:57
HmacKeyMetadata & set_updated(std::chrono::system_clock::time_point v)
Definition: hmac_key_metadata.h:110
static std::string state_active()
Definition: hmac_key_metadata.h:73
std::string const & project_id() const
Definition: hmac_key_metadata.h:59
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
bool operator!=(HmacKeyMetadata const &lhs, HmacKeyMetadata const &rhs)
Definition: hmac_key_metadata.h:144
bool operator==(HmacKeyMetadata const &lhs, HmacKeyMetadata const &rhs)
Definition: hmac_key_metadata.h:131