在Day 15有分享用DOS過版Tableau,但每次過版都需要Tableau Owner及DBA同時在場,當時與客戶IT研究,將DOS Script透過7-zip工具轉成exe,DB帳密存在裡面,然後再交付給Tableau Owner過版,就不用DBA到場,而DB的密碼若改變,可以再交出新的exe給Tableau Owner。
然而現實很骨感,用7-zip包出的exe,雖然是二進位檔不擔心密碼外洩,但會被IT偵測不明來源軟體而狂發告警,所以試著找PowerShell的ps1轉成exe的工具,結果不但有,而且是微軟官方的,執行了也不會被偵測告警來源不明軟體。分享網址如下:
https://github.com/MScholtes/TechNet-Gallery/tree/master/PS2EXE-GUI
上一層目錄提供不少工具:https://github.com/MScholtes/TechNet-Gallery
下載TechNet-Gallery後,有很多ps1工具,但最最主要的是PS2EXE-GUI。
工作開始....
# MakeExeUAT.ps1
$account = Read-Host "Enter DB Account"
if (-not(Test-Path -Path ./"${account}.ini")) {
Write-Host "No config for $account"
Exit
}
$content = ( Get-Content .\${account}.ini | ConvertFrom-StringData)
$content = $content + @{dbaccount=$account}
$securePwd = Read-Host "Enter password" -AsSecureString
$plainPwd =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePwd))
$securePwd2 = Read-Host "Enter password Again" -AsSecureString
$plainPwd2 =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePwd2))
if ($plainPwd -cne $plainPwd2) {
Write-Host "Password Inconsistent"
Exit
}
$content = $content + @{dbpwd=$plainPwd}
"#publish.ps1 " | Out-File "publish.ps1"
$content.Keys | % {
"`$$_ = " + '"' + $content.$_ + '"' | Add-Content "publish.ps1"
}
Get-Content .\publishUAT.ps1 | Add-Content "publish.ps1"
# 產出exe要改檔名,以DB Account前綴:RPT_publish.exe
."D:\TechNet-Gallery-master\PS2EXE-GUI\ps2exe.ps1" .\publish.ps1 ".\${account}_publishUAT.exe" -verbose
# Remove-Item .\publish.ps1
【說明】
模版檔(publishUAT.ps1)內容如下:
$account = Read-Host "Enter Tableau Account"
$securePwd = Read-Host "Enter Tableau's password" -AsSecureString
$plainPwd =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePwd))
$NOW = Get-Date -format "yyyyMMdd"
$folder = $folder.replace("YYYYMMDD", $NOW)
Get-ChildItem -Path $folder | ForEach {
$logfile = $_.FullName.replace('.twb', '.log')
& $tabcmd publish $_.FullName -n $_.BaseName -s $url --username $account --password $plainPwd --db-username $dbaccount --db-password $dbpwd --Project $project --save-db-password --save-oauth --overwrite --tabbed 2> $logfile
}
#publish.ps1
$project = "RPT_PRJ"
$url = "http://localhost:8000"
$folder = "D:\UAT\YYYYMMDD_UAT\TABLEAU\*.twb"
$tabcmd = "D:\Program Files\Tableau\Tableau Server\10.5\bin\tabcmd.exe"
$dbaccount = "RPT"
$dbpwd = "RPT1234"
$account = Read-Host "Enter Tableau Account"
$securePwd = Read-Host "Enter Tableau's password" -AsSecureString
$plainPwd =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePwd))
$NOW = Get-Date -format "yyyyMMdd"
$folder = $folder.replace("YYYYMMDD", $NOW)
Get-ChildItem -Path $folder | ForEach {
$logfile = $_.FullName.replace('.twb', '.log')
& $tabcmd publish $_.FullName -n $_.BaseName -s $url --username $account --password $plainPwd --db-username $dbaccount --db-password $dbpwd --Project $project --save-db-password --save-oauth --overwrite --tabbed 2> $logfile
}
所以之後只要DB密碼變更到期,DBA再用MakeExeUAT.exe產出新的publishUAT.exe交付Tableau Owner處理過版就好,節省大伙寶貴的時間。
而這支專案也可以做得更好。改善方向如下:
第29天了,推出壓箱寶