Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
metadata_update_policy.h
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
24namespace google {
25namespace cloud {
26namespace bigtable {
27GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
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 */
41class 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
65inline bool operator==(MetadataParamTypes const& lhs,
66 MetadataParamTypes const& rhs) {
67 return lhs.type() == rhs.type();
68}
69
70inline 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
105GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
106} // namespace bigtable
107namespace bigtable_internal {
108GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
109
110/**
111 * Returns a `MetadataUpdatePolicy` that implements the explicit routing
112 * specification in `bigtable.proto`.
113 */
114bigtable::MetadataUpdatePolicy MakeMetadataUpdatePolicy(
115 std::string const& table_name, std::string const& app_profile_id);
116
117GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
118} // namespace bigtable_internal
119} // namespace cloud
120} // namespace google
121
122#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_METADATA_UPDATE_POLICY_H
static MetadataParamTypes const APP_PROFILE_NAME
Definition: metadata_update_policy.h:52
static MetadataParamTypes const RESOURCE
Definition: metadata_update_policy.h:48
static MetadataParamTypes const TABLE_NAME
Definition: metadata_update_policy.h:50
static MetadataParamTypes const PARENT
Definition: metadata_update_policy.h:44
static MetadataParamTypes const BACKUP_NAME
Definition: metadata_update_policy.h:56
static MetadataParamTypes const NAME
Definition: metadata_update_policy.h:46
std::string const & type() const
Definition: metadata_update_policy.h:58
static MetadataParamTypes const INSTANCE_NAME
Definition: metadata_update_policy.h:54
MetadataUpdatePolicy holds supported metadata and setup ClientContext.
Definition: metadata_update_policy.h:76
MetadataUpdatePolicy & operator=(MetadataUpdatePolicy &&)=default
void Setup(grpc::ClientContext &context) const
MetadataUpdatePolicy(MetadataUpdatePolicy &&)=default
MetadataUpdatePolicy(MetadataUpdatePolicy const &)=default
MetadataUpdatePolicy & operator=(MetadataUpdatePolicy const &)=default
std::string const & api_client_header() const
Definition: metadata_update_policy.h:98
MetadataUpdatePolicy(std::string const &resource_name, MetadataParamTypes const &metadata_param_type)
Constructor with default metadata pair.
std::string const & value() const
Definition: metadata_update_policy.h:97
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
bool operator!=(MetadataParamTypes const &lhs, MetadataParamTypes const &rhs)
Definition: metadata_update_policy.h:70
bool operator==(MetadataParamTypes const &lhs, MetadataParamTypes const &rhs)
Definition: metadata_update_policy.h:65