Skip to content

Commit e0ea277

Browse files
authored
Allow npipe protocol in DefaultDockerClientConfig (docker-java#1325)
Fixes docker-java#1324
1 parent b4ce5ae commit e0ea277

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ public class DefaultDockerClientConfig implements Serializable, DockerClientConf
9898
}
9999

100100
private URI checkDockerHostScheme(URI dockerHost) {
101-
if ("tcp".equals(dockerHost.getScheme()) || "unix".equals(dockerHost.getScheme())) {
102-
return dockerHost;
103-
} else {
104-
throw new DockerClientException("Unsupported protocol scheme found: '" + dockerHost
105-
+ "'. Only 'tcp://' or 'unix://' supported.");
101+
switch (dockerHost.getScheme()) {
102+
case "tcp":
103+
case "unix":
104+
case "npipe":
105+
return dockerHost;
106+
default:
107+
throw new DockerClientException("Unsupported protocol scheme found: '" + dockerHost);
106108
}
107109
}
108110

docker-java-transport-jersey/src/main/java/com/github/dockerjava/jaxrs/JerseyDockerCmdExecFactory.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,20 @@ public void init(DockerClientConfig dockerClientConfig) {
139139
protocol = "http";
140140
}
141141

142-
if (!originalUri.getScheme().equals("unix")) {
143-
144-
try {
145-
originalUri = new URI(originalUri.toString().replaceFirst("tcp", protocol));
146-
} catch (URISyntaxException e) {
147-
throw new RuntimeException(e);
148-
}
142+
switch (originalUri.getScheme()) {
143+
case "unix":
144+
break;
145+
case "tcp":
146+
try {
147+
originalUri = new URI(originalUri.toString().replaceFirst("tcp", protocol));
148+
} catch (URISyntaxException e) {
149+
throw new RuntimeException(e);
150+
}
149151

150-
configureProxy(clientConfig, originalUri, protocol);
152+
configureProxy(clientConfig, originalUri, protocol);
153+
break;
154+
default:
155+
throw new IllegalArgumentException("Unsupported protocol scheme: " + originalUri);
151156
}
152157

153158
connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry(

docker-java-transport-netty/src/main/java/com/github/dockerjava/netty/NettyDockerCmdExecFactory.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,18 @@ public void init(DockerClientConfig dockerClientConfig) {
101101
String scheme = dockerClientConfig.getDockerHost().getScheme();
102102
String host = "";
103103

104-
if ("unix".equals(scheme)) {
105-
nettyInitializer = new UnixDomainSocketInitializer();
106-
host = "DUMMY";
107-
} else if ("tcp".equals(scheme)) {
108-
nettyInitializer = new InetSocketInitializer();
109-
host = dockerClientConfig.getDockerHost().getHost() + ":"
110-
+ Integer.toString(dockerClientConfig.getDockerHost().getPort());
104+
switch (scheme) {
105+
case "unix":
106+
nettyInitializer = new UnixDomainSocketInitializer();
107+
host = "DUMMY";
108+
break;
109+
case "tcp":
110+
nettyInitializer = new InetSocketInitializer();
111+
host = dockerClientConfig.getDockerHost().getHost() + ":"
112+
+ Integer.toString(dockerClientConfig.getDockerHost().getPort());
113+
break;
114+
default:
115+
throw new IllegalArgumentException("Unsupported protocol scheme: " + dockerClientConfig.getDockerHost());
111116
}
112117

113118
eventLoopGroup = nettyInitializer.init(bootstrap, dockerClientConfig);

docker-java/src/test/java/com/github/dockerjava/core/DefaultDockerClientConfigTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ public void testUnixHostScheme() throws Exception {
177177
null);
178178
}
179179

180+
@Test()
181+
public void testNpipeHostScheme() throws Exception {
182+
new DefaultDockerClientConfig(URI.create("npipe://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
183+
null);
184+
}
185+
180186
@Test
181187
public void withDockerTlsVerify() throws Exception {
182188
DefaultDockerClientConfig.Builder builder = new DefaultDockerClientConfig.Builder();

0 commit comments

Comments
 (0)