Google Cloud Storage C++ Client  2.1.0
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 // 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_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 {
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 
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  */
90  public:
91  NativeIamBinding(std::string role, std::vector<std::string> members);
92  NativeIamBinding(std::string role, std::vector<std::string> members,
93  NativeExpression condition);
95 
98 
99  // This have to be declared explicitly and defined out of line because `Impl`
100  // is incomplete at this point.
103 
104  std::string role() const;
105  void set_role(std::string role);
106  std::vector<std::string> const& members() const;
107  std::vector<std::string>& members();
108  NativeExpression const& condition() const;
111  bool has_condition() const;
113 
114  private:
115  struct Impl;
116  explicit NativeIamBinding(std::unique_ptr<Impl> impl);
117  friend class NativeIamPolicy;
118  std::unique_ptr<Impl> pimpl_;
119 };
120 
121 std::ostream& operator<<(std::ostream& os, NativeIamBinding const& binding);
122 
123 /**
124  * Represent the result of a GetIamPolicy or SetIamPolicy request.
125  *
126  * @see
127  * https://cloud.google.com/resource-manager/reference/rest/Shared.Types/Policy
128  * for more information about IAM policies.
129  *
130  * @see https://tools.ietf.org/html/rfc7232#section-2.3 for more information
131  * about ETags.
132  *
133  * Compared to `IamPolicy`, `NativeIamPolicy` is a more future-proof
134  * solution - it gracefully tolerates changes in the underlying protocol.
135  * If IamPolicy is extended with additional fields in the future,
136  * `NativeIamPolicy` will preserve them (contrary to IamPolicy).
137  */
139  public:
140  explicit NativeIamPolicy(std::vector<NativeIamBinding> bindings,
141  std::string etag = "", std::int32_t version = 0);
144 
145  static StatusOr<NativeIamPolicy> CreateFromJson(std::string const& json_rep);
146  std::string ToJson() const;
147 
149 
150  std::int32_t version() const;
151  void set_version(std::int32_t version);
152  std::string etag() const;
153  void set_etag(std::string etag);
154  std::vector<NativeIamBinding>& bindings();
155  std::vector<NativeIamBinding> const& bindings() const;
156 
157  private:
158  struct Impl;
159  explicit NativeIamPolicy(std::unique_ptr<Impl> impl);
160  std::unique_ptr<Impl> pimpl_;
161 };
162 
163 std::ostream& operator<<(std::ostream& os, NativeIamPolicy const& rhs);
164 
166 } // namespace storage
167 } // namespace cloud
168 } // namespace google
169 
170 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_IAM_POLICY_H