-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathhmac_key_metadata.h
More file actions
155 lines (138 loc) · 5.03 KB
/
hmac_key_metadata.h
File metadata and controls
155 lines (138 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H
#include "google/cloud/storage/version.h"
#include "google/cloud/status_or.h"
#include <chrono>
#include <iosfwd>
#include <string>
#include <tuple>
namespace google {
namespace cloud {
namespace storage {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/**
* Represents the metadata for a Google Cloud Storage HmacKeyResource.
*
* HMAC keys allow applications to authenticate with Google Cloud Storage using
* HMAC authentication. Applications can create a limited number of HMAC keys
* associated with a service account. The application can use the HMAC keys to
* authenticate with GCS. GCS will use the service account permissions to
* determine if the request is authorized.
*
* @see https://cloud.google.com/storage/docs/authentication/hmackeys for
* general information on HMAC keys.
*
* @see https://cloud.google.com/storage/ for general information on Google
* Cloud Storage.
*/
class HmacKeyMetadata {
public:
HmacKeyMetadata() = default;
std::string const& access_id() const { return access_id_; }
std::string const& etag() const { return etag_; }
HmacKeyMetadata& set_etag(std::string v) {
etag_ = std::move(v);
return *this;
}
std::string const& id() const { return id_; }
std::string const& kind() const { return kind_; }
std::string const& project_id() const { return project_id_; }
std::string const& service_account_email() const {
return service_account_email_;
}
std::string const& state() const { return state_; }
HmacKeyMetadata& set_state(std::string v) {
state_ = std::move(v);
return *this;
}
std::chrono::system_clock::time_point time_created() const {
return time_created_;
}
std::chrono::system_clock::time_point updated() const { return updated_; }
static std::string state_active() { return "ACTIVE"; }
static std::string state_inactive() { return "INACTIVE"; }
static std::string state_deleted() { return "DELETED"; }
///@{
/**
* @name Testing modifiers.
*
* The following attributes cannot be changed when updating, creating, or
* patching an HmacKeyMetadata resource. However, it is useful to change
* them in tests, e.g., when mocking the results from the C++ client library.
*/
HmacKeyMetadata& set_access_id(std::string v) {
access_id_ = std::move(v);
return *this;
}
HmacKeyMetadata& set_id(std::string v) {
id_ = std::move(v);
return *this;
}
HmacKeyMetadata& set_kind(std::string v) {
kind_ = std::move(v);
return *this;
}
HmacKeyMetadata& set_project_id(std::string v) {
project_id_ = std::move(v);
return *this;
}
HmacKeyMetadata& set_service_account_email(std::string v) {
service_account_email_ = std::move(v);
return *this;
}
HmacKeyMetadata& set_time_created(std::chrono::system_clock::time_point v) {
time_created_ = v;
return *this;
}
HmacKeyMetadata& set_updated(std::chrono::system_clock::time_point v) {
updated_ = v;
return *this;
}
///@}
private:
friend std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
// Keep the fields in alphabetical order.
std::string access_id_;
std::string etag_;
std::string id_;
std::string kind_;
std::string project_id_;
std::string service_account_email_;
std::string state_;
std::chrono::system_clock::time_point time_created_;
std::chrono::system_clock::time_point updated_;
};
inline bool operator==(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
auto lhs_time_created = lhs.time_created();
auto rhs_time_created = rhs.time_created();
auto lhs_updated = lhs.updated();
auto rhs_updated = rhs.updated();
return std::tie(lhs.id(), lhs.access_id(), lhs.etag(), lhs.kind(),
lhs.project_id(), lhs.service_account_email(), lhs.state(),
lhs_time_created, lhs_updated) ==
std::tie(rhs.id(), rhs.access_id(), rhs.etag(), rhs.kind(),
rhs.project_id(), rhs.service_account_email(), rhs.state(),
rhs_time_created, rhs_updated);
}
inline bool operator!=(HmacKeyMetadata const& lhs, HmacKeyMetadata const& rhs) {
return std::rel_ops::operator!=(lhs, rhs);
}
std::ostream& operator<<(std::ostream& os, HmacKeyMetadata const& rhs);
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace storage
} // namespace cloud
} // namespace google
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_HMAC_KEY_METADATA_H