Skip to content

Commit 6216fdb

Browse files
committed
fix ci failures
1 parent 6efc34d commit 6216fdb

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

google/cloud/storage/bucket_metadata.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ BucketMetadataPatchBuilder& BucketMetadataPatchBuilder::ResetDefaultAcl() {
362362
BucketMetadataPatchBuilder& BucketMetadataPatchBuilder::SetEncryption(
363363
BucketEncryption const& v) {
364364
internal::PatchBuilder builder;
365-
builder.SetStringField("defaultKmsKeyName", v.default_kms_key_name);
365+
if (v.default_kms_key_name.empty()) {
366+
builder.RemoveField("defaultKmsKeyName");
367+
} else {
368+
builder.SetStringField("defaultKmsKeyName", v.default_kms_key_name);
369+
}
366370

367371
auto add_config_patch = [&](char const* name, auto const& config) {
368372
if (config.restriction_mode.empty()) return;

google/cloud/storage/examples/storage_bucket_encryption_enforcement_samples.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ void UpdateBucketEncryptionEnforcementConfig(
140140
namespace gcs = ::google::cloud::storage;
141141
using ::google::cloud::StatusOr;
142142
[](gcs::Client client, std::string const& bucket_name) {
143+
StatusOr<gcs::BucketMetadata> original =
144+
client.GetBucketMetadata(bucket_name);
145+
146+
gcs::BucketMetadata updated_metadata = *original;
143147
gcs::BucketEncryption encryption;
148+
if (original->has_encryption()) {
149+
encryption = original->encryption();
150+
}
151+
144152
// 1. Update a specific type (e.g., change GMEK to FullyRestricted)
145153
encryption.google_managed_encryption_enforcement_config.restriction_mode =
146154
"FullyRestricted";
@@ -152,9 +160,10 @@ void UpdateBucketEncryptionEnforcementConfig(
152160
encryption.customer_supplied_encryption_enforcement_config
153161
.restriction_mode = "FullyRestricted";
154162

155-
StatusOr<gcs::BucketMetadata> updated = client.PatchBucket(
156-
bucket_name,
157-
gcs::BucketMetadataPatchBuilder().SetEncryption(encryption));
163+
updated_metadata.set_encryption(encryption);
164+
165+
StatusOr<gcs::BucketMetadata> updated =
166+
client.PatchBucket(bucket_name, *original, updated_metadata);
158167
if (!updated) throw std::move(updated).status();
159168

160169
std::cout << "Encryption enforcement policy updated for bucket "
@@ -183,15 +192,6 @@ void RunAll(std::vector<std::string> const& argv) {
183192

184193
auto constexpr kBucketPeriod = std::chrono::seconds(2);
185194

186-
// Clean up any potentially leaked buckets from a previous run before creating
187-
// them.
188-
(void)examples::RemoveBucketAndContents(client, "g-" + bucket_name);
189-
if (!examples::UsingEmulator()) std::this_thread::sleep_for(kBucketPeriod);
190-
(void)examples::RemoveBucketAndContents(client, "c-" + bucket_name);
191-
if (!examples::UsingEmulator()) std::this_thread::sleep_for(kBucketPeriod);
192-
(void)examples::RemoveBucketAndContents(client, "rc-" + bucket_name);
193-
if (!examples::UsingEmulator()) std::this_thread::sleep_for(kBucketPeriod);
194-
195195
std::cout << "\nRunning the SetBucketEncryptionEnforcementConfig() example"
196196
<< std::endl;
197197
SetBucketEncryptionEnforcementConfig(client, {project_id, bucket_name});

0 commit comments

Comments
 (0)