Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
760f9030
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
760f9030
编写于
12月 19, 2011
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CLI now supports using HTTP proxy for tunneling its TCP/IP connection
上级
721111b1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
81 addition
and
4 deletion
+81
-4
changelog.html
changelog.html
+2
-0
cli/src/main/java/hudson/cli/CLI.java
cli/src/main/java/hudson/cli/CLI.java
+76
-3
cli/src/main/resources/hudson/cli/client/Messages.properties
cli/src/main/resources/hudson/cli/client/Messages.properties
+3
-1
未找到文件。
changelog.html
浏览文件 @
760f9030
...
...
@@ -55,6 +55,8 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div
id=
"trunk"
style=
"display:none"
>
<!--=TRUNK-BEGIN=-->
<ul
class=
image
>
<li
class=
rfe
>
CLI now supports using HTTP proxy for tunneling its TCP/IP connection.
<li
class=
rfe
>
CLI now supports routing TCP/IP requests without going through HTTP reverse proxy.
<li
class=
rfe
>
...
...
cli/src/main/java/hudson/cli/CLI.java
浏览文件 @
760f9030
...
...
@@ -35,8 +35,10 @@ import hudson.remoting.SocketOutputStream;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.Closeable
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.File
;
...
...
@@ -44,9 +46,14 @@ import java.io.FileInputStream;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.io.StringReader
;
import
java.net.HttpURLConnection
;
import
java.net.InetSocketAddress
;
import
java.net.Proxy
;
import
java.net.ProxySelector
;
import
java.net.Socket
;
import
java.net.URI
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.security.GeneralSecurityException
;
...
...
@@ -63,6 +70,7 @@ import java.util.Locale;
import
java.util.Properties
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.logging.ConsoleHandler
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
...
...
@@ -78,17 +86,30 @@ public class CLI {
private
final
Channel
channel
;
private
final
CliEntryPoint
entryPoint
;
private
final
boolean
ownsPool
;
private
final
List
<
Closeable
>
closables
=
new
ArrayList
<
Closeable
>();
// stuff to close in the close method
private
final
String
httpsProxyTunnel
;
public
CLI
(
URL
jenkins
)
throws
IOException
,
InterruptedException
{
this
(
jenkins
,
null
);
}
public
CLI
(
URL
jenkins
,
ExecutorService
exec
)
throws
IOException
,
InterruptedException
{
this
(
jenkins
,
exec
,
null
);
}
/**
*
* @param httpsProxyTunnel
* Configures the HTTP proxy that we use for making a plain TCP/IP connection.
* "host:port" that points to an HTTP proxy or null.
*/
public
CLI
(
URL
jenkins
,
ExecutorService
exec
,
String
httpsProxyTunnel
)
throws
IOException
,
InterruptedException
{
String
url
=
jenkins
.
toExternalForm
();
if
(!
url
.
endsWith
(
"/"
))
url
+=
'/'
;
ownsPool
=
exec
==
null
;
pool
=
exec
!=
null
?
exec
:
Executors
.
newCachedThreadPool
();
this
.
httpsProxyTunnel
=
httpsProxyTunnel
;
Channel
channel
=
null
;
InetSocketAddress
clip
=
getCliTcpPort
(
url
);
...
...
@@ -132,13 +153,51 @@ public class CLI {
private
Channel
connectViaCliPort
(
URL
jenkins
,
InetSocketAddress
endpoint
)
throws
IOException
{
LOGGER
.
fine
(
"Trying to connect directly via TCP/IP to "
+
endpoint
);
Socket
s
=
new
Socket
(
endpoint
.
getHostName
(),
endpoint
.
getPort
());
final
Socket
s
;
OutputStream
out
;
if
(
httpsProxyTunnel
!=
null
)
{
String
[]
tokens
=
httpsProxyTunnel
.
split
(
":"
);
s
=
new
Socket
(
tokens
[
0
],
Integer
.
parseInt
(
tokens
[
1
]));
PrintStream
o
=
new
PrintStream
(
s
.
getOutputStream
());
o
.
print
(
"CONNECT "
+
endpoint
.
getHostName
()
+
":"
+
endpoint
.
getPort
()
+
" HTTP/1.0\r\n\r\n"
);
// read the response from the proxy
ByteArrayOutputStream
rsp
=
new
ByteArrayOutputStream
();
while
(!
rsp
.
toString
().
endsWith
(
"\r\n\r\n"
))
{
int
ch
=
s
.
getInputStream
().
read
();
if
(
ch
<
0
)
throw
new
IOException
(
"Failed to read the HTTP proxy response: "
+
rsp
);
rsp
.
write
(
ch
);
}
String
head
=
new
BufferedReader
(
new
StringReader
(
rsp
.
toString
())).
readLine
();
if
(!
head
.
startsWith
(
"HTTP/1.0 200 "
))
throw
new
IOException
(
"Failed to establish a connection through HTTP proxy: "
+
rsp
);
// HTTP proxies (at least the one I tried --- squid) doesn't seem to do half-close very well.
// So instead of relying on it, we'll just send the close command and then let the server
// cut their side, then close the socket after the join.
closables
.
add
(
new
Closeable
()
{
public
void
close
()
throws
IOException
{
s
.
close
();
}
});
out
=
new
SocketOutputStream
(
s
)
{
@Override
public
void
close
()
throws
IOException
{
// ignore
}
};
}
else
{
s
=
new
Socket
(
endpoint
.
getHostName
(),
endpoint
.
getPort
());
out
=
new
SocketOutputStream
(
s
);
}
DataOutputStream
dos
=
new
DataOutputStream
(
s
.
getOutputStream
());
dos
.
writeUTF
(
"Protocol:CLI-connect"
);
return
new
Channel
(
"CLI connection to "
+
jenkins
,
pool
,
new
BufferedInputStream
(
new
SocketInputStream
(
s
)),
new
BufferedOutputStream
(
new
SocketOutputStream
(
s
)
));
new
BufferedOutputStream
(
out
));
}
/**
...
...
@@ -196,6 +255,8 @@ public class CLI {
channel
.
join
();
if
(
ownsPool
)
pool
.
shutdown
();
for
(
Closeable
c
:
closables
)
c
.
close
();
}
public
int
execute
(
List
<
String
>
args
,
InputStream
stdin
,
OutputStream
stdout
,
OutputStream
stderr
)
{
...
...
@@ -244,6 +305,12 @@ public class CLI {
}
public
static
void
main
(
final
String
[]
_args
)
throws
Exception
{
// Logger l = Logger.getLogger(Channel.class.getName());
// l.setLevel(ALL);
// ConsoleHandler h = new ConsoleHandler();
// h.setLevel(ALL);
// l.addHandler(h);
//
System
.
exit
(
_main
(
_args
));
}
...
...
@@ -251,6 +318,7 @@ public class CLI {
List
<
String
>
args
=
Arrays
.
asList
(
_args
);
List
<
KeyPair
>
candidateKeys
=
new
ArrayList
<
KeyPair
>();
boolean
sshAuthRequestedExplicitly
=
false
;
String
httpProxy
=
null
;
String
url
=
System
.
getenv
(
"JENKINS_URL"
);
...
...
@@ -285,6 +353,11 @@ public class CLI {
sshAuthRequestedExplicitly
=
true
;
continue
;
}
if
(
head
.
equals
(
"-p"
)
&&
args
.
size
()>=
2
)
{
httpProxy
=
args
.
get
(
1
);
args
=
args
.
subList
(
2
,
args
.
size
());
continue
;
}
break
;
}
...
...
@@ -299,7 +372,7 @@ public class CLI {
if
(
candidateKeys
.
isEmpty
())
addDefaultPrivateKeyLocations
(
candidateKeys
);
CLI
cli
=
new
CLI
(
new
URL
(
url
));
CLI
cli
=
new
CLI
(
new
URL
(
url
)
,
null
,
httpProxy
);
try
{
if
(!
candidateKeys
.
isEmpty
())
{
try
{
...
...
cli/src/main/resources/hudson/cli/client/Messages.properties
浏览文件 @
760f9030
CLI.Usage
=
Jenkins CLI
\n\
Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...
\n\
Options:
\n\
\
-s URL : specify the server URL (defaults to the JENKINS_URL env var)
\n\
\
-s URL : the server URL (defaults to the JENKINS_URL env var)
\n\
\
-i KEY : SSH private key file used for authentication
\n\
\
-p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See http://jenkins-ci.org/https-proxy-tunnel
\n\
\n\
The available commands depend on the server. Run the 'help' command to
\n\
see the list.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录