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