Google Cloud Bigtable C++ Client  1.33.0
A C++ Client Library for Google Cloud Bigtable
iam_binding.cc
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 // 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 #include "google/cloud/bigtable/iam_binding.h"
16 #include "google/cloud/bigtable/expr.h"
17 #include <google/protobuf/util/message_differencer.h>
18 #include <algorithm>
19 #include <iostream>
20 #include <iterator>
21 
22 namespace google {
23 namespace cloud {
24 namespace bigtable {
26 google::iam::v1::Binding IamBinding(
27  std::string role, std::initializer_list<std::string> members) {
28  return IamBinding(std::move(role), members.begin(), members.end());
29 }
30 
31 google::iam::v1::Binding IamBinding(std::string role,
32  std::initializer_list<std::string> members,
33  google::type::Expr condition) {
34  return IamBindingSetCondition(IamBinding(std::move(role), members),
35  std::move(condition));
36 }
37 
38 google::iam::v1::Binding IamBinding(std::string role,
39  std::vector<std::string> members) {
40  google::iam::v1::Binding res;
41  for (auto& member : members) {
42  *res.add_members() = std::move(member);
43  }
44  res.set_role(std::move(role));
45  return res;
46 }
47 
48 google::iam::v1::Binding IamBinding(std::string role,
49  std::vector<std::string> members,
50  google::type::Expr condition) {
51  return IamBindingSetCondition(IamBinding(std::move(role), std::move(members)),
52  std::move(condition));
53 }
54 
55 google::iam::v1::Binding IamBindingSetCondition(
56  google::iam::v1::Binding binding, google::type::Expr condition) {
57  *binding.mutable_condition() = std::move(condition);
58  return binding;
59 }
60 
61 std::ostream& operator<<(std::ostream& os,
62  google::iam::v1::Binding const& binding) {
63  os << binding.role() << ": [";
64  bool first = true;
65  for (auto const& member : binding.members()) {
66  os << (first ? "" : ", ") << member;
67  first = false;
68  }
69  os << "]";
70  if (binding.has_condition()) {
71  os << " when " << binding.condition();
72  }
73  return os;
74 }
75 
77 } // namespace bigtable
78 } // namespace cloud
79 } // namespace google