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