Google Cloud C++ Client  1.42.0
C++ Client Library for Google Cloud Platform
iam_updater.h
Go to the documentation of this file.
1 // Copyright 2021 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_IAM_UPDATER_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_IAM_UPDATER_H
17 
18 #include "google/cloud/version.h"
19 #include "absl/types/optional.h"
20 #include <google/iam/v1/policy.pb.h>
21 #include <functional>
22 
23 namespace google {
24 namespace cloud {
26 
27 /**
28  * Used in the `SetIamPolicy()` read-modify-write cycles where an `etag` helps
29  * prevent simultaneous updates of a policy from overwriting each other.
30  *
31  * The updater is called with a recently fetched policy, and should either
32  * return an empty optional if no changes are required, or return a new policy
33  * to be set. In the latter case the updater should either (1) set the `etag`
34  * of the returned policy to that of the recently fetched policy (strongly
35  * suggested), or (2) not set the `etag` at all.
36  *
37  * In case (1) if the `etag` does not match the existing policy (i.e., there
38  * has been an intermediate update), this update is dropped and a new cycle is
39  * initiated. In case (2) the existing policy is overwritten blindly.
40  */
41 using IamUpdater = std::function<absl::optional<google::iam::v1::Policy>(
42  google::iam::v1::Policy)>;
43 
45 } // namespace cloud
46 } // namespace google
47 
48 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_IAM_UPDATER_H