Google Cloud Bigtable C++ Client  1.35.0
A C++ Client Library for Google Cloud Bigtable
iam_binding.h
Go to the documentation of this file.
1 // Copyright 2019 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_BIGTABLE_IAM_BINDING_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_IAM_BINDING_H
17 
18 #include "google/cloud/bigtable/version.h"
19 #include <google/bigtable/admin/v2/bigtable_instance_admin.pb.h>
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 namespace google {
25 namespace cloud {
26 namespace bigtable {
28 /**
29  * Create a google::iam::v1::Binding.
30  *
31  * @see
32  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
33  * for more information about a IAM policies.
34  *
35  * @param role the role which is assigned to members
36  * @param begin iterator pointing to the first member
37  * @param end iterator pointing to past last member
38  *
39  * @return The binding
40  */
41 template <class InputIt>
42 google::iam::v1::Binding IamBinding(std::string role, InputIt begin,
43  InputIt end);
44 
45 /**
46  * Create a google::iam::v1::Binding.
47  *
48  * @see
49  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
50  * for more information about a IAM policies.
51  *
52  * @param role the role which is assigned to members
53  * @param begin iterator pointing to the first member
54  * @param end iterator pointing to past last member
55  * @param condition expression indicating when the binding is effective
56  *
57  * @return The binding
58  */
59 template <class InputIt>
60 google::iam::v1::Binding IamBinding(std::string role, InputIt begin,
61  InputIt end, google::type::Expr condition);
62 
63 /**
64  * Create a google::iam::v1::Binding.
65  *
66  * @see
67  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
68  * for more information about a IAM policies.
69  *
70  * @param role the role which is assigned to members
71  * @param members initializer_list of members
72  *
73  * @return The binding
74  */
75 google::iam::v1::Binding IamBinding(std::string role,
76  std::initializer_list<std::string> members);
77 
78 /**
79  * Create a google::iam::v1::Binding.
80  *
81  * @see
82  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
83  * for more information about a IAM policies.
84  *
85  * @param role the role which is assigned to members
86  * @param members initializer_list of members
87  * @param condition expression indicating when the binding is effective
88  *
89  * @return The binding
90  */
91 google::iam::v1::Binding IamBinding(std::string role,
92  std::initializer_list<std::string> members,
93  google::type::Expr condition);
94 
95 /**
96  * Create a google::iam::v1::Binding.
97  *
98  * @see
99  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
100  * for more information about a IAM policies.
101  *
102  * @param role the role which is assigned to members
103  * @param members vector of members
104  *
105  * @return The binding
106  */
107 google::iam::v1::Binding IamBinding(std::string role,
108  std::vector<std::string> members);
109 
110 /**
111  * Create a google::iam::v1::Binding.
112  *
113  * @see
114  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
115  * for more information about a IAM policies.
116  *
117  * @param role the role which is assigned to members
118  * @param members vector of members
119  * @param condition expression indicating when the binding is effective
120  *
121  * @return The binding
122  */
123 google::iam::v1::Binding IamBinding(std::string role,
124  std::vector<std::string> members,
125  google::type::Expr condition);
126 
127 std::ostream& operator<<(std::ostream& os,
128  google::iam::v1::Binding const& binding);
129 
130 /**
131  * Append members to a google::iam::v1::Binding.
132  *
133  * @param binding the role which is assigned to members
134  * @param begin iterator pointing to the first member
135  * @param end iterator pointing to past last member
136  *
137  * @return The binding with appended members
138  */
139 template <class InputIt>
140 google::iam::v1::Binding IamBindingAppendMembers(
141  google::iam::v1::Binding binding, InputIt begin, InputIt end) {
142  for (auto member = begin; member != end; ++member) {
143  *binding.add_members() = *member;
144  }
145  return binding;
146 }
147 
148 /**
149  * Set a condition to an google::iam::v1::Binding.
150  *
151  * @param binding the binding to which the condition is added
152  * @param condition the added condition
153  *
154  * @return the binding with the condition set
155  */
156 google::iam::v1::Binding IamBindingSetCondition(
157  google::iam::v1::Binding binding, google::type::Expr condition);
158 
159 template <class InputIt>
160 google::iam::v1::Binding IamBinding(std::string role, InputIt begin,
161  InputIt end) {
162  google::iam::v1::Binding res;
163  res.set_role(std::move(role));
164  return IamBindingAppendMembers(res, begin, end);
165 }
166 
167 template <class InputIt>
168 google::iam::v1::Binding IamBinding(std::string role, InputIt begin,
169  InputIt end, google::type::Expr condition) {
170  return IamBindingSetCondition(IamBinding(std::move(role), begin, end),
171  std::move(condition));
172 }
173 
175 } // namespace bigtable
176 } // namespace cloud
177 } // namespace google
178 
179 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_IAM_BINDING_H