1 // Copyright 2019 Google LLC
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 // http://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 #include "google/cloud/storage/internal/sign_blob_requests.h"
16 #include "google/cloud/internal/absl_str_join_quiet.h"
17 #include <nlohmann/json.hpp>
18
19 namespace google {
20 namespace cloud {
21 namespace storage {
22 inline namespace STORAGE_CLIENT_NS {
23 namespace internal {
24
operator <<(std::ostream & os,SignBlobRequest const & r)25 std::ostream& operator<<(std::ostream& os, SignBlobRequest const& r) {
26 return os << "SignBlobRequest={service_account=" << r.service_account()
27 << ", base64_encoded_blob=" << r.base64_encoded_blob()
28 << ", delegates=" << absl::StrJoin(r.delegates(), ", ") << "}";
29 }
30
FromHttpResponse(std::string const & payload)31 StatusOr<SignBlobResponse> SignBlobResponse::FromHttpResponse(
32 std::string const& payload) {
33 auto json = nlohmann::json::parse(payload, nullptr, false);
34 if (!json.is_object()) {
35 return Status(StatusCode::kInvalidArgument, __func__);
36 }
37 SignBlobResponse result;
38 result.key_id = json.value("keyId", "");
39 result.signed_blob = json.value("signedBlob", "");
40 return result;
41 }
42
operator <<(std::ostream & os,SignBlobResponse const & r)43 std::ostream& operator<<(std::ostream& os, SignBlobResponse const& r) {
44 return os << "SignBlobResponse={key_id=" << r.key_id
45 << ", signed_blob=" << r.signed_blob << "}";
46 }
47
48 } // namespace internal
49 } // namespace STORAGE_CLIENT_NS
50 } // namespace storage
51 } // namespace cloud
52 } // namespace google
53