在上個鐵人賽題目「作業系統的專武」第一天的文章,有提供客戶一支Perl程式,客戶提供Log給廠商時遮蔽IP資訊。參考:https://ithelp.ithome.com.tw/articles/10344881
而這次是廠商要提供docker-compose.yml給客戶,其中密碼資訊要遮蔽,依樣畫葫蘆寫支Perl程式給負責交付的同學執行。
#!/usr/bin/perl
open F, $ARGV[0] or die "error: $!";
@patterns = <DATA>;
while(<F>) {
my $line = $_;
for $pat (@patterns) {
chomp $pat;
$line =~ s/($pat): .+$/$1: XXXXX/;
$line =~ s/($pat)=.+?;/$1=XXXXX/;
}
print $line;
}
close F;
__DATA__
DB_PWD
APP_LOCAL_ADMIN_PWD
這支程式所要遮蔽的內容,是DB_PWD及APP_LOCAL_ADMIN_PWD這兩個key的value,或是類似Connection String形式,採key=value的格式,然後一律用XXXXX遮蔽
./maskInfo.pl docker-compose.yml > new.yml
得到new.yml內容如下:
version: '3.4'
services:
dashboard:
image: 192.168.1.17:5000/app-gui:1.0.0
restart: always
- "8080:8080"
volumes:
- /ap_logs:/workspace/logs
environment:
DB_URL: "10.0.014:1433;databaseName=MDB"
DB_NAME: "MDB"
DB_USER: "mdbadmin"
DB_PWD: XXXXX
APP_MONITOR_HOST: "10.0.0.62"
APP_LDAP_TYPE: "jcifs"
APP_LDAP_DOMAIN: "uat.corp"
APP_LDAP_URL: "10.0.0.114"
APP_LOACL_ADMIN: "enable"
APP_LOCAL_ADMIN_PWD: XXXXX