Skip to content

Commit 058887b

Browse files
authored
cleanup(GCS+gRPC): move SignBlob request helpers (#9962)
1 parent d25d981 commit 058887b

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

google/cloud/storage/internal/grpc_client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,13 +1050,13 @@ StatusOr<HmacKeyMetadata> GrpcClient::UpdateHmacKey(
10501050

10511051
StatusOr<SignBlobResponse> GrpcClient::SignBlob(
10521052
SignBlobRequest const& request) {
1053-
auto proto = ToProto(request);
1053+
auto proto = storage_internal::ToProto(request);
10541054
grpc::ClientContext context;
10551055
// This request does not have any options that require using
10561056
// ApplyQueryParameters(context, request)
10571057
auto response = iam_stub_->SignBlob(context, proto);
10581058
if (!response) return std::move(response).status();
1059-
return FromProto(*response);
1059+
return storage_internal::FromProto(*response);
10601060
}
10611061

10621062
StatusOr<ListNotificationsResponse> GrpcClient::ListNotifications(

google/cloud/storage/internal/grpc_sign_blob_request_parser.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,29 @@
1717

1818
namespace google {
1919
namespace cloud {
20-
namespace storage {
20+
namespace storage_internal {
2121
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
22-
namespace internal {
2322

2423
google::iam::credentials::v1::SignBlobRequest ToProto(
25-
SignBlobRequest const& rhs) {
24+
storage::internal::SignBlobRequest const& rhs) {
2625
google::iam::credentials::v1::SignBlobRequest request;
2726
request.set_name("projects/-/serviceAccounts/" + rhs.service_account());
2827
for (auto const& d : rhs.delegates()) request.add_delegates(d);
29-
auto b64decoded = Base64Decode(rhs.base64_encoded_blob());
28+
auto b64decoded = storage::internal::Base64Decode(rhs.base64_encoded_blob());
3029
if (!b64decoded) return request;
3130
request.mutable_payload()->assign(b64decoded->begin(), b64decoded->end());
3231
return request;
3332
}
3433

35-
SignBlobResponse FromProto(
34+
storage::internal::SignBlobResponse FromProto(
3635
google::iam::credentials::v1::SignBlobResponse const& rhs) {
37-
SignBlobResponse response;
36+
storage::internal::SignBlobResponse response;
3837
response.key_id = rhs.key_id();
39-
response.signed_blob = Base64Encode(rhs.signed_blob());
38+
response.signed_blob = storage::internal::Base64Encode(rhs.signed_blob());
4039
return response;
4140
}
4241

43-
} // namespace internal
4442
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
45-
} // namespace storage
43+
} // namespace storage_internal
4644
} // namespace cloud
4745
} // namespace google

google/cloud/storage/internal/grpc_sign_blob_request_parser.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121

2222
namespace google {
2323
namespace cloud {
24-
namespace storage {
24+
namespace storage_internal {
2525
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
26-
namespace internal {
2726

2827
google::iam::credentials::v1::SignBlobRequest ToProto(
29-
SignBlobRequest const& rhs);
30-
SignBlobResponse FromProto(
28+
storage::internal::SignBlobRequest const& rhs);
29+
storage::internal::SignBlobResponse FromProto(
3130
google::iam::credentials::v1::SignBlobResponse const& rhs);
3231

33-
} // namespace internal
3432
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
35-
} // namespace storage
33+
} // namespace storage_internal
3634
} // namespace cloud
3735
} // namespace google
3836

google/cloud/storage/internal/grpc_sign_blob_request_parser_test.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020

2121
namespace google {
2222
namespace cloud {
23-
namespace storage {
23+
namespace storage_internal {
2424
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
25-
namespace internal {
2625
namespace {
2726

2827
using ::google::cloud::testing_util::IsProtoEqual;
@@ -38,11 +37,11 @@ TEST(GrpcSignBlobRequestParser, ToProto) {
3837
)pb",
3938
&expected));
4039

41-
auto b64encoded = Base64Encode("test-only-text-to-sign");
40+
auto b64encoded = storage::internal::Base64Encode("test-only-text-to-sign");
4241

43-
auto request =
44-
SignBlobRequest("test-only-sa", std::move(b64encoded),
45-
{"test-only-delegate-1", "test-only-delegate-2"});
42+
auto request = storage::internal::SignBlobRequest(
43+
"test-only-sa", std::move(b64encoded),
44+
{"test-only-delegate-1", "test-only-delegate-2"});
4645
auto const actual = ToProto(request);
4746
EXPECT_THAT(actual, IsProtoEqual(expected));
4847
}
@@ -56,12 +55,12 @@ TEST(GrpcSignBlobRequestParser, FromProto) {
5655
&input));
5756
auto response = FromProto(input);
5857
EXPECT_EQ(response.key_id, "test-only-key-id");
59-
EXPECT_EQ(response.signed_blob, Base64Encode("test-only-signed-blob"));
58+
EXPECT_EQ(response.signed_blob,
59+
storage::internal::Base64Encode("test-only-signed-blob"));
6060
}
6161

6262
} // namespace
63-
} // namespace internal
6463
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
65-
} // namespace storage
64+
} // namespace storage_internal
6665
} // namespace cloud
6766
} // namespace google

0 commit comments

Comments
 (0)