Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
object_access_control.h
1// Copyright 2018 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_OBJECT_ACCESS_CONTROL_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OBJECT_ACCESS_CONTROL_H
17
18#include "google/cloud/storage/internal/patch_builder.h"
19#include "google/cloud/storage/project_team.h"
20#include "google/cloud/storage/version.h"
21#include "google/cloud/status_or.h"
22#include <string>
23
24namespace google {
25namespace cloud {
26namespace storage {
27GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
28
29/**
30 * Wraps the objectAccessControl resource in Google Cloud Storage.
31 *
32 * objectAccessControl describes the access to a bucket for a single entity,
33 * where the entity might be a user, group, or other role.
34 *
35 * @see
36 * https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls for
37 * an authoritative source of field definitions.
38 */
40 public:
41 ObjectAccessControl() = default;
42
43 ///@{
44 /**
45 * @name Well-known values for the role() field..
46 *
47 * The following functions are handy to avoid common typos in the role names.
48 * We use functions instead of enums because enums are not backwards
49 * compatible and are brittle to changes in the server-side.
50 */
51 static std::string ROLE_OWNER() { return "OWNER"; }
52 static std::string ROLE_READER() { return "READER"; }
53 ///@}
54
55 ///@{
56 /**
57 * @name Well-known values for the project_team().team field..
58 *
59 * The following functions are handy to avoid common typos in the team names.
60 * We use functions instead of enums because enums are not backwards
61 * compatible and are brittle to changes in the server-side.
62 */
63 static std::string TEAM_EDITORS() { return storage::TEAM_EDITORS(); }
64 static std::string TEAM_OWNERS() { return storage::TEAM_OWNERS(); }
65 static std::string TEAM_VIEWERS() { return storage::TEAM_VIEWERS(); }
66 ///@}
67
68 ///@{
69 /**
70 * @name Accessors.
71 */
72 std::string const& bucket() const { return bucket_; }
73 std::string const& object() const { return object_; }
74 std::int64_t generation() const { return generation_; }
75 std::string const& domain() const { return domain_; }
76 std::string const& email() const { return email_; }
77 std::string const& entity() const { return entity_; }
78 std::string const& entity_id() const { return entity_id_; }
79 std::string const& etag() const { return etag_; }
80 std::string const& id() const { return id_; }
81 std::string const& kind() const { return kind_; }
82 bool has_project_team() const { return project_team_.has_value(); }
83 ProjectTeam const& project_team() const { return *project_team_; }
84 absl::optional<ProjectTeam> const& project_team_as_optional() const {
85 return project_team_;
86 }
87 std::string const& role() const { return role_; }
88 std::string const& self_link() const { return self_link_; }
89 ///@}
90
91 ///@{
92 /**
93 * @name Modifiers for mutable attributes.
94 *
95 * The follow attributes can be changed in update and patch operations.
96 */
97 ObjectAccessControl& set_entity(std::string v) {
98 entity_ = std::move(v);
99 return *this;
100 }
101 ObjectAccessControl& set_role(std::string v) {
102 role_ = std::move(v);
103 return *this;
104 }
105 ///@}
106
107 ///@{
108 /**
109 * @name Testing modifiers.
110 *
111 * The following attributes cannot be changed when updating, creating, or
112 * patching an ObjectAccessControl resource. However, it is useful to change
113 * them in tests, e.g., when mocking the results from the C++ client library.
114 */
115 ObjectAccessControl& set_bucket(std::string v) {
116 bucket_ = std::move(v);
117 return *this;
118 }
119 ObjectAccessControl& set_object(std::string v) {
120 object_ = std::move(v);
121 return *this;
122 }
123 ObjectAccessControl& set_generation(std::int64_t v) {
124 generation_ = v;
125 return *this;
126 }
127 ObjectAccessControl& set_domain(std::string v) {
128 domain_ = std::move(v);
129 return *this;
130 }
131 ObjectAccessControl& set_email(std::string v) {
132 email_ = std::move(v);
133 return *this;
134 }
135 ObjectAccessControl& set_entity_id(std::string v) {
136 entity_id_ = std::move(v);
137 return *this;
138 }
139 ObjectAccessControl& set_etag(std::string v) {
140 etag_ = std::move(v);
141 return *this;
142 }
143 ObjectAccessControl& set_id(std::string v) {
144 id_ = std::move(v);
145 return *this;
146 }
147 ObjectAccessControl& set_kind(std::string v) {
148 kind_ = std::move(v);
149 return *this;
150 }
152 project_team_ = std::move(v);
153 return *this;
154 }
155 ObjectAccessControl& set_self_link(std::string v) {
156 self_link_ = std::move(v);
157 return *this;
158 }
159 ///@}
160
161 friend bool operator==(ObjectAccessControl const& lhs,
162 ObjectAccessControl const& rhs);
163 friend bool operator!=(ObjectAccessControl const& lhs,
164 ObjectAccessControl const& rhs) {
165 return !(lhs == rhs);
166 }
167
168 private:
169 std::string bucket_;
170 std::string object_;
171 std::int64_t generation_ = 0;
172 std::string domain_;
173 std::string email_;
174 std::string entity_;
175 std::string entity_id_;
176 std::string etag_;
177 std::string id_;
178 std::string kind_;
179 absl::optional<ProjectTeam> project_team_;
180 std::string role_;
181 std::string self_link_;
182};
183
184std::ostream& operator<<(std::ostream& os, ObjectAccessControl const& rhs);
185
186/**
187 * Prepares a patch for an ObjectAccessControl resource.
188 *
189 * The ObjectAccessControl resource only has two modifiable fields: entity
190 * and role. This class allows application developers to setup a PATCH message,
191 * note that some of the possible PATCH messages may result in errors from the
192 * server, for example: while it is possible to express "change the value of the
193 * entity field" with a PATCH request, the server rejects such changes.
194 *
195 * @see
196 * https://cloud.google.com/storage/docs/json_api/v1/how-tos/performance#patch
197 * for general information on PATCH requests for the Google Cloud Storage
198 * JSON API.
199 */
201 public:
203
204 std::string BuildPatch() const { return impl_.ToString(); }
205
206 ObjectAccessControlPatchBuilder& set_entity(std::string const& v) {
207 impl_.SetStringField("entity", v);
208 return *this;
209 }
210
212 impl_.RemoveField("entity");
213 return *this;
214 }
215
216 ObjectAccessControlPatchBuilder& set_role(std::string const& v) {
217 impl_.SetStringField("role", v);
218 return *this;
219 }
220
222 impl_.RemoveField("role");
223 return *this;
224 }
225
226 private:
227 friend struct internal::PatchBuilderDetails;
228 internal::PatchBuilder impl_;
229};
230
231GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
232} // namespace storage
233} // namespace cloud
234} // namespace google
235
236#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OBJECT_ACCESS_CONTROL_H
Prepares a patch for an ObjectAccessControl resource.
Definition: object_access_control.h:200
ObjectAccessControlPatchBuilder & delete_entity()
Definition: object_access_control.h:211
ObjectAccessControlPatchBuilder & delete_role()
Definition: object_access_control.h:221
std::string BuildPatch() const
Definition: object_access_control.h:204
ObjectAccessControlPatchBuilder & set_entity(std::string const &v)
Definition: object_access_control.h:206
ObjectAccessControlPatchBuilder & set_role(std::string const &v)
Definition: object_access_control.h:216
Wraps the objectAccessControl resource in Google Cloud Storage.
Definition: object_access_control.h:39
ObjectAccessControl & set_object(std::string v)
Definition: object_access_control.h:119
std::string const & domain() const
Definition: object_access_control.h:75
std::string const & entity_id() const
Definition: object_access_control.h:78
static std::string TEAM_OWNERS()
Definition: object_access_control.h:64
std::int64_t generation() const
Definition: object_access_control.h:74
std::string const & entity() const
Definition: object_access_control.h:77
ObjectAccessControl & set_domain(std::string v)
Definition: object_access_control.h:127
std::string const & id() const
Definition: object_access_control.h:80
ObjectAccessControl & set_project_team(ProjectTeam v)
Definition: object_access_control.h:151
ObjectAccessControl & set_kind(std::string v)
Definition: object_access_control.h:147
std::string const & etag() const
Definition: object_access_control.h:79
std::string const & bucket() const
Definition: object_access_control.h:72
ObjectAccessControl & set_generation(std::int64_t v)
Definition: object_access_control.h:123
std::string const & role() const
Definition: object_access_control.h:87
ObjectAccessControl & set_entity(std::string v)
Definition: object_access_control.h:97
friend bool operator!=(ObjectAccessControl const &lhs, ObjectAccessControl const &rhs)
Definition: object_access_control.h:163
static std::string ROLE_OWNER()
Definition: object_access_control.h:51
std::string const & email() const
Definition: object_access_control.h:76
ProjectTeam const & project_team() const
Definition: object_access_control.h:83
static std::string ROLE_READER()
Definition: object_access_control.h:52
ObjectAccessControl & set_role(std::string v)
Definition: object_access_control.h:101
ObjectAccessControl & set_etag(std::string v)
Definition: object_access_control.h:139
std::string const & kind() const
Definition: object_access_control.h:81
std::string const & object() const
Definition: object_access_control.h:73
bool has_project_team() const
Definition: object_access_control.h:82
ObjectAccessControl & set_id(std::string v)
Definition: object_access_control.h:143
absl::optional< ProjectTeam > const & project_team_as_optional() const
Definition: object_access_control.h:84
ObjectAccessControl & set_self_link(std::string v)
Definition: object_access_control.h:155
ObjectAccessControl & set_entity_id(std::string v)
Definition: object_access_control.h:135
static std::string TEAM_VIEWERS()
Definition: object_access_control.h:65
friend bool operator==(ObjectAccessControl const &lhs, ObjectAccessControl const &rhs)
ObjectAccessControl & set_email(std::string v)
Definition: object_access_control.h:131
static std::string TEAM_EDITORS()
Definition: object_access_control.h:63
ObjectAccessControl & set_bucket(std::string v)
Definition: object_access_control.h:115
std::string const & self_link() const
Definition: object_access_control.h:88
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
std::string TEAM_VIEWERS()
Definition: project_team.h:76
std::string TEAM_EDITORS()
Definition: project_team.h:74
std::string TEAM_OWNERS()
Definition: project_team.h:75
Represents the projectTeam field in *AccessControls.
Definition: project_team.h:35