Skip to content

Commit 8211af4

Browse files
authored
feat(bigtable): add CMEK attributes to admin APIs (#5921)
1 parent afca7b2 commit 8211af4

4 files changed

Lines changed: 52 additions & 19 deletions

File tree

google/cloud/bigtable/cluster_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ class ClusterConfig {
4646
proto_.set_default_storage_type(storage);
4747
}
4848

49+
ClusterConfig& SetEncryptionConfig(
50+
google::bigtable::admin::v2::Cluster::EncryptionConfig encryption) & {
51+
*proto_.mutable_encryption_config() = std::move(encryption);
52+
return *this;
53+
}
54+
ClusterConfig&& SetEncryptionConfig(
55+
google::bigtable::admin::v2::Cluster::EncryptionConfig encryption) && {
56+
return std::move(SetEncryptionConfig(std::move(encryption)));
57+
}
58+
4959
std::string const& GetName() { return proto_.name(); }
5060

5161
google::bigtable::admin::v2::Cluster const& as_proto() const& {

google/cloud/bigtable/cluster_config_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/bigtable/cluster_config.h"
16+
#include "google/cloud/testing_util/is_proto_equal.h"
17+
#include <google/protobuf/text_format.h>
1618
#include <gmock/gmock.h>
1719

1820
namespace google {
@@ -21,6 +23,9 @@ namespace bigtable {
2123
inline namespace BIGTABLE_CLIENT_NS {
2224
namespace {
2325

26+
using ::google::cloud::testing_util::IsProtoEqual;
27+
using ::google::protobuf::TextFormat;
28+
2429
TEST(ClusterConfigTest, Constructor) {
2530
ClusterConfig config("somewhere", 7, ClusterConfig::SSD);
2631
auto const& proto = config.as_proto();
@@ -42,6 +47,23 @@ TEST(ClusterConfigTest, Move) {
4247
EXPECT_EQ(ClusterConfig::HDD, proto.default_storage_type());
4348
}
4449

50+
TEST(ClusterConfigTest, SetEncryptionConfig) {
51+
google::bigtable::admin::v2::Cluster::EncryptionConfig encryption;
52+
encryption.set_kms_key_name("test-only-invalid-kms-key-name");
53+
auto const actual = ClusterConfig("somewhere", 7, ClusterConfig::HDD)
54+
.SetEncryptionConfig(std::move(encryption))
55+
.as_proto();
56+
auto constexpr kText = R"pb(
57+
location: "somewhere"
58+
serve_nodes: 7
59+
default_storage_type: HDD
60+
encryption_config { kms_key_name: "test-only-invalid-kms-key-name" }
61+
)pb";
62+
google::bigtable::admin::v2::Cluster expected;
63+
ASSERT_TRUE(TextFormat::ParseFromString(kText, &expected));
64+
EXPECT_THAT(actual, IsProtoEqual(expected));
65+
}
66+
4567
} // namespace
4668
} // namespace BIGTABLE_CLIENT_NS
4769
} // namespace bigtable

google/cloud/bigtable/table_admin.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ static_assert(std::is_copy_assignable<bigtable::TableAdmin>::value,
3636
"bigtable::TableAdmin must be assignable");
3737

3838
// NOLINTNEXTLINE(readability-identifier-naming)
39-
constexpr TableAdmin::TableView TableAdmin::VIEW_UNSPECIFIED;
39+
constexpr TableAdmin::TableView TableAdmin::ENCRYPTION_VIEW;
4040
// NOLINTNEXTLINE(readability-identifier-naming)
41-
constexpr TableAdmin::TableView TableAdmin::NAME_ONLY;
41+
constexpr TableAdmin::TableView TableAdmin::FULL;
4242
// NOLINTNEXTLINE(readability-identifier-naming)
43-
constexpr TableAdmin::TableView TableAdmin::SCHEMA_VIEW;
43+
constexpr TableAdmin::TableView TableAdmin::NAME_ONLY;
4444
// NOLINTNEXTLINE(readability-identifier-naming)
4545
constexpr TableAdmin::TableView TableAdmin::REPLICATION_VIEW;
4646
// NOLINTNEXTLINE(readability-identifier-naming)
47-
constexpr TableAdmin::TableView TableAdmin::FULL;
47+
constexpr TableAdmin::TableView TableAdmin::SCHEMA_VIEW;
48+
// NOLINTNEXTLINE(readability-identifier-naming)
49+
constexpr TableAdmin::TableView TableAdmin::VIEW_UNSPECIFIED;
4850

4951
/// Shortcuts to avoid typing long names over and over.
5052
using ClientUtils = bigtable::internal::UnaryClientUtils<AdminClient>;

google/cloud/bigtable/table_admin.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,25 @@ class TableAdmin {
188188
//@{
189189
/// @name Convenience shorthands for the schema views.
190190
using TableView = google::bigtable::admin::v2::Table::View;
191-
/// Use the default view as defined for each function.
192-
// NOLINTNEXTLINE(readability-identifier-naming)
193-
constexpr static TableView VIEW_UNSPECIFIED =
194-
google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED;
191+
/// Only populate 'name' and fields related to the table's encryption state.
192+
static auto constexpr ENCRYPTION_VIEW = // NOLINT(readability-identifier-naming)
193+
google::bigtable::admin::v2::Table::ENCRYPTION_VIEW;
194+
/// Populate all the fields in the response.
195+
static auto constexpr FULL = // NOLINT(readability-identifier-naming)
196+
google::bigtable::admin::v2::Table::FULL;
195197
/// Populate only the name in the responses.
196-
// NOLINTNEXTLINE(readability-identifier-naming)
197-
constexpr static TableView NAME_ONLY =
198+
static auto constexpr NAME_ONLY = // NOLINT(readability-identifier-naming)
198199
google::bigtable::admin::v2::Table::NAME_ONLY;
199-
/// Populate only the name and the fields related to the table schema.
200-
// NOLINTNEXTLINE(readability-identifier-naming)
201-
constexpr static TableView SCHEMA_VIEW =
202-
google::bigtable::admin::v2::Table::SCHEMA_VIEW;
203200
/// Populate only the name and the fields related to the table replication
204201
/// state.
205-
// NOLINTNEXTLINE(readability-identifier-naming)
206-
constexpr static TableView REPLICATION_VIEW =
202+
static auto constexpr REPLICATION_VIEW = // NOLINT(readability-identifier-naming)
207203
google::bigtable::admin::v2::Table::REPLICATION_VIEW;
208-
/// Populate all the fields in the response.
209-
// NOLINTNEXTLINE(readability-identifier-naming)
210-
constexpr static TableView FULL = google::bigtable::admin::v2::Table::FULL;
204+
/// Populate only the name and the fields related to the table schema.
205+
static auto constexpr SCHEMA_VIEW = // NOLINT(readability-identifier-naming)
206+
google::bigtable::admin::v2::Table::SCHEMA_VIEW;
207+
/// Use the default view as defined for each function.
208+
static auto constexpr VIEW_UNSPECIFIED = // NOLINT(readability-identifier-naming)
209+
google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED;
211210
//@}
212211

213212
std::string const& project() const { return client_->project(); }

0 commit comments

Comments
 (0)