Google Cloud Storage C++ Client  1.32.1
A C++ Client Library for Google Cloud Storage
iam_policy.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 // 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_IAM_POLICY_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_IAM_POLICY_H
17 
18 #include "google/cloud/storage/version.h"
19 #include "google/cloud/status_or.h"
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 namespace google {
25 namespace cloud {
26 namespace storage {
27 inline namespace STORAGE_CLIENT_NS {
28 /**
29  * Represents a google::type::Expr.
30  *
31  * This is a textual representation of an expression in Common Expression
32  * Language (CEL) syntax.
33  */
35  public:
36  /**
37  * Create a `NativeExpression`.
38  *
39  * @param expression the expression in Common Expression Language.
40  * @param title an optional title for the expression, i.e. a short string
41  * describing its purpose.
42  * @param description an optional description of the expression. This is a
43  * longer text which describes the expression, e.g. when hovered over it
44  * in a UI.
45  * @param location an optional string indicating the location of the
46  * expression for error reporting, e.g. a file name and a position in the
47  * file.
48  */
49  // NOLINTNEXTLINE(google-explicit-constructor)
50  NativeExpression(std::string expression, std::string title = "",
51  std::string description = "", std::string location = "");
53 
54  NativeExpression(NativeExpression const& other);
56 
57  // This have to be declared explicitly and defined out of line because `Impl`
58  // is incomplete at this point.
61 
62  std::string expression() const;
63  void set_expression(std::string expression);
64  std::string title() const;
65  void set_title(std::string title);
66  std::string description() const;
67  void set_description(std::string description);
68  std::string location() const;
69  void set_location(std::string location);
70 
71  private:
72  struct Impl;
73  explicit NativeExpression(std::unique_ptr<Impl> impl);
74  friend class NativeIamPolicy;
75  friend class NativeIamBinding;
76  std::unique_ptr<Impl> pimpl_;
77 };
78 
79 std::ostream& operator<<(std::ostream& stream, NativeExpression const&);
80 
81 /**
82  * Represents a Binding which associates a `member` with a particular `role`
83  * which can be used for Identity and Access management for Cloud Platform
84  * Resources.
85  *
86  * For more information about a Binding please refer to:
87  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Binding
88  *
89  * Compared to `IamBinding`, `NativeIamBinding` is a more future-proof
90  * solution - it gracefully tolerates changes in the underlying protocol.
91  * If IamBinding contains more fields than just a role and members, in the
92  * future, `NativeIamBinding` will preserve them (contrary to IamBinding).
93  */
95  public:
96  NativeIamBinding(std::string role, std::vector<std::string> members);
97  NativeIamBinding(std::string role, std::vector<std::string> members,
98  NativeExpression condition);
100 
101  NativeIamBinding(NativeIamBinding const& other);
103 
104  // This have to be declared explicitly and defined out of line because `Impl`
105  // is incomplete at this point.
108 
109  std::string role() const;
110  void set_role(std::string role);
111  std::vector<std::string> const& members() const;
112  std::vector<std::string>& members();
113  NativeExpression const& condition() const;
115  void set_condition(NativeExpression condition);
116  bool has_condition() const;
117  void clear_condition();
118 
119  private:
120  struct Impl;
121  explicit NativeIamBinding(std::unique_ptr<Impl> impl);
122  friend class NativeIamPolicy;
123  std::unique_ptr<Impl> pimpl_;
124 };
125 
126 std::ostream& operator<<(std::ostream& os, NativeIamBinding const& binding);
127 
128 /**
129  * Represent the result of a GetIamPolicy or SetIamPolicy request.
130  *
131  * @see
132  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
133  * for more information about IAM policies.
134  *
135  * @see https://tools.ietf.org/html/rfc7232#section-2.3 for more information
136  * about ETags.
137  *
138  * Compared to `IamPolicy`, `NativeIamPolicy` is a more future-proof
139  * solution - it gracefully tolerates changes in the underlying protocol.
140  * If IamPolicy is extended with additional fields in the future,
141  * `NativeIamPolicy` will preserve them (contrary to IamPolicy).
142  */
144  public:
145  explicit NativeIamPolicy(std::vector<NativeIamBinding> bindings,
146  std::string etag = "", std::int32_t version = 0);
147  NativeIamPolicy(NativeIamPolicy const& other);
149 
150  static StatusOr<NativeIamPolicy> CreateFromJson(std::string const& json_rep);
151  std::string ToJson() const;
152 
153  NativeIamPolicy& operator=(NativeIamPolicy const& other);
154 
155  std::int32_t version() const;
156  void set_version(std::int32_t version);
157  std::string etag() const;
158  void set_etag(std::string etag);
159  std::vector<NativeIamBinding>& bindings();
160  std::vector<NativeIamBinding> const& bindings() const;
161 
162  private:
163  struct Impl;
164  explicit NativeIamPolicy(std::unique_ptr<Impl> impl);
165  std::unique_ptr<Impl> pimpl_;
166 };
167 
168 std::ostream& operator<<(std::ostream& os, NativeIamPolicy const& rhs);
169 
170 } // namespace STORAGE_CLIENT_NS
171 } // namespace storage
172 } // namespace cloud
173 } // namespace google
174 
175 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_IAM_POLICY_H