我想用详细选项执行Ant,但我不希望传递给arguments任务的Exec在敏感的情况下显示(即用户/密码)。< / p>
一个例子是与数据库的连接:
<exec executable="/bin/sh" failonerror="true">
<arg line="/opt/blah/blah/bin/frmcmp_batch.sh Module=blah Userid=username/mypassword@blah Module_Type=blah"/>
</exec>
我不希望参数(特别是“Userid = username / mypassword @ blah”出现在日志中)。
隐藏/保护参数的最佳方法是什么?
答案 0 :(得分:0)
目前我正在使用以下解决方法(描述here)隐藏“mypassword”,但我想知道是否有更优雅的解决方案?
的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default="test">
<target name="test" depends="">
<echo message="Testing..."/>
<echo message="Turning verbose off... you should NOT see the arguments..."/>
<script language="javascript">
var logger = project.getBuildListeners().firstElement();
// 2 works to turn off verbose
logger.setMessageOutputLevel(2);
</script>
<exec dir="." executable="cmd">
<arg line="/c dummy.bat mypassword"/>
</exec>
<echo message="Turning verbose on... you should see the arguments..."/>
<script language="javascript">
var logger = project.getBuildListeners().firstElement();
// 3 works to turn verbose back on
logger.setMessageOutputLevel(3);
</script>
<exec dir="." executable="cmd">
<arg line="/c dummy.bat mypassword"/>
</exec>
</target>
</project>
dummy.bat
@echo off
echo dummy
输出
test:
[echo] Testing...
[echo] Turning verbose off... you should NOT see the arguments...
[exec] dummy
[echo] Turning verbose on... you should see the arguments...
[exec] Current OS is Windows XP
[exec] Executing 'cmd' with arguments:
[exec] '/c'
[exec] 'dummy.bat'
[exec] 'mypassword'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] dummy
答案 1 :(得分:0)
保护密码的最佳方法是不使用密码:-)以下答案描述了如何设置SSH密钥:
ANT sshexec命令支持“keyfile”属性。
以下是过去对我有用的解决方案。
您似乎担心日志文件中出现的密码?我的固定是永远不要写下我的密码或在脚本中硬编码....