|
| 1 | +// Copyright 2025 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 | +// https://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/bucket_ip_filter.h" |
| 16 | +#include "google/cloud/internal/ios_flags_saver.h" |
| 17 | +#include <iostream> |
| 18 | + |
| 19 | +namespace google { |
| 20 | +namespace cloud { |
| 21 | +namespace storage { |
| 22 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
| 23 | + |
| 24 | +bool operator==(BucketIpFilterPublicNetworkSource const& lhs, |
| 25 | + BucketIpFilterPublicNetworkSource const& rhs) { |
| 26 | + return lhs.allowed_ip_cidr_ranges == rhs.allowed_ip_cidr_ranges; |
| 27 | +} |
| 28 | + |
| 29 | +bool operator!=(BucketIpFilterPublicNetworkSource const& lhs, |
| 30 | + BucketIpFilterPublicNetworkSource const& rhs) { |
| 31 | + return !(lhs == rhs); |
| 32 | +} |
| 33 | + |
| 34 | +std::ostream& operator<<(std::ostream& os, |
| 35 | + BucketIpFilterPublicNetworkSource const& rhs) { |
| 36 | + os << "BucketIpFilterPublicNetworkSource={allowed_ip_cidr_ranges=["; |
| 37 | + char const* sep = ""; |
| 38 | + for (auto const& r : rhs.allowed_ip_cidr_ranges) { |
| 39 | + os << sep << r; |
| 40 | + sep = ", "; |
| 41 | + } |
| 42 | + return os << "]}"; |
| 43 | +} |
| 44 | + |
| 45 | +bool operator==(BucketIpFilterVpcNetworkSource const& lhs, |
| 46 | + BucketIpFilterVpcNetworkSource const& rhs) { |
| 47 | + return std::tie(lhs.network, lhs.allowed_ip_cidr_ranges) == |
| 48 | + std::tie(rhs.network, rhs.allowed_ip_cidr_ranges); |
| 49 | +} |
| 50 | + |
| 51 | +bool operator!=(BucketIpFilterVpcNetworkSource const& lhs, |
| 52 | + BucketIpFilterVpcNetworkSource const& rhs) { |
| 53 | + return !(lhs == rhs); |
| 54 | +} |
| 55 | + |
| 56 | +std::ostream& operator<<(std::ostream& os, |
| 57 | + BucketIpFilterVpcNetworkSource const& rhs) { |
| 58 | + os << "BucketIpFilterVpcNetworkSource={network=" << rhs.network |
| 59 | + << ", allowed_ip_cidr_ranges=["; |
| 60 | + char const* sep = ""; |
| 61 | + for (auto const& r : rhs.allowed_ip_cidr_ranges) { |
| 62 | + os << sep << r; |
| 63 | + sep = ", "; |
| 64 | + } |
| 65 | + return os << "]}"; |
| 66 | +} |
| 67 | + |
| 68 | +bool operator==(BucketIpFilter const& lhs, BucketIpFilter const& rhs) { |
| 69 | + return std::tie(lhs.allow_all_service_agent_access, lhs.allow_cross_org_vpcs, |
| 70 | + lhs.mode, lhs.public_network_source, |
| 71 | + lhs.vpc_network_sources) == |
| 72 | + std::tie(rhs.allow_all_service_agent_access, rhs.allow_cross_org_vpcs, |
| 73 | + rhs.mode, rhs.public_network_source, rhs.vpc_network_sources); |
| 74 | +} |
| 75 | + |
| 76 | +bool operator!=(BucketIpFilter const& lhs, BucketIpFilter const& rhs) { |
| 77 | + return !(lhs == rhs); |
| 78 | +} |
| 79 | + |
| 80 | +std::ostream& operator<<(std::ostream& os, BucketIpFilter const& rhs) { |
| 81 | + google::cloud::internal::IosFlagsSaver save_format(os); |
| 82 | + os << "BucketIpFilter={"; |
| 83 | + os << "mode=" << rhs.mode.value_or("") << ", "; |
| 84 | + if (rhs.allow_all_service_agent_access) { |
| 85 | + os << "allow_all_service_agent_access=" << std::boolalpha |
| 86 | + << *rhs.allow_all_service_agent_access << ", "; |
| 87 | + } |
| 88 | + if (rhs.allow_cross_org_vpcs) { |
| 89 | + os << "allow_cross_org_vpcs=" << std::boolalpha << *rhs.allow_cross_org_vpcs |
| 90 | + << ", "; |
| 91 | + } |
| 92 | + if (rhs.public_network_source) { |
| 93 | + os << "public_network_source=" << *rhs.public_network_source << ", "; |
| 94 | + } |
| 95 | + if (rhs.vpc_network_sources) { |
| 96 | + os << "vpc_network_sources=["; |
| 97 | + char const* sep = ""; |
| 98 | + for (auto const& r : *rhs.vpc_network_sources) { |
| 99 | + os << sep << r; |
| 100 | + sep = ", "; |
| 101 | + } |
| 102 | + os << "]"; |
| 103 | + } |
| 104 | + return os << "}"; |
| 105 | +} |
| 106 | + |
| 107 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
| 108 | +} // namespace storage |
| 109 | +} // namespace cloud |
| 110 | +} // namespace google |
0 commit comments