Google Cloud Bigtable C++ Client  1.35.0
A C++ Client Library for Google Cloud Bigtable
metadata_update_policy.h
Go to the documentation of this file.
1 // Copyright 2018 Google Inc.
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_BIGTABLE_METADATA_UPDATE_POLICY_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_METADATA_UPDATE_POLICY_H
17 
18 #include "google/cloud/bigtable/version.h"
19 #include <grpcpp/grpcpp.h>
20 #include <memory>
21 #include <string>
22 #include <utility>
23 
24 namespace google {
25 namespace cloud {
26 namespace bigtable {
28 /**
29  * Define the class for governing x-goog-request-params metadata value.
30  *
31  * The value of x-goog-request-params starts with one of the following suffix
32  * "parent=" : Operation in instance, e.g. TableAdmin::CreateTable.
33  * "table_name=" : table_id is known at the time of creation, e.g.
34  * Table::Apply.
35  * "name=" : this is used when table|_id is known only in the RPC call, e.g.
36  * TableAdmin::GetTable.
37  * "resource=" : this is used to set IAM policies for bigtable resource.
38  *
39  * The Setup function also adds x-goog-api-client header for analytics purpose.
40  */
41 class MetadataParamTypes final {
42  public:
43  // NOLINTNEXTLINE(readability-identifier-naming)
44  static MetadataParamTypes const PARENT;
45  // NOLINTNEXTLINE(readability-identifier-naming)
46  static MetadataParamTypes const NAME;
47  // NOLINTNEXTLINE(readability-identifier-naming)
48  static MetadataParamTypes const RESOURCE;
49  // NOLINTNEXTLINE(readability-identifier-naming)
50  static MetadataParamTypes const TABLE_NAME;
51  // NOLINTNEXTLINE(readability-identifier-naming)
52  static MetadataParamTypes const APP_PROFILE_NAME;
53  // NOLINTNEXTLINE(readability-identifier-naming)
54  static MetadataParamTypes const INSTANCE_NAME;
55  // NOLINTNEXTLINE(readability-identifier-naming)
56  static MetadataParamTypes const BACKUP_NAME;
57 
58  std::string const& type() const { return type_; }
59 
60  private:
61  explicit MetadataParamTypes(std::string type) : type_(std::move(type)) {}
62  std::string type_;
63 };
64 
65 inline bool operator==(MetadataParamTypes const& lhs,
66  MetadataParamTypes const& rhs) {
67  return lhs.type() == rhs.type();
68 }
69 
70 inline bool operator!=(MetadataParamTypes const& lhs,
71  MetadataParamTypes const& rhs) {
72  return std::rel_ops::operator!=(lhs, rhs);
73 }
74 
75 /// MetadataUpdatePolicy holds supported metadata and setup ClientContext
77  public:
78  /**
79  * Constructor with default metadata pair.
80  *
81  * @param resource_name hierarchical name of resource, including project id,
82  * instance id and/or table_id.
83  * @param metadata_param_type type to decide prefix for the value of
84  * x-goog-request-params
85  */
86  MetadataUpdatePolicy(std::string const& resource_name,
87  MetadataParamTypes const& metadata_param_type);
88 
93 
94  // Update the ClientContext for the next call.
95  void Setup(grpc::ClientContext& context) const;
96 
97  std::string const& value() const { return value_; }
98  std::string const& api_client_header() const { return api_client_header_; }
99 
100  private:
101  std::string value_;
102  std::string api_client_header_;
103 };
104 
106 } // namespace bigtable
107 } // namespace cloud
108 } // namespace google
109 
110 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_METADATA_UPDATE_POLICY_H