diff --git a/envoy/network/resolver.h b/envoy/network/resolver.h index 64e66bff32f8..dcdcfe8a8c92 100644 --- a/envoy/network/resolver.h +++ b/envoy/network/resolver.h @@ -24,9 +24,9 @@ class Resolver : public Config::UntypedFactory { /** * Resolve a custom address string and port to an Address::Instance. * @param socket_address supplies the socket address to resolve. - * @return InstanceConstSharedPtr appropriate Address::Instance or an error status. + * @return InstanceConstSharedPtr appropriate Address::Instance. */ - virtual absl::StatusOr + virtual InstanceConstSharedPtr resolve(const envoy::config::core::v3::SocketAddress& socket_address) PURE; std::string category() const override { return "envoy.resolvers"; } diff --git a/source/common/listener_manager/listener_impl.cc b/source/common/listener_manager/listener_impl.cc index 1c4034620a3f..984ebca0a7b9 100644 --- a/source/common/listener_manager/listener_impl.cc +++ b/source/common/listener_manager/listener_impl.cc @@ -223,9 +223,7 @@ std::string listenerStatsScope(const envoy::config::listener::v3::Listener& conf if (config.has_internal_listener()) { return absl::StrCat("envoy_internal_", config.name()); } - auto address_or_error = Network::Address::resolveProtoAddress(config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - return address_or_error.value()->asString(); + return Network::Address::resolveProtoAddress(config.address())->asString(); } } // namespace @@ -310,9 +308,7 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3::Listener& config, } else { // All the addresses should be same socket type, so get the first address's socket type is // enough. - auto address_or_error = Network::Address::resolveProtoAddress(config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - auto address = std::move(address_or_error.value()); + auto address = Network::Address::resolveProtoAddress(config.address()); checkIpv4CompatAddress(address, config.address()); addresses_.emplace_back(address); address_opts_list.emplace_back(std::ref(config.socket_options())); @@ -325,10 +321,8 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3::Listener& config, "support same socket type for all the addresses.", name_)); } - auto addresses_or_error = + auto additional_address = Network::Address::resolveProtoAddress(config.additional_addresses(i).address()); - THROW_IF_STATUS_NOT_OK(addresses_or_error, throw); - auto additional_address = std::move(addresses_or_error.value()); checkIpv4CompatAddress(address, config.additional_addresses(i).address()); addresses_.emplace_back(additional_address); if (config.additional_addresses(i).has_socket_options()) { diff --git a/source/common/listener_manager/listener_manager_impl.cc b/source/common/listener_manager/listener_manager_impl.cc index 853087d0b1bf..3982b72eed00 100644 --- a/source/common/listener_manager/listener_manager_impl.cc +++ b/source/common/listener_manager/listener_manager_impl.cc @@ -468,9 +468,7 @@ ListenerManagerImpl::addOrUpdateListener(const envoy::config::listener::v3::List name)); } if (!api_listener_ && !added_via_api) { - auto listener_or_error = HttpApiListener::create(config, server_, config.name()); - THROW_IF_STATUS_NOT_OK(listener_or_error, throw); - api_listener_ = std::move(listener_or_error.value()); + api_listener_ = std::make_unique(config, server_, config.name()); return true; } else { ENVOY_LOG(warn, "listener {} can not be added because currently only one ApiListener is " diff --git a/source/common/network/resolver_impl.cc b/source/common/network/resolver_impl.cc index 63119deff8ae..bd51bcfd2272 100644 --- a/source/common/network/resolver_impl.cc +++ b/source/common/network/resolver_impl.cc @@ -20,7 +20,7 @@ namespace Address { class IpResolver : public Resolver { public: - absl::StatusOr + InstanceConstSharedPtr resolve(const envoy::config::core::v3::SocketAddress& socket_address) override { switch (socket_address.port_specifier_case()) { case envoy::config::core::v3::SocketAddress::PortSpecifierCase::kPortValue: @@ -31,8 +31,8 @@ class IpResolver : public Resolver { case envoy::config::core::v3::SocketAddress::PortSpecifierCase::kNamedPort: break; } - return absl::InvalidArgumentError(fmt::format("IP resolver can't handle port specifier type {}", - socket_address.port_specifier_case())); + throwEnvoyExceptionOrPanic(fmt::format("IP resolver can't handle port specifier type {}", + socket_address.port_specifier_case())); } std::string name() const override { return Config::AddressResolverNames::get().IP; } @@ -43,8 +43,7 @@ class IpResolver : public Resolver { */ REGISTER_FACTORY(IpResolver, Resolver); -absl::StatusOr -resolveProtoAddress(const envoy::config::core::v3::Address& address) { +InstanceConstSharedPtr resolveProtoAddress(const envoy::config::core::v3::Address& address) { switch (address.address_case()) { case envoy::config::core::v3::Address::AddressCase::ADDRESS_NOT_SET: throwEnvoyExceptionOrPanic("Address must be set: " + address.DebugString()); @@ -67,7 +66,7 @@ resolveProtoAddress(const envoy::config::core::v3::Address& address) { throwEnvoyExceptionOrPanic("Failed to resolve address:" + address.DebugString()); } -absl::StatusOr +InstanceConstSharedPtr resolveProtoSocketAddress(const envoy::config::core::v3::SocketAddress& socket_address) { Resolver* resolver = nullptr; const std::string& resolver_name = socket_address.resolver_name(); @@ -80,9 +79,7 @@ resolveProtoSocketAddress(const envoy::config::core::v3::SocketAddress& socket_a if (resolver == nullptr) { throwEnvoyExceptionOrPanic(fmt::format("Unknown address resolver: {}", resolver_name)); } - auto instance_or_error = resolver->resolve(socket_address); - THROW_IF_STATUS_NOT_OK(instance_or_error, throw); - return std::move(instance_or_error.value()); + return resolver->resolve(socket_address); } } // namespace Address diff --git a/source/common/network/resolver_impl.h b/source/common/network/resolver_impl.h index f36c0f03b203..fb26085eb00d 100644 --- a/source/common/network/resolver_impl.h +++ b/source/common/network/resolver_impl.h @@ -14,17 +14,17 @@ namespace Address { /** * Create an Instance from a envoy::config::core::v3::Address. * @param address supplies the address proto to resolve. - * @return pointer to the Instance or an error status + * @return pointer to the Instance. */ -absl::StatusOr +Address::InstanceConstSharedPtr resolveProtoAddress(const envoy::config::core::v3::Address& address); /** * Create an Instance from a envoy::config::core::v3::SocketAddress. * @param address supplies the socket address proto to resolve. - * @return pointer to the Instance or an error status. + * @return pointer to the Instance. */ -absl::StatusOr +Address::InstanceConstSharedPtr resolveProtoSocketAddress(const envoy::config::core::v3::SocketAddress& address); DECLARE_FACTORY(IpResolver); diff --git a/source/common/upstream/health_discovery_service.cc b/source/common/upstream/health_discovery_service.cc index 4db99e3361d0..b1c659a5529f 100644 --- a/source/common/upstream/health_discovery_service.cc +++ b/source/common/upstream/health_discovery_service.cc @@ -371,11 +371,10 @@ HdsCluster::HdsCluster(Server::Configuration::ServerFactoryContext& server_conte for (const auto& host : locality_endpoints.lb_endpoints()) { const LocalityEndpointTuple endpoint_key = {locality_endpoints.locality(), host}; // Initialize an endpoint host object. - auto address_or_error = Network::Address::resolveProtoAddress(host.endpoint().address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); HostSharedPtr endpoint = std::make_shared( - info_, "", std::move(address_or_error.value()), nullptr, 1, locality_endpoints.locality(), - host.endpoint().health_check_config(), 0, envoy::config::core::v3::UNKNOWN, time_source_); + info_, "", Network::Address::resolveProtoAddress(host.endpoint().address()), nullptr, 1, + locality_endpoints.locality(), host.endpoint().health_check_config(), 0, + envoy::config::core::v3::UNKNOWN, time_source_); // Add this host/endpoint pointer to our flat list of endpoints for health checking. hosts_->push_back(endpoint); // Add this host/endpoint pointer to our structured list by locality so results can be @@ -484,13 +483,10 @@ void HdsCluster::updateHosts( host = host_pair->second; } else { // We do not have this endpoint saved, so create a new one. - auto address_or_error = - Network::Address::resolveProtoAddress(endpoint.endpoint().address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - host = std::make_shared(info_, "", std::move(address_or_error.value()), nullptr, - 1, endpoints.locality(), - endpoint.endpoint().health_check_config(), 0, - envoy::config::core::v3::UNKNOWN, time_source_); + host = std::make_shared( + info_, "", Network::Address::resolveProtoAddress(endpoint.endpoint().address()), + nullptr, 1, endpoints.locality(), endpoint.endpoint().health_check_config(), 0, + envoy::config::core::v3::UNKNOWN, time_source_); // Set the initial health status as in HdsCluster::initialize. host->healthFlagSet(Host::HealthFlag::FAILED_ACTIVE_HC); diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index 5c781c9bd70a..aa4e8fc849f9 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -227,14 +227,10 @@ parseBindConfig(::Envoy::OptRef bind_ std::vector<::Envoy::Upstream::UpstreamLocalAddress> upstream_local_addresses; if (bind_config.has_value()) { UpstreamLocalAddress upstream_local_address; - upstream_local_address.address_ = nullptr; - if (bind_config->has_source_address()) { - - auto address_or_error = - ::Envoy::Network::Address::resolveProtoSocketAddress(bind_config->source_address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - upstream_local_address.address_ = address_or_error.value(); - } + upstream_local_address.address_ = + bind_config->has_source_address() + ? ::Envoy::Network::Address::resolveProtoSocketAddress(bind_config->source_address()) + : nullptr; upstream_local_address.socket_options_ = std::make_shared(); ::Envoy::Network::Socket::appendOptions(upstream_local_address.socket_options_, @@ -246,10 +242,8 @@ parseBindConfig(::Envoy::OptRef bind_ for (const auto& extra_source_address : bind_config->extra_source_addresses()) { UpstreamLocalAddress extra_upstream_local_address; - auto address_or_error = + extra_upstream_local_address.address_ = ::Envoy::Network::Address::resolveProtoSocketAddress(extra_source_address.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - extra_upstream_local_address.address_ = address_or_error.value(); extra_upstream_local_address.socket_options_ = std::make_shared<::Envoy::Network::ConnectionSocket::Options>(); @@ -270,10 +264,8 @@ parseBindConfig(::Envoy::OptRef bind_ for (const auto& additional_source_address : bind_config->additional_source_addresses()) { UpstreamLocalAddress additional_upstream_local_address; - auto address_or_error = + additional_upstream_local_address.address_ = ::Envoy::Network::Address::resolveProtoSocketAddress(additional_source_address); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - additional_upstream_local_address.address_ = address_or_error.value(); additional_upstream_local_address.socket_options_ = std::make_shared<::Envoy::Network::ConnectionSocket::Options>(); ::Envoy::Network::Socket::appendOptions(additional_upstream_local_address.socket_options_, @@ -1749,11 +1741,7 @@ void ClusterImplBase::reloadHealthyHostsHelper(const HostSharedPtr&) { const Network::Address::InstanceConstSharedPtr ClusterImplBase::resolveProtoAddress(const envoy::config::core::v3::Address& address) { - TRY_ASSERT_MAIN_THREAD { - auto address_or_error = Network::Address::resolveProtoAddress(address); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - return address_or_error.value(); - } + TRY_ASSERT_MAIN_THREAD { return Network::Address::resolveProtoAddress(address); } END_TRY CATCH(EnvoyException & e, { if (info_->type() == envoy::config::cluster::v3::Cluster::STATIC || @@ -2421,9 +2409,7 @@ Network::Address::InstanceConstSharedPtr resolveHealthCheckAddress( Network::Address::InstanceConstSharedPtr health_check_address; const auto& port_value = health_check_config.port_value(); if (health_check_config.has_address()) { - auto address_or_error = Network::Address::resolveProtoAddress(health_check_config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - auto address = address_or_error.value(); + auto address = Network::Address::resolveProtoAddress(health_check_config.address()); health_check_address = port_value == 0 ? address : Network::Utility::getAddressWithPort(*address, port_value); } else { diff --git a/source/extensions/network/dns_resolver/cares/dns_impl.cc b/source/extensions/network/dns_resolver/cares/dns_impl.cc index 64848d6a4331..f1fec3b6bcc8 100644 --- a/source/extensions/network/dns_resolver/cares/dns_impl.cc +++ b/source/extensions/network/dns_resolver/cares/dns_impl.cc @@ -555,9 +555,7 @@ class CaresDnsResolverFactory : public DnsResolverFactory, const auto& resolver_addrs = cares.resolvers(); resolvers.reserve(resolver_addrs.size()); for (const auto& resolver_addr : resolver_addrs) { - auto address_or_error = Network::Address::resolveProtoAddress(resolver_addr); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - resolvers.push_back(std::move(address_or_error.value())); + resolvers.push_back(Network::Address::resolveProtoAddress(resolver_addr)); } } return std::make_shared(cares, dispatcher, resolvers, diff --git a/source/extensions/stat_sinks/dog_statsd/config.cc b/source/extensions/stat_sinks/dog_statsd/config.cc index 78c39f20d914..f3204bb322cb 100644 --- a/source/extensions/stat_sinks/dog_statsd/config.cc +++ b/source/extensions/stat_sinks/dog_statsd/config.cc @@ -22,9 +22,8 @@ DogStatsdSinkFactory::createStatsSink(const Protobuf::Message& config, const auto& sink_config = MessageUtil::downcastAndValidate( config, server.messageValidationContext().staticValidationVisitor()); - auto address_or_error = Network::Address::resolveProtoAddress(sink_config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - Network::Address::InstanceConstSharedPtr address = address_or_error.value(); + Network::Address::InstanceConstSharedPtr address = + Network::Address::resolveProtoAddress(sink_config.address()); ENVOY_LOG(debug, "dog_statsd UDP ip address: {}", address->asString()); absl::optional max_bytes; if (sink_config.has_max_bytes_per_datagram()) { diff --git a/source/extensions/stat_sinks/graphite_statsd/config.cc b/source/extensions/stat_sinks/graphite_statsd/config.cc index 93322442900d..7320993e035e 100644 --- a/source/extensions/stat_sinks/graphite_statsd/config.cc +++ b/source/extensions/stat_sinks/graphite_statsd/config.cc @@ -25,9 +25,8 @@ GraphiteStatsdSinkFactory::createStatsSink(const Protobuf::Message& config, switch (statsd_sink.statsd_specifier_case()) { case envoy::extensions::stat_sinks::graphite_statsd::v3::GraphiteStatsdSink::StatsdSpecifierCase:: kAddress: { - auto address_or_error = Network::Address::resolveProtoAddress(statsd_sink.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - Network::Address::InstanceConstSharedPtr address = address_or_error.value(); + Network::Address::InstanceConstSharedPtr address = + Network::Address::resolveProtoAddress(statsd_sink.address()); ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString()); absl::optional max_bytes; if (statsd_sink.has_max_bytes_per_datagram()) { diff --git a/source/extensions/stat_sinks/statsd/config.cc b/source/extensions/stat_sinks/statsd/config.cc index ae76707892a0..84670fa1308b 100644 --- a/source/extensions/stat_sinks/statsd/config.cc +++ b/source/extensions/stat_sinks/statsd/config.cc @@ -23,9 +23,8 @@ StatsdSinkFactory::createStatsSink(const Protobuf::Message& config, config, server.messageValidationContext().staticValidationVisitor()); switch (statsd_sink.statsd_specifier_case()) { case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::kAddress: { - auto address_or_error = Network::Address::resolveProtoAddress(statsd_sink.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - Network::Address::InstanceConstSharedPtr address = address_or_error.value(); + Network::Address::InstanceConstSharedPtr address = + Network::Address::resolveProtoAddress(statsd_sink.address()); ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString()); return std::make_unique(server.threadLocal(), std::move(address), false, statsd_sink.prefix()); diff --git a/source/server/api_listener_impl.cc b/source/server/api_listener_impl.cc index a9dfa065d89c..d947a0549c7a 100644 --- a/source/server/api_listener_impl.cc +++ b/source/server/api_listener_impl.cc @@ -13,10 +13,10 @@ namespace Envoy { namespace Server { -ApiListenerImplBase::ApiListenerImplBase(Network::Address::InstanceConstSharedPtr&& address, - const envoy::config::listener::v3::Listener& config, +ApiListenerImplBase::ApiListenerImplBase(const envoy::config::listener::v3::Listener& config, Server::Instance& server, const std::string& name) - : config_(config), name_(name), address_(std::move(address)), + : config_(config), name_(name), + address_(Network::Address::resolveProtoAddress(config.address())), factory_context_(server, *this, server.stats().createScope(""), server.stats().createScope(fmt::format("listener.api.{}.", name_)), std::make_shared(config)) {} @@ -41,19 +41,9 @@ HttpApiListener::ApiListenerWrapper::newStreamHandle(Http::ResponseEncoder& resp return http_connection_manager_->newStreamHandle(response_encoder, is_internally_created); } -absl::StatusOr> -HttpApiListener::create(const envoy::config::listener::v3::Listener& config, - Server::Instance& server, const std::string& name) { - auto address_or_error = Network::Address::resolveProtoAddress(config.address()); - RETURN_IF_STATUS_NOT_OK(address_or_error); - return std::unique_ptr( - new HttpApiListener(std::move(address_or_error.value()), config, server, name)); -} - -HttpApiListener::HttpApiListener(Network::Address::InstanceConstSharedPtr&& address, - const envoy::config::listener::v3::Listener& config, +HttpApiListener::HttpApiListener(const envoy::config::listener::v3::Listener& config, Server::Instance& server, const std::string& name) - : ApiListenerImplBase(std::move(address), config, server, name) { + : ApiListenerImplBase(config, server, name) { if (config.api_listener().api_listener().type_url() == absl::StrCat( "type.googleapis.com/", diff --git a/source/server/api_listener_impl.h b/source/server/api_listener_impl.h index 5ac8a3b7c07b..ccf1b2cbdcd3 100644 --- a/source/server/api_listener_impl.h +++ b/source/server/api_listener_impl.h @@ -49,8 +49,7 @@ class ApiListenerImplBase : public ApiListener, } protected: - ApiListenerImplBase(Network::Address::InstanceConstSharedPtr&& address, - const envoy::config::listener::v3::Listener& config, Server::Instance& server, + ApiListenerImplBase(const envoy::config::listener::v3::Listener& config, Server::Instance& server, const std::string& name); // Synthetic class that acts as a stub Network::ReadFilterCallbacks. @@ -222,18 +221,14 @@ class HttpApiListener : public ApiListenerImplBase { Http::ApiListenerPtr http_connection_manager_; }; + HttpApiListener(const envoy::config::listener::v3::Listener& config, Server::Instance& server, + const std::string& name); + // ApiListener ApiListener::Type type() const override { return ApiListener::Type::HttpApiListener; } Http::ApiListenerPtr createHttpApiListener(Event::Dispatcher& dispatcher) override; - static absl::StatusOr> - create(const envoy::config::listener::v3::Listener& config, Server::Instance& server, - const std::string& name); private: - HttpApiListener(Network::Address::InstanceConstSharedPtr&& address, - const envoy::config::listener::v3::Listener& config, Server::Instance& server, - const std::string& name); - // Need to store the factory due to the shared_ptrs that need to be kept alive: date provider, // route config manager, scoped route config manager. std::function diff --git a/source/server/configuration_impl.cc b/source/server/configuration_impl.cc index 6129c6182131..80818215be7b 100644 --- a/source/server/configuration_impl.cc +++ b/source/server/configuration_impl.cc @@ -231,9 +231,7 @@ InitialImpl::InitialImpl(const envoy::config::bootstrap::v3::Bootstrap& bootstra admin_.profile_path_ = admin.profile_path().empty() ? "/var/log/envoy/envoy.prof" : admin.profile_path(); if (admin.has_address()) { - auto address_or_error = Network::Address::resolveProtoAddress(admin.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); - admin_.address_ = std::move(address_or_error.value()); + admin_.address_ = Network::Address::resolveProtoAddress(admin.address()); } admin_.socket_options_ = std::make_shared>(); if (!admin.socket_options().empty()) { diff --git a/test/common/network/resolver_impl_test.cc b/test/common/network/resolver_impl_test.cc index 3574414e6298..22e752bd28ae 100644 --- a/test/common/network/resolver_impl_test.cc +++ b/test/common/network/resolver_impl_test.cc @@ -32,7 +32,7 @@ TEST_F(IpResolverTest, Basic) { envoy::config::core::v3::SocketAddress socket_address; socket_address.set_address("1.2.3.4"); socket_address.set_port_value(443); - auto address = resolver_->resolve(socket_address).value(); + auto address = resolver_->resolve(socket_address); EXPECT_EQ(address->ip()->addressAsString(), "1.2.3.4"); EXPECT_EQ(address->ip()->port(), 443); } @@ -41,25 +41,26 @@ TEST_F(IpResolverTest, DisallowsNamedPort) { envoy::config::core::v3::SocketAddress socket_address; socket_address.set_address("1.2.3.4"); socket_address.set_named_port("http"); - EXPECT_EQ(resolver_->resolve(socket_address).status().message(), - fmt::format("IP resolver can't handle port specifier type {}", - envoy::config::core::v3::SocketAddress::PortSpecifierCase::kNamedPort)); + EXPECT_THROW_WITH_MESSAGE( + resolver_->resolve(socket_address), EnvoyException, + fmt::format("IP resolver can't handle port specifier type {}", + envoy::config::core::v3::SocketAddress::PortSpecifierCase::kNamedPort)); } TEST(ResolverTest, FromProtoAddress) { envoy::config::core::v3::Address ipv4_address; ipv4_address.mutable_socket_address()->set_address("1.2.3.4"); ipv4_address.mutable_socket_address()->set_port_value(5); - EXPECT_EQ("1.2.3.4:5", resolveProtoAddress(ipv4_address).value()->asString()); + EXPECT_EQ("1.2.3.4:5", resolveProtoAddress(ipv4_address)->asString()); envoy::config::core::v3::Address ipv6_address; ipv6_address.mutable_socket_address()->set_address("1::1"); ipv6_address.mutable_socket_address()->set_port_value(2); - EXPECT_EQ("[1::1]:2", resolveProtoAddress(ipv6_address).value()->asString()); + EXPECT_EQ("[1::1]:2", resolveProtoAddress(ipv6_address)->asString()); envoy::config::core::v3::Address pipe_address; pipe_address.mutable_pipe()->set_path("/foo/bar"); - EXPECT_EQ("/foo/bar", resolveProtoAddress(pipe_address).value()->asString()); + EXPECT_EQ("/foo/bar", resolveProtoAddress(pipe_address)->asString()); } TEST(ResolverTest, InternalListenerNameFromProtoAddress) { @@ -67,14 +68,14 @@ TEST(ResolverTest, InternalListenerNameFromProtoAddress) { internal_listener_address.mutable_envoy_internal_address()->set_server_listener_name( "internal_listener_foo"); EXPECT_EQ("envoy://internal_listener_foo/", - resolveProtoAddress(internal_listener_address).value()->asString()); + resolveProtoAddress(internal_listener_address)->asString()); } TEST(ResolverTest, UninitializedInternalAddressFromProtoAddress) { envoy::config::core::v3::Address internal_address; internal_address.mutable_envoy_internal_address(); EXPECT_THROW_WITH_MESSAGE( - resolveProtoAddress(internal_address).IgnoreError(), EnvoyException, + resolveProtoAddress(internal_address), EnvoyException, fmt::format("Failed to resolve address:{}", internal_address.DebugString())); } @@ -84,7 +85,7 @@ TEST(ResolverTest, FromProtoAddressV4Compat) { envoy::config::core::v3::Address ipv6_address; ipv6_address.mutable_socket_address()->set_address("1::1"); ipv6_address.mutable_socket_address()->set_port_value(2); - auto resolved_addr = resolveProtoAddress(ipv6_address).value(); + auto resolved_addr = resolveProtoAddress(ipv6_address); EXPECT_EQ("[1::1]:2", resolved_addr->asString()); } { @@ -92,14 +93,14 @@ TEST(ResolverTest, FromProtoAddressV4Compat) { ipv6_address.mutable_socket_address()->set_address("1::1"); ipv6_address.mutable_socket_address()->set_port_value(2); ipv6_address.mutable_socket_address()->set_ipv4_compat(true); - auto resolved_addr = resolveProtoAddress(ipv6_address).value(); + auto resolved_addr = resolveProtoAddress(ipv6_address); EXPECT_EQ("[1::1]:2", resolved_addr->asString()); } } class TestResolver : public Resolver { public: - absl::StatusOr + InstanceConstSharedPtr resolve(const envoy::config::core::v3::SocketAddress& socket_address) override { const std::string& logical = socket_address.address(); const std::string physical = getPhysicalName(logical); @@ -153,7 +154,7 @@ TEST(ResolverTest, NonStandardResolver) { socket->set_address("foo"); socket->set_port_value(5); socket->set_resolver_name("envoy.test.resolver"); - auto instance = resolveProtoAddress(address).value(); + auto instance = resolveProtoAddress(address); EXPECT_EQ("1.2.3.4:5", instance->asString()); EXPECT_EQ("foo:5", instance->logicalName()); } @@ -163,7 +164,7 @@ TEST(ResolverTest, NonStandardResolver) { socket->set_address("bar"); socket->set_named_port("http"); socket->set_resolver_name("envoy.test.resolver"); - auto instance = resolveProtoAddress(address).value(); + auto instance = resolveProtoAddress(address); EXPECT_EQ("4.3.2.1:http", instance->asString()); EXPECT_EQ("bar:http", instance->logicalName()); } @@ -171,8 +172,7 @@ TEST(ResolverTest, NonStandardResolver) { TEST(ResolverTest, UninitializedAddress) { envoy::config::core::v3::Address address; - EXPECT_THROW_WITH_MESSAGE(resolveProtoAddress(address).IgnoreError(), EnvoyException, - "Address must be set: "); + EXPECT_THROW_WITH_MESSAGE(resolveProtoAddress(address), EnvoyException, "Address must be set: "); } TEST(ResolverTest, NoSuchResolver) { @@ -181,7 +181,7 @@ TEST(ResolverTest, NoSuchResolver) { socket->set_address("foo"); socket->set_port_value(5); socket->set_resolver_name("envoy.test.resolver"); - EXPECT_THROW_WITH_MESSAGE(resolveProtoAddress(address).IgnoreError(), EnvoyException, + EXPECT_THROW_WITH_MESSAGE(resolveProtoAddress(address), EnvoyException, "Unknown address resolver: envoy.test.resolver"); } diff --git a/test/fuzz/utility.h b/test/fuzz/utility.h index 681674debc4e..7ecd69d0942d 100644 --- a/test/fuzz/utility.h +++ b/test/fuzz/utility.h @@ -170,7 +170,7 @@ inline std::unique_ptr fromStreamInfo(const test::fuzz::StreamIn replaceInvalidHostCharacters( stream_info.address().envoy_internal_address().server_listener_name())); } else { - address = Envoy::Network::Address::resolveProtoAddress(stream_info.address()).value(); + address = Envoy::Network::Address::resolveProtoAddress(stream_info.address()); } } else { address = Network::Utility::resolveUrl("tcp://10.0.0.1:443"); @@ -178,7 +178,6 @@ inline std::unique_ptr fromStreamInfo(const test::fuzz::StreamIn auto upstream_local_address = stream_info.has_upstream_local_address() ? Envoy::Network::Address::resolveProtoAddress(stream_info.upstream_local_address()) - .value() : Network::Utility::resolveUrl("tcp://10.0.0.1:10000"); test_stream_info->upstreamInfo()->setUpstreamLocalAddress(upstream_local_address); test_stream_info->downstream_connection_info_provider_ = diff --git a/test/mocks/network/mocks.h b/test/mocks/network/mocks.h index 09417750b16b..283bb4377df7 100644 --- a/test/mocks/network/mocks.h +++ b/test/mocks/network/mocks.h @@ -88,7 +88,7 @@ class MockAddressResolver : public Address::Resolver { MockAddressResolver(); ~MockAddressResolver() override; - MOCK_METHOD(absl::StatusOr, resolve, + MOCK_METHOD(Address::InstanceConstSharedPtr, resolve, (const envoy::config::core::v3::SocketAddress&)); MOCK_METHOD(std::string, name, (), (const)); }; diff --git a/test/server/api_listener_test.cc b/test/server/api_listener_test.cc index 9d70fbd6e4e3..7183f80b8651 100644 --- a/test/server/api_listener_test.cc +++ b/test/server/api_listener_test.cc @@ -53,11 +53,11 @@ name: test_api_listener const envoy::config::listener::v3::Listener config = parseListenerFromV3Yaml(yaml); server_.server_factory_context_->cluster_manager_.initializeClusters( {"dynamic_forward_proxy_cluster"}, {}); - auto http_api_listener = HttpApiListener::create(config, server_, config.name()).value(); + auto http_api_listener = HttpApiListener(config, server_, config.name()); - ASSERT_EQ("test_api_listener", http_api_listener->name()); - ASSERT_EQ(ApiListener::Type::HttpApiListener, http_api_listener->type()); - ASSERT_NE(http_api_listener->createHttpApiListener(server_.dispatcher()), nullptr); + ASSERT_EQ("test_api_listener", http_api_listener.name()); + ASSERT_EQ(ApiListener::Type::HttpApiListener, http_api_listener.type()); + ASSERT_NE(http_api_listener.createHttpApiListener(server_.dispatcher()), nullptr); } TEST_F(ApiListenerTest, MobileApiListener) { @@ -88,11 +88,11 @@ name: test_api_listener const envoy::config::listener::v3::Listener config = parseListenerFromV3Yaml(yaml); server_.server_factory_context_->cluster_manager_.initializeClusters( {"dynamic_forward_proxy_cluster"}, {}); - auto http_api_listener = HttpApiListener::create(config, server_, config.name()).value(); + auto http_api_listener = HttpApiListener(config, server_, config.name()); - ASSERT_EQ("test_api_listener", http_api_listener->name()); - ASSERT_EQ(ApiListener::Type::HttpApiListener, http_api_listener->type()); - ASSERT_NE(http_api_listener->createHttpApiListener(server_.dispatcher()), nullptr); + ASSERT_EQ("test_api_listener", http_api_listener.name()); + ASSERT_EQ(ApiListener::Type::HttpApiListener, http_api_listener.type()); + ASSERT_NE(http_api_listener.createHttpApiListener(server_.dispatcher()), nullptr); } TEST_F(ApiListenerTest, HttpApiListenerThrowsWithBadConfig) { @@ -125,7 +125,7 @@ name: test_api_listener ->set_path("eds path"); expected_any_proto.PackFrom(expected_cluster_proto); EXPECT_THROW_WITH_MESSAGE( - HttpApiListener::create(config, server_, config.name()).IgnoreError(), EnvoyException, + HttpApiListener(config, server_, config.name()), EnvoyException, fmt::format("Unable to unpack as " "envoy.extensions.filters.network.http_connection_manager.v3." "HttpConnectionManager: {}", @@ -159,11 +159,11 @@ name: test_api_listener const envoy::config::listener::v3::Listener config = parseListenerFromV3Yaml(yaml); server_.server_factory_context_->cluster_manager_.initializeClusters( {"dynamic_forward_proxy_cluster"}, {}); - auto http_api_listener = HttpApiListener::create(config, server_, config.name()).value(); + auto http_api_listener = HttpApiListener(config, server_, config.name()); - ASSERT_EQ("test_api_listener", http_api_listener->name()); - ASSERT_EQ(ApiListener::Type::HttpApiListener, http_api_listener->type()); - auto api_listener = http_api_listener->createHttpApiListener(server_.dispatcher()); + ASSERT_EQ("test_api_listener", http_api_listener.name()); + ASSERT_EQ(ApiListener::Type::HttpApiListener, http_api_listener.type()); + auto api_listener = http_api_listener.createHttpApiListener(server_.dispatcher()); ASSERT_NE(api_listener, nullptr); Network::MockConnectionCallbacks network_connection_callbacks; diff --git a/tools/code_format/config.yaml b/tools/code_format/config.yaml index 1e1b071c2d19..c7e1dc6bd7c9 100644 --- a/tools/code_format/config.yaml +++ b/tools/code_format/config.yaml @@ -109,6 +109,7 @@ paths: - source/common/network/address_impl.cc - source/common/network/utility.cc - source/common/network/dns_resolver/dns_factory_util.cc + - source/common/network/resolver_impl.cc - source/common/network/socket_impl.cc - source/common/ssl/tls_certificate_config_impl.cc - source/common/formatter/http_specific_formatter.cc