Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
bucket_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_BUCKET_ACCESS_CONTROL_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_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 bucketAccessControl resource in Google Cloud Storage.
31 *
32 * BucketAccessControl 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/bucketAccessControls for
37 * an authoritative source of field definitions.
38 */
40 public:
41 BucketAccessControl() = 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& domain() const { return domain_; }
74 std::string const& email() const { return email_; }
75 std::string const& entity() const { return entity_; }
76 std::string const& entity_id() const { return entity_id_; }
77 std::string const& etag() const { return etag_; }
78 std::string const& id() const { return id_; }
79 std::string const& kind() const { return kind_; }
80 bool has_project_team() const { return project_team_.has_value(); }
81 ProjectTeam const& project_team() const { return *project_team_; }
82 absl::optional<ProjectTeam> const& project_team_as_optional() const {
83 return project_team_;
84 }
85 std::string const& role() const { return role_; }
86 std::string const& self_link() const { return self_link_; }
87 ///@}
88
89 ///@{
90 /**
91 * @name Modifiers for mutable attributes.
92 *
93 * The follow attributes can be changed in update and patch operations.
94 */
95 BucketAccessControl& set_entity(std::string v) {
96 entity_ = std::move(v);
97 return *this;
98 }
99 BucketAccessControl& set_role(std::string v) {
100 role_ = std::move(v);
101 return *this;
102 }
103 ///@}
104
105 ///@{
106 /**
107 * @name Testing modifiers.
108 *
109 * The following attributes cannot be changed when updating, creating, or
110 * patching an BucketAccessControl resource. However, it is useful to change
111 * them in tests, e.g., when mocking the results from the C++ client library.
112 */
113 BucketAccessControl& set_bucket(std::string v) {
114 bucket_ = std::move(v);
115 return *this;
116 }
117 BucketAccessControl& set_domain(std::string v) {
118 domain_ = std::move(v);
119 return *this;
120 }
121 BucketAccessControl& set_email(std::string v) {
122 email_ = std::move(v);
123 return *this;
124 }
125 BucketAccessControl& set_entity_id(std::string v) {
126 entity_id_ = std::move(v);
127 return *this;
128 }
129 BucketAccessControl& set_etag(std::string v) {
130 etag_ = std::move(v);
131 return *this;
132 }
133 BucketAccessControl& set_id(std::string v) {
134 id_ = std::move(v);
135 return *this;
136 }
137 BucketAccessControl& set_kind(std::string v) {
138 kind_ = std::move(v);
139 return *this;
140 }
142 project_team_ = std::move(v);
143 return *this;
144 }
145 BucketAccessControl& set_self_link(std::string v) {
146 self_link_ = std::move(v);
147 return *this;
148 }
149 ///@}
150
151 friend bool operator==(BucketAccessControl const& lhs,
152 BucketAccessControl const& rhs);
153 friend bool operator!=(BucketAccessControl const& lhs,
154 BucketAccessControl const& rhs) {
155 return !(lhs == rhs);
156 }
157
158 private:
159 std::string bucket_;
160 std::string domain_;
161 std::string email_;
162 std::string entity_;
163 std::string entity_id_;
164 std::string etag_;
165 std::string id_;
166 std::string kind_;
167 absl::optional<ProjectTeam> project_team_;
168 std::string role_;
169 std::string self_link_;
170};
171
172std::ostream& operator<<(std::ostream& os, BucketAccessControl const& rhs);
173
174/**
175 * Prepares a patch for a BucketAccessControl resource.
176 *
177 * The BucketAccessControl resource only has two modifiable fields: entity
178 * and role. This class allows application developers to setup a PATCH message,
179 * note that some of the possible PATCH messages may result in errors from the
180 * server, for example: while it is possible to express "change the value of the
181 * entity field" with a PATCH request, the server rejects such changes.
182 *
183 * @see
184 * https://cloud.google.com/storage/docs/json_api/v1/how-tos/performance#patch
185 * for general information on PATCH requests for the Google Cloud Storage
186 * JSON API.
187 */
189 public:
191
192 std::string BuildPatch() const { return impl_.ToString(); }
193
194 BucketAccessControlPatchBuilder& set_entity(std::string const& v) {
195 impl_.SetStringField("entity", v);
196 return *this;
197 }
198
200 impl_.RemoveField("entity");
201 return *this;
202 }
203
204 BucketAccessControlPatchBuilder& set_role(std::string const& v) {
205 impl_.SetStringField("role", v);
206 return *this;
207 }
208
210 impl_.RemoveField("role");
211 return *this;
212 }
213
214 private:
215 friend struct internal::PatchBuilderDetails;
216 internal::PatchBuilder impl_;
217};
218
219GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
220} // namespace storage
221} // namespace cloud
222} // namespace google
223
224#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_ACCESS_CONTROL_H
Prepares a patch for a BucketAccessControl resource.
Definition: bucket_access_control.h:188
BucketAccessControlPatchBuilder & set_role(std::string const &v)
Definition: bucket_access_control.h:204
BucketAccessControlPatchBuilder & set_entity(std::string const &v)
Definition: bucket_access_control.h:194
BucketAccessControlPatchBuilder & delete_entity()
Definition: bucket_access_control.h:199
BucketAccessControlPatchBuilder & delete_role()
Definition: bucket_access_control.h:209
std::string BuildPatch() const
Definition: bucket_access_control.h:192
Wraps the bucketAccessControl resource in Google Cloud Storage.
Definition: bucket_access_control.h:39
ProjectTeam const & project_team() const
Definition: bucket_access_control.h:81
BucketAccessControl & set_etag(std::string v)
Definition: bucket_access_control.h:129
BucketAccessControl & set_self_link(std::string v)
Definition: bucket_access_control.h:145
static std::string ROLE_OWNER()
Definition: bucket_access_control.h:51
BucketAccessControl & set_project_team(ProjectTeam v)
Definition: bucket_access_control.h:141
static std::string TEAM_VIEWERS()
Definition: bucket_access_control.h:65
std::string const & bucket() const
Definition: bucket_access_control.h:72
BucketAccessControl & set_domain(std::string v)
Definition: bucket_access_control.h:117
friend bool operator!=(BucketAccessControl const &lhs, BucketAccessControl const &rhs)
Definition: bucket_access_control.h:153
BucketAccessControl & set_kind(std::string v)
Definition: bucket_access_control.h:137
std::string const & entity() const
Definition: bucket_access_control.h:75
absl::optional< ProjectTeam > const & project_team_as_optional() const
Definition: bucket_access_control.h:82
std::string const & domain() const
Definition: bucket_access_control.h:73
static std::string ROLE_READER()
Definition: bucket_access_control.h:52
std::string const & role() const
Definition: bucket_access_control.h:85
friend bool operator==(BucketAccessControl const &lhs, BucketAccessControl const &rhs)
BucketAccessControl & set_role(std::string v)
Definition: bucket_access_control.h:99
std::string const & entity_id() const
Definition: bucket_access_control.h:76
std::string const & kind() const
Definition: bucket_access_control.h:79
std::string const & self_link() const
Definition: bucket_access_control.h:86
BucketAccessControl & set_entity_id(std::string v)
Definition: bucket_access_control.h:125
BucketAccessControl & set_id(std::string v)
Definition: bucket_access_control.h:133
std::string const & email() const
Definition: bucket_access_control.h:74
static std::string TEAM_OWNERS()
Definition: bucket_access_control.h:64
BucketAccessControl & set_entity(std::string v)
Definition: bucket_access_control.h:95
bool has_project_team() const
Definition: bucket_access_control.h:80
static std::string TEAM_EDITORS()
Definition: bucket_access_control.h:63
std::string const & id() const
Definition: bucket_access_control.h:78
BucketAccessControl & set_email(std::string v)
Definition: bucket_access_control.h:121
std::string const & etag() const
Definition: bucket_access_control.h:77
BucketAccessControl & set_bucket(std::string v)
Definition: bucket_access_control.h:113
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