Apache Ant - 隐藏/保护 Exec 任务参数 [英] Apache Ant - Hide/Secure Exec Task Arguments

查看:23
本文介绍了Apache Ant - 隐藏/保护 Exec 任务参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用详细选项执行 Ant,但我不想要 参数 传递到 Exec 任务中,在敏感的情况下显示(即用户/密码).

I want to execute Ant with the verbose option but I don't want the arguments passed into the Exec task to be displayed in situations where they are sensitive (i.e. user/password).

一个例子是连接到数据库的地方:

An example is where there's a connection to a database:

<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"出现在日志中).

I don't want the arguments (specifically "Userid=username/mypassword@blah" showing up in the log).

隐藏/保护参数的最佳方法是什么?

What is the best way to hide/secure the arguments?

推荐答案

目前我正在使用以下解决方法(描述了 here) 来隐藏mypassword",但我想知道是否有更优雅的解决方案?

Currently I'm using the following workaround (described here) to hide "mypassword" but I was wondering if there's a more elegant solution?

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

这篇关于Apache Ant - 隐藏/保护 Exec 任务参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