Skip to content

Commit 21d2f86

Browse files
committed
Fix ci failure, address review comments
1 parent bf6f534 commit 21d2f86

File tree

8 files changed

+225
-312
lines changed

8 files changed

+225
-312
lines changed

google/cloud/storage/bucket_encryption.h

Lines changed: 55 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -29,152 +29,95 @@ namespace cloud {
2929
namespace storage {
3030
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3131

32-
/**
33-
* Google Managed Encryption (GMEK) enforcement config of a bucket.
34-
*/
35-
struct GoogleManagedEncryptionEnforcementConfig {
36-
std::string restriction_mode;
37-
std::chrono::system_clock::time_point effective_time;
38-
};
39-
40-
///@{
41-
/// @name Comparison operators For GoogleManagedEncryptionEnforcementConfig
42-
inline bool operator==(GoogleManagedEncryptionEnforcementConfig const& lhs,
43-
GoogleManagedEncryptionEnforcementConfig const& rhs) {
44-
return std::tie(lhs.restriction_mode, lhs.effective_time) ==
45-
std::tie(rhs.restriction_mode, rhs.effective_time);
46-
}
47-
48-
inline bool operator<(GoogleManagedEncryptionEnforcementConfig const& lhs,
49-
GoogleManagedEncryptionEnforcementConfig const& rhs) {
50-
return std::tie(lhs.restriction_mode, lhs.effective_time) <
51-
std::tie(rhs.restriction_mode, rhs.effective_time);
52-
}
53-
54-
inline bool operator!=(GoogleManagedEncryptionEnforcementConfig const& lhs,
55-
GoogleManagedEncryptionEnforcementConfig const& rhs) {
56-
return std::rel_ops::operator!=(lhs, rhs);
57-
}
58-
59-
inline bool operator>(GoogleManagedEncryptionEnforcementConfig const& lhs,
60-
GoogleManagedEncryptionEnforcementConfig const& rhs) {
61-
return std::rel_ops::operator>(lhs, rhs);
62-
}
63-
64-
inline bool operator<=(GoogleManagedEncryptionEnforcementConfig const& lhs,
65-
GoogleManagedEncryptionEnforcementConfig const& rhs) {
66-
return std::rel_ops::operator<=(lhs, rhs);
67-
}
68-
69-
inline bool operator>=(GoogleManagedEncryptionEnforcementConfig const& lhs,
70-
GoogleManagedEncryptionEnforcementConfig const& rhs) {
71-
return std::rel_ops::operator>=(lhs, rhs);
72-
}
73-
///@}
74-
75-
inline std::ostream& operator<<(
76-
std::ostream& os, GoogleManagedEncryptionEnforcementConfig const& rhs) {
77-
return os << "GoogleManagedEncryptionEnforcementConfig={restriction_mode="
78-
<< rhs.restriction_mode << ", effective_time="
79-
<< google::cloud::internal::FormatRfc3339(rhs.effective_time)
80-
<< "}";
81-
}
32+
template <typename Tag>
33+
struct EncryptionEnforcementConfigName;
8234

83-
struct CustomerManagedEncryptionEnforcementConfig {
35+
template <typename Tag>
36+
struct EncryptionEnforcementConfig {
8437
std::string restriction_mode;
8538
std::chrono::system_clock::time_point effective_time;
8639
};
8740

88-
///@{
89-
/// @name Comparison operators For CustomerManagedEncryptionEnforcementConfig
90-
inline bool operator==(CustomerManagedEncryptionEnforcementConfig const& lhs,
91-
CustomerManagedEncryptionEnforcementConfig const& rhs) {
41+
template <typename Tag>
42+
inline bool operator==(EncryptionEnforcementConfig<Tag> const& lhs,
43+
EncryptionEnforcementConfig<Tag> const& rhs) {
9244
return std::tie(lhs.restriction_mode, lhs.effective_time) ==
9345
std::tie(rhs.restriction_mode, rhs.effective_time);
9446
}
9547

96-
inline bool operator<(CustomerManagedEncryptionEnforcementConfig const& lhs,
97-
CustomerManagedEncryptionEnforcementConfig const& rhs) {
48+
template <typename Tag>
49+
inline bool operator<(EncryptionEnforcementConfig<Tag> const& lhs,
50+
EncryptionEnforcementConfig<Tag> const& rhs) {
9851
return std::tie(lhs.restriction_mode, lhs.effective_time) <
9952
std::tie(rhs.restriction_mode, rhs.effective_time);
10053
}
10154

102-
inline bool operator!=(CustomerManagedEncryptionEnforcementConfig const& lhs,
103-
CustomerManagedEncryptionEnforcementConfig const& rhs) {
55+
template <typename Tag>
56+
inline bool operator!=(EncryptionEnforcementConfig<Tag> const& lhs,
57+
EncryptionEnforcementConfig<Tag> const& rhs) {
10458
return std::rel_ops::operator!=(lhs, rhs);
10559
}
10660

107-
inline bool operator>(CustomerManagedEncryptionEnforcementConfig const& lhs,
108-
CustomerManagedEncryptionEnforcementConfig const& rhs) {
61+
template <typename Tag>
62+
inline bool operator>(EncryptionEnforcementConfig<Tag> const& lhs,
63+
EncryptionEnforcementConfig<Tag> const& rhs) {
10964
return std::rel_ops::operator>(lhs, rhs);
11065
}
11166

112-
inline bool operator<=(CustomerManagedEncryptionEnforcementConfig const& lhs,
113-
CustomerManagedEncryptionEnforcementConfig const& rhs) {
67+
template <typename Tag>
68+
inline bool operator<=(EncryptionEnforcementConfig<Tag> const& lhs,
69+
EncryptionEnforcementConfig<Tag> const& rhs) {
11470
return std::rel_ops::operator<=(lhs, rhs);
11571
}
11672

117-
inline bool operator>=(CustomerManagedEncryptionEnforcementConfig const& lhs,
118-
CustomerManagedEncryptionEnforcementConfig const& rhs) {
73+
template <typename Tag>
74+
inline bool operator>=(EncryptionEnforcementConfig<Tag> const& lhs,
75+
EncryptionEnforcementConfig<Tag> const& rhs) {
11976
return std::rel_ops::operator>=(lhs, rhs);
12077
}
121-
///@}
12278

123-
inline std::ostream& operator<<(
124-
std::ostream& os, CustomerManagedEncryptionEnforcementConfig const& rhs) {
125-
return os << "CustomerManagedEncryptionEnforcementConfig={restriction_mode="
126-
<< rhs.restriction_mode << ", effective_time="
79+
template <typename Tag>
80+
inline std::ostream& operator<<(std::ostream& os,
81+
EncryptionEnforcementConfig<Tag> const& rhs) {
82+
return os << EncryptionEnforcementConfigName<Tag>::value
83+
<< "={restriction_mode=" << rhs.restriction_mode
84+
<< ", effective_time="
12785
<< google::cloud::internal::FormatRfc3339(rhs.effective_time)
12886
<< "}";
12987
}
13088

131-
struct CustomerSuppliedEncryptionEnforcementConfig {
132-
std::string restriction_mode;
133-
std::chrono::system_clock::time_point effective_time;
134-
};
135-
136-
///@{
137-
/// @name Comparison operators For CustomerSuppliedEncryptionEnforcementConfig
138-
inline bool operator==(CustomerSuppliedEncryptionEnforcementConfig const& lhs,
139-
CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
140-
return std::tie(lhs.restriction_mode, lhs.effective_time) ==
141-
std::tie(rhs.restriction_mode, rhs.effective_time);
142-
}
143-
144-
inline bool operator<(CustomerSuppliedEncryptionEnforcementConfig const& lhs,
145-
CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
146-
return std::tie(lhs.restriction_mode, lhs.effective_time) <
147-
std::tie(rhs.restriction_mode, rhs.effective_time);
148-
}
89+
struct GoogleManagedEncryptionEnforcementConfigTag {};
90+
using GoogleManagedEncryptionEnforcementConfig =
91+
EncryptionEnforcementConfig<GoogleManagedEncryptionEnforcementConfigTag>;
14992

150-
inline bool operator!=(CustomerSuppliedEncryptionEnforcementConfig const& lhs,
151-
CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
152-
return std::rel_ops::operator!=(lhs, rhs);
153-
}
93+
template <>
94+
struct EncryptionEnforcementConfigName<
95+
GoogleManagedEncryptionEnforcementConfigTag> {
96+
static constexpr char const* value =
97+
"GoogleManagedEncryptionEnforcementConfig";
98+
};
15499

155-
inline bool operator>(CustomerSuppliedEncryptionEnforcementConfig const& lhs,
156-
CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
157-
return std::rel_ops::operator>(lhs, rhs);
158-
}
100+
struct CustomerManagedEncryptionEnforcementConfigTag {};
101+
using CustomerManagedEncryptionEnforcementConfig =
102+
EncryptionEnforcementConfig<CustomerManagedEncryptionEnforcementConfigTag>;
159103

160-
inline bool operator<=(CustomerSuppliedEncryptionEnforcementConfig const& lhs,
161-
CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
162-
return std::rel_ops::operator<=(lhs, rhs);
163-
}
104+
template <>
105+
struct EncryptionEnforcementConfigName<
106+
CustomerManagedEncryptionEnforcementConfigTag> {
107+
static constexpr char const* value =
108+
"CustomerManagedEncryptionEnforcementConfig";
109+
};
164110

165-
inline bool operator>=(CustomerSuppliedEncryptionEnforcementConfig const& lhs,
166-
CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
167-
return std::rel_ops::operator>=(lhs, rhs);
168-
}
169-
///@}
111+
struct CustomerSuppliedEncryptionEnforcementConfigTag {};
112+
using CustomerSuppliedEncryptionEnforcementConfig =
113+
EncryptionEnforcementConfig<CustomerSuppliedEncryptionEnforcementConfigTag>;
170114

171-
inline std::ostream& operator<<(
172-
std::ostream& os, CustomerSuppliedEncryptionEnforcementConfig const& rhs) {
173-
return os << "CustomerSuppliedEncryptionEnforcementConfig={restriction_mode="
174-
<< rhs.restriction_mode << ", effective_time="
175-
<< google::cloud::internal::FormatRfc3339(rhs.effective_time)
176-
<< "}";
177-
}
115+
template <>
116+
struct EncryptionEnforcementConfigName<
117+
CustomerSuppliedEncryptionEnforcementConfigTag> {
118+
static constexpr char const* value =
119+
"CustomerSuppliedEncryptionEnforcementConfig";
120+
};
178121

179122
/**
180123
* Describes the default customer managed encryption key for a bucket.

google/cloud/storage/bucket_encryption_feature_test.cc

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -62,15 +62,17 @@ TEST(BucketEncryptionTest, Parse) {
6262
encryption.google_managed_encryption_enforcement_config
6363
.effective_time));
6464

65-
EXPECT_EQ("NOT_RESTRICTED", encryption.customer_managed_encryption_enforcement_config
66-
.restriction_mode);
65+
EXPECT_EQ("NOT_RESTRICTED",
66+
encryption.customer_managed_encryption_enforcement_config
67+
.restriction_mode);
6768
EXPECT_EQ("2025-12-18T18:13:15Z",
6869
google::cloud::internal::FormatRfc3339(
6970
encryption.customer_managed_encryption_enforcement_config
7071
.effective_time));
7172

72-
EXPECT_EQ("NOT_RESTRICTED", encryption.customer_supplied_encryption_enforcement_config
73-
.restriction_mode);
73+
EXPECT_EQ("NOT_RESTRICTED",
74+
encryption.customer_supplied_encryption_enforcement_config
75+
.restriction_mode);
7476
EXPECT_EQ("2025-12-18T18:13:15Z",
7577
google::cloud::internal::FormatRfc3339(
7678
encryption.customer_supplied_encryption_enforcement_config
@@ -98,18 +100,14 @@ TEST(BucketEncryptionTest, ToJson) {
98100
ASSERT_TRUE(json.contains("encryption"));
99101
auto e = json["encryption"];
100102
EXPECT_EQ("test-key", e["defaultKmsKeyName"]);
101-
EXPECT_EQ(
102-
"FULLY_RESTRICTED",
103-
e["googleManagedEncryptionEnforcementConfig"]["restrictionMode"]);
104-
EXPECT_EQ(
105-
"2025-12-18T18:13:15Z",
106-
e["googleManagedEncryptionEnforcementConfig"]["effectiveTime"]);
107-
EXPECT_EQ(
108-
"NOT_RESTRICTED",
109-
e["customerManagedEncryptionEnforcementConfig"]["restrictionMode"]);
110-
EXPECT_EQ(
111-
"2025-12-18T18:13:15Z",
112-
e["customerManagedEncryptionEnforcementConfig"]["effectiveTime"]);
103+
EXPECT_EQ("FULLY_RESTRICTED",
104+
e["googleManagedEncryptionEnforcementConfig"]["restrictionMode"]);
105+
EXPECT_EQ("2025-12-18T18:13:15Z",
106+
e["googleManagedEncryptionEnforcementConfig"]["effectiveTime"]);
107+
EXPECT_EQ("NOT_RESTRICTED",
108+
e["customerManagedEncryptionEnforcementConfig"]["restrictionMode"]);
109+
EXPECT_EQ("2025-12-18T18:13:15Z",
110+
e["customerManagedEncryptionEnforcementConfig"]["effectiveTime"]);
113111
EXPECT_FALSE(e.contains("customerSuppliedEncryptionEnforcementConfig"));
114112
}
115113

@@ -130,12 +128,10 @@ TEST(BucketEncryptionTest, Patch) {
130128
ASSERT_TRUE(patch.contains("encryption"));
131129
auto e = patch["encryption"];
132130
EXPECT_EQ("test-key", e["defaultKmsKeyName"]);
133-
EXPECT_EQ(
134-
"FULLY_RESTRICTED",
135-
e["googleManagedEncryptionEnforcementConfig"]["restrictionMode"]);
136-
EXPECT_EQ(
137-
"2025-12-18T18:13:15Z",
138-
e["googleManagedEncryptionEnforcementConfig"]["effectiveTime"]);
131+
EXPECT_EQ("FULLY_RESTRICTED",
132+
e["googleManagedEncryptionEnforcementConfig"]["restrictionMode"]);
133+
EXPECT_EQ("2025-12-18T18:13:15Z",
134+
e["googleManagedEncryptionEnforcementConfig"]["effectiveTime"]);
139135
}
140136

141137
} // namespace

google/cloud/storage/bucket_metadata.cc

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ std::ostream& operator<<(std::ostream& os, BucketMetadata const& rhs) {
150150
os << "]";
151151

152152
if (rhs.has_encryption()) {
153-
os << ", encryption="
154-
<< rhs.encryption();
153+
os << ", encryption=" << rhs.encryption();
155154
}
156155

157156
os << ", etag=" << rhs.etag();
@@ -364,45 +363,23 @@ BucketMetadataPatchBuilder& BucketMetadataPatchBuilder::SetEncryption(
364363
BucketEncryption const& v) {
365364
internal::PatchBuilder builder;
366365
builder.SetStringField("defaultKmsKeyName", v.default_kms_key_name);
367-
if (!v.google_managed_encryption_enforcement_config.restriction_mode
368-
.empty()) {
369-
builder.AddSubPatch(
370-
"googleManagedEncryptionEnforcementConfig",
371-
internal::PatchBuilder()
372-
.SetStringField("restrictionMode",
373-
v.google_managed_encryption_enforcement_config
374-
.restriction_mode)
375-
.SetStringField("effectiveTime",
376-
google::cloud::internal::FormatRfc3339(
377-
v.google_managed_encryption_enforcement_config
378-
.effective_time)));
379-
}
380-
if (!v.customer_managed_encryption_enforcement_config.restriction_mode
381-
.empty()) {
382-
builder.AddSubPatch(
383-
"customerManagedEncryptionEnforcementConfig",
384-
internal::PatchBuilder()
385-
.SetStringField("restrictionMode",
386-
v.customer_managed_encryption_enforcement_config
387-
.restriction_mode)
388-
.SetStringField("effectiveTime",
389-
google::cloud::internal::FormatRfc3339(
390-
v.customer_managed_encryption_enforcement_config
391-
.effective_time)));
392-
}
393-
if (!v.customer_supplied_encryption_enforcement_config.restriction_mode
394-
.empty()) {
366+
367+
auto add_config_patch = [&](char const* name, auto const& config) {
368+
if (config.restriction_mode.empty()) return;
395369
builder.AddSubPatch(
396-
"customerSuppliedEncryptionEnforcementConfig",
397-
internal::PatchBuilder()
398-
.SetStringField("restrictionMode",
399-
v.customer_supplied_encryption_enforcement_config
400-
.restriction_mode)
401-
.SetStringField("effectiveTime",
402-
google::cloud::internal::FormatRfc3339(
403-
v.customer_supplied_encryption_enforcement_config
404-
.effective_time)));
405-
}
370+
name, internal::PatchBuilder()
371+
.SetStringField("restrictionMode", config.restriction_mode)
372+
.SetStringField("effectiveTime",
373+
google::cloud::internal::FormatRfc3339(
374+
config.effective_time)));
375+
};
376+
add_config_patch("googleManagedEncryptionEnforcementConfig",
377+
v.google_managed_encryption_enforcement_config);
378+
add_config_patch("customerManagedEncryptionEnforcementConfig",
379+
v.customer_managed_encryption_enforcement_config);
380+
add_config_patch("customerSuppliedEncryptionEnforcementConfig",
381+
v.customer_supplied_encryption_enforcement_config);
382+
406383
impl_.AddSubPatch("encryption", std::move(builder));
407384
return *this;
408385
}

0 commit comments

Comments
 (0)