Files
syops/scripts/rpa/new_rpa_worker_secret.ps1
T
hugoandCursor fd6a23f870 feat(shipping-notice): 收敛复核阶段同源投影与 OT 后履约推进
统一 Case/Progress 阶段 label_key、修复 Job 成功未推进 OT 的可重试失败投影与写路径,并落地 OT 后行级匹配/波次履约与版面诊断开关。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 13:11:14 +08:00

44 lines
1.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<#
.SYNOPSIS
为同一 Windows 用户下的 RPA Worker 创建当前用户可解密的 Secret 文件。
.DESCRIPTION
Secret 文件使用 PowerShell SecureString/Windows DPAPI 保存,不能被其他用户直接解密。
启动脚本只在 Worker 子进程中设置 Process 级环境变量,不写入 User/Machine 环境变量。
Secret 文件应保存在仓库之外,例如 C:\HxopsRpaSecrets\test.xml。
DSV/Crane 登录地址、账号和密码不在本文件中保存;它们由 HXOPS RPA Profile
配置并随加密 credential_envelope 进入 trigger,Worker 使用 CredentialKey 解密。
#>
param(
[Parameter(Mandatory = $true)]
[ValidateSet("test", "prod")]
[string]$Environment,
[string]$OutputRoot = "C:\HxopsRpaSecrets"
)
$ErrorActionPreference = "Stop"
$secretPath = Join-Path $OutputRoot ("{0}.xml" -f $Environment)
New-Item -ItemType Directory -Force -Path $OutputRoot | Out-Null
function Read-RequiredSecret {
param([Parameter(Mandatory = $true)][string]$Prompt)
$value = Read-Host $Prompt -AsSecureString
if (-not $value -or $value.Length -eq 0) {
throw "$Prompt 不能为空"
}
return $value
}
$record = [pscustomobject]@{
ToolApiKey = Read-RequiredSecret "请输入 $Environment 环境 SHIPPING_NOTICE_TOOL_API_KEY"
CredentialKey = Read-RequiredSecret "请输入 $Environment 环境 SHIPPING_NOTICE_RPA_CREDENTIAL_KEY"
}
$record | Export-Clixml -LiteralPath $secretPath
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
icacls $secretPath /inheritance:r /grant:r "${currentUser}:F" | Out-Null
Write-Host "Secret 文件已创建:$secretPath"
Write-Host "仅当前 Windows 用户可解密;不要复制到其他账号、提交 Git 或写入日志。"