Remove hostname from NetworkAddress.format (x-plugins side)

This removes the old usage of NetworkAddress.formatAddress in favor of the updated version, which is just
the method renamed to NetworkAddress.format (replacing the old version of that method).

There is no impact to x-plugins beyond making the build work because all places were currently using that
method variant already.

Original commit: elastic/x-pack-elasticsearch@05f0dcfa90
This commit is contained in:
Chris Earle 2016-04-07 14:03:46 -04:00
parent 52b6fc54b8
commit daa875db11
8 changed files with 27 additions and 27 deletions

View File

@ -51,7 +51,7 @@ public class WatcherWithShieldIT extends ESRestTestCase {
public void startWatcher() throws Exception {
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
InetSocketAddress address = cluster().httpAddresses()[0];
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.formatAddress(address.getAddress()), address.getPort(), "/_watcher/_start", null, null));
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.format(address.getAddress()), address.getPort(), "/_watcher/_start", null, null));
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray()));
request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token);
client.execute(request);
@ -62,7 +62,7 @@ public class WatcherWithShieldIT extends ESRestTestCase {
public void stopWatcher() throws Exception {
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
InetSocketAddress address = cluster().httpAddresses()[0];
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.formatAddress(address.getAddress()), address.getPort(), "/_watcher/_stop", null, null));
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.format(address.getAddress()), address.getPort(), "/_watcher/_stop", null, null));
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray()));
request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token);
client.execute(request);

View File

@ -610,7 +610,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
msg.builder.field(Field.ORIGIN_TYPE, "rest");
SocketAddress address = request.getRemoteAddress();
if (address instanceof InetSocketAddress) {
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.formatAddress(((InetSocketAddress) request.getRemoteAddress())
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.format(((InetSocketAddress) request.getRemoteAddress())
.getAddress()));
} else {
msg.builder.field(Field.ORIGIN_ADDRESS, address);
@ -626,7 +626,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
Message msg = new Message().start();
common(layer, type, msg.builder);
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.formatAddress(originAddress));
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.format(originAddress));
msg.builder.field(Field.TRANSPORT_PROFILE, profile);
msg.builder.field(Field.RULE, rule);
@ -649,7 +649,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
if (restAddress != null) {
builder.field(Field.ORIGIN_TYPE, "rest");
builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.formatAddress(restAddress.getAddress()));
builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.format(restAddress.getAddress()));
return builder;
}
@ -659,7 +659,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
builder.field(Field.ORIGIN_TYPE, "transport");
if (address instanceof InetSocketTransportAddress) {
builder.field(Field.ORIGIN_ADDRESS,
NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress()));
NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()));
} else {
builder.field(Field.ORIGIN_ADDRESS, address);
}

View File

@ -339,14 +339,14 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
public void connectionGranted(InetAddress inetAddress, String profile, ShieldIpFilterRule rule) {
if (logger.isTraceEnabled()) {
logger.trace("{}[ip_filter] [connection_granted]\torigin_address=[{}], transport_profile=[{}], rule=[{}]", prefix,
NetworkAddress.formatAddress(inetAddress), profile, rule);
NetworkAddress.format(inetAddress), profile, rule);
}
}
@Override
public void connectionDenied(InetAddress inetAddress, String profile, ShieldIpFilterRule rule) {
logger.error("{}[ip_filter] [connection_denied]\torigin_address=[{}], transport_profile=[{}], rule=[{}]", prefix,
NetworkAddress.formatAddress(inetAddress), profile, rule);
NetworkAddress.format(inetAddress), profile, rule);
}
@Override
@ -377,7 +377,7 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
String formattedAddress;
SocketAddress socketAddress = request.getRemoteAddress();
if (socketAddress instanceof InetSocketAddress) {
formattedAddress = NetworkAddress.formatAddress(((InetSocketAddress) socketAddress).getAddress());
formattedAddress = NetworkAddress.format(((InetSocketAddress) socketAddress).getAddress());
} else {
formattedAddress = socketAddress.toString();
}
@ -391,7 +391,7 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
if (restAddress != null) {
builder.append("origin_type=[rest], origin_address=[").
append(NetworkAddress.formatAddress(restAddress.getAddress())).
append(NetworkAddress.format(restAddress.getAddress())).
append("]");
return builder.toString();
}
@ -402,7 +402,7 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
builder.append("origin_type=[transport], ");
if (address instanceof InetSocketTransportAddress) {
builder.append("origin_address=[").
append(NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress())).
append(NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress())).
append("]");
} else {
builder.append("origin_address=[").append(address).append("]");

View File

@ -155,7 +155,7 @@ public class ShieldIpFilterRule implements IpFilterRule {
}
assert transportAddress instanceof InetSocketTransportAddress;
ruleSpec.append(NetworkAddress.formatAddress(((InetSocketTransportAddress) transportAddress).address().getAddress()));
ruleSpec.append(NetworkAddress.format(((InetSocketTransportAddress) transportAddress).address().getAddress()));
}
return ruleSpec.toString();
}

View File

