Google Cloud Storage C++ Client  1.34.0
A C++ Client Library for Google Cloud Storage
bucket_access_control.h
Go to the documentation of this file.
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 // 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_BUCKET_ACCESS_CONTROL_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_ACCESS_CONTROL_H
17 
18 #include "google/cloud/storage/internal/access_control_common.h"
19 #include "google/cloud/storage/internal/patch_builder.h"
20 #include "google/cloud/storage/version.h"
21 #include "google/cloud/status_or.h"
22 #include <string>
23 
24 namespace google {
25 namespace cloud {
26 namespace storage {
28 namespace internal {
29 struct BucketAccessControlParser;
30 } // namespace internal
31 
32 /**
33  * Wraps the bucketAccessControl resource in Google Cloud Storage.
34  *
35  * BucketAccessControl describes the access to a bucket for a single entity,
36  * where the entity might be a user, group, or other role.
37  *
38  * @see
39  * https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls for
40  * an authoritative source of field definitions.
41  */
42 class BucketAccessControl : private internal::AccessControlCommon {
43  public:
44  BucketAccessControl() = default;
45 
46  using AccessControlCommon::ROLE_OWNER;
47  using AccessControlCommon::ROLE_READER;
48  using AccessControlCommon::TEAM_EDITORS;
49  using AccessControlCommon::TEAM_OWNERS;
50  using AccessControlCommon::TEAM_VIEWERS;
51 
52  using AccessControlCommon::bucket;
53  using AccessControlCommon::domain;
54  using AccessControlCommon::email;
55 
56  using AccessControlCommon::entity;
57  BucketAccessControl& set_entity(std::string v) {
58  AccessControlCommon::set_entity(std::move(v));
59  return *this;
60  }
61 
62  using AccessControlCommon::entity_id;
63  using AccessControlCommon::etag;
64  using AccessControlCommon::has_project_team;
65  using AccessControlCommon::id;
66  using AccessControlCommon::kind;
67  using AccessControlCommon::project_team;
68 
69  using AccessControlCommon::role;
70  BucketAccessControl& set_role(std::string v) {
71  AccessControlCommon::set_role(std::move(v));
72  return *this;
73  }
74 
75  using AccessControlCommon::self_link;
76 
77  friend bool operator==(BucketAccessControl const& lhs,
78  BucketAccessControl const& rhs);
79  friend bool operator!=(BucketAccessControl const& lhs,
80  BucketAccessControl const& rhs) {
81  return !(lhs == rhs);
82  }
83 
84  friend struct internal::BucketAccessControlParser;
85  friend class internal::GrpcClient;
86 };
87 
88 std::ostream& operator<<(std::ostream& os, BucketAccessControl const& rhs);
89 
90 /**
91  * Prepares a patch for a BucketAccessControl resource.
92  *
93  * The BucketAccessControl resource only has two modifiable fields: entity
94  * and role. This class allows application developers to setup a PATCH message,
95  * note that some of the possible PATCH messages may result in errors from the
96  * server, for example: while it is possible to express "change the value of the
97  * entity field" with a PATCH request, the server rejects such changes.
98  *
99  * @see
100  * https://cloud.google.com/storage/docs/json_api/v1/how-tos/performance#patch
101  * for general information on PATCH requests for the Google Cloud Storage
102  * JSON API.
103  */
105  public:
107 
108  std::string BuildPatch() const { return impl_.ToString(); }
109 
111  impl_.SetStringField("entity", v);
112  return *this;
113  }
114 
116  impl_.RemoveField("entity");
117  return *this;
118  }
119 
120  BucketAccessControlPatchBuilder& set_role(std::string const& v) {
121  impl_.SetStringField("role", v);
122  return *this;
123  }
124 
126  impl_.RemoveField("role");
127  return *this;
128  }
129 
130  private:
131  internal::PatchBuilder impl_;
132 };
133 
135 } // namespace storage
136 } // namespace cloud
137 } // namespace google
138 
139 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_ACCESS_CONTROL_H