@ -178,7 +178,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase {
Settings.Builder builder = Settings.builder()
.put(settings)
.put(XPackPlugin.featureEnabledSetting(Security.NAME), useShield)
.put(remoteSettings(NetworkAddress.formatAddress(inet.address().getAddress()), inet.address().getPort(), cluster2Name))
.put(remoteSettings(NetworkAddress.format(inet.address().getAddress()), inet.address().getPort(), cluster2Name))
.put("xpack.security.audit.index.client." + Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD);
if (useSSL) {
@ -264,7 +264,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase {
assertAuditMessage(hit, "rest", "anonymous_access_denied");
Map<String, Object> sourceMap = hit.sourceAsMap();
assertThat(NetworkAddress.formatAddress(InetAddress.getLoopbackAddress()), equalTo(sourceMap.get("origin_address")));
assertThat(NetworkAddress.format(InetAddress.getLoopbackAddress()), equalTo(sourceMap.get("origin_address")));
assertThat("_uri", equalTo(sourceMap.get("uri")));
assertThat(sourceMap.get("origin_type"), is("rest"));
assertThat(sourceMap.get("request_body"), notNullValue());

View File

@ -173,12 +173,12 @@ public class LoggingAuditTrailTests extends ESTestCase {
case WARN:
case INFO:
assertMsg(logger, Level.WARN, prefix + "[rest] [anonymous_access_denied]\torigin_address=[" +
NetworkAddress.formatAddress(address) + "], uri=[_uri]");
NetworkAddress.format(address) + "], uri=[_uri]");
break;
case DEBUG:
case TRACE:
assertMsg(logger, Level.DEBUG, prefix + "[rest] [anonymous_access_denied]\torigin_address=[" +
NetworkAddress.formatAddress(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
NetworkAddress.format(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
}
}
}
@ -265,12 +265,12 @@ public class LoggingAuditTrailTests extends ESTestCase {
case WARN:
case INFO:
assertMsg(logger, Level.ERROR, prefix + "[rest] [authentication_failed]\torigin_address=[" +
NetworkAddress.formatAddress(address) + "], principal=[_principal], uri=[_uri]");
NetworkAddress.format(address) + "], principal=[_principal], uri=[_uri]");
break;
case DEBUG:
case TRACE:
assertMsg(logger, Level.DEBUG, prefix + "[rest] [authentication_failed]\torigin_address=[" +
NetworkAddress.formatAddress(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
NetworkAddress.format(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
expectedMessage + "]");
}
}
@ -292,12 +292,12 @@ public class LoggingAuditTrailTests extends ESTestCase {
case WARN:
case INFO:
assertMsg(logger, Level.ERROR, prefix + "[rest] [authentication_failed]\torigin_address=[" +
NetworkAddress.formatAddress(address) + "], uri=[_uri]");
NetworkAddress.format(address) + "], uri=[_uri]");
break;
case DEBUG:
case TRACE:
assertMsg(logger, Level.DEBUG, prefix + "[rest] [authentication_failed]\torigin_address=[" +
NetworkAddress.formatAddress(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
NetworkAddress.format(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
}
}
}
@ -349,7 +349,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
break;
case TRACE:
assertMsg(logger, Level.TRACE, prefix + "[rest] [authentication_failed]\trealm=[_realm], origin_address=[" +
NetworkAddress.formatAddress(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
NetworkAddress.format(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
expectedMessage + "]");
}
}
@ -600,7 +600,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
case ERROR:
assertMsg(logger, Level.ERROR, String.format(Locale.ROOT, prefix +
"[ip_filter] [connection_denied]\torigin_address=[%s], transport_profile=[%s], rule=[deny %s]",
NetworkAddress.formatAddress(inetAddress), "default", "_all"));
NetworkAddress.format(inetAddress), "default", "_all"));
break;
case WARN:
case INFO:
@ -628,7 +628,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
case TRACE:
assertMsg(logger, Level.TRACE, String.format(Locale.ROOT, prefix + "[ip_filter] " +
"[connection_granted]\torigin_address=[%s], transport_profile=[default], rule=[allow default:accept_all]",
NetworkAddress.formatAddress(inetAddress)));
NetworkAddress.format(inetAddress)));
}
}
}
@ -692,7 +692,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
if (restAddress != null) {
assertThat(text, equalTo("origin_type=[rest], origin_address=[" +
NetworkAddress.formatAddress(restAddress.getAddress()) + "]"));
NetworkAddress.format(restAddress.getAddress()) + "]"));
return;
}
TransportAddress address = message.remoteAddress();
@ -704,7 +704,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
if (address instanceof InetSocketTransportAddress) {
assertThat(text, equalTo("origin_type=[transport], origin_address=[" +
NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress()) + "]"));
NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()) + "]"));
} else {
assertThat(text, equalTo("origin_type=[transport], origin_address=[" + address + "]"));
}

View File

@ -90,7 +90,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
TransportAddress transportAddress = transport.boundAddress().publishAddress();
assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class));
InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address();
String unicastHost = NetworkAddress.formatAddress(inetSocketAddress);
String unicastHost = NetworkAddress.format(inetSocketAddress);
// test that starting up a node works
Settings nodeSettings = settingsBuilder()

View File

@ -194,7 +194,7 @@ public class IPFilterTests extends ESTestCase {
public void testThatBoundAddressIsNeverRejected() throws Exception {
List<String> addressStrings = new ArrayList<>();
for (TransportAddress address : transport.boundAddress().boundAddresses()) {
addressStrings.add(NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress()));
addressStrings.add(NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()));
}
Settings settings;