feat(shipping-notice): 收敛复核阶段同源投影与 OT 后履约推进
统一 Case/Progress 阶段 label_key、修复 Job 成功未推进 OT 的可重试失败投影与写路径,并落地 OT 后行级匹配/波次履约与版面诊断开关。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
74270adc22
commit
fd6a23f870
100 files changed
+12138
-1017
No files matched your search
+1190
-113
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.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 或写入日志。"
|
||||
@@ -1,162 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
为货代库存 RPA Worker 写入 Windows 用户级永久环境变量(含共享 scope 与心跳)。
|
||||
|
||||
.DESCRIPTION
|
||||
test/prod 部署时必须配置 SHIPPING_NOTICE_RPA_SHARED_SCOPE_ID,与 Ubuntu 后端
|
||||
SHIPPING_NOTICE_RPA_SHARED_SCOPE_ID 一致,否则 Worker 不会写哨兵文件,
|
||||
后端就绪检查将报 shared_sentinel_missing。
|
||||
|
||||
RPA Profile 凭据解密还要求 Windows Worker 与对应环境后端使用同一个
|
||||
SHIPPING_NOTICE_RPA_CREDENTIAL_KEY。脚本通过 SecureString 交互读取该密钥,
|
||||
不接收明文命令行参数,也不会在控制台显示密钥。
|
||||
|
||||
用法(以管理员或 RPA 专用账号登录后执行一次):
|
||||
.\scripts\rpa\set_rpa_worker_env.ps1 -Environment test -ApiBase "http://192.168.1.20:8890" -ToolApiKey "<密钥>"
|
||||
.\scripts\rpa\set_rpa_worker_env.ps1 -Environment prod -ApiBase "http://生产地址:端口" -ToolApiKey "<密钥>"
|
||||
|
||||
执行后请关闭并重新打开 PowerShell,再运行 freight_rpa_worker.py。
|
||||
完整说明见 docs/features/shipping-notice/technical.md §1.5.5a / §1.5.10。
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet("test", "prod")]
|
||||
[string]$Environment,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ApiBase,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ToolApiKey,
|
||||
|
||||
[SecureString]$CredentialKey,
|
||||
|
||||
[string]$DsvUsername = "",
|
||||
[string]$DsvPassword = "",
|
||||
[string]$CraneUsername = "",
|
||||
[string]$CranePassword = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function ConvertTo-PlainText {
|
||||
param([Parameter(Mandatory = $true)][SecureString]$Value)
|
||||
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($Value)
|
||||
try {
|
||||
return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer)
|
||||
} finally {
|
||||
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer)
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $CredentialKey) {
|
||||
$CredentialKey = Read-Host `
|
||||
"请输入与 $Environment 后端一致的 SHIPPING_NOTICE_RPA_CREDENTIAL_KEY" `
|
||||
-AsSecureString
|
||||
}
|
||||
$CredentialKeyPlainText = ConvertTo-PlainText -Value $CredentialKey
|
||||
try {
|
||||
$credentialKeyBytes = [Convert]::FromBase64String(
|
||||
$CredentialKeyPlainText.Replace('-', '+').Replace('_', '/')
|
||||
)
|
||||
} catch {
|
||||
throw "SHIPPING_NOTICE_RPA_CREDENTIAL_KEY 必须是有效的 Fernet URL-safe Base64 密钥"
|
||||
}
|
||||
if ($credentialKeyBytes.Length -ne 32) {
|
||||
throw "SHIPPING_NOTICE_RPA_CREDENTIAL_KEY 解码后必须为 32 字节"
|
||||
}
|
||||
|
||||
if ($Environment -eq "test") {
|
||||
$Root = "C:\HxopsRpaTest"
|
||||
$ScopeId = "hxops-rpa-test-data"
|
||||
} else {
|
||||
$Root = "C:\HxopsRpaProd"
|
||||
$ScopeId = "hxops-rpa-prod-data"
|
||||
}
|
||||
|
||||
$DataRoot = Join-Path $Root "data"
|
||||
$Vars = [ordered]@{
|
||||
"HXOPS_API_BASE" = $ApiBase
|
||||
"SHIPPING_NOTICE_TOOL_API_KEY" = $ToolApiKey
|
||||
"SHIPPING_NOTICE_RPA_CREDENTIAL_KEY" = $CredentialKeyPlainText
|
||||
"SHIPPING_NOTICE_RPA_WORKER_ENVIRONMENT" = $Environment
|
||||
"SHIPPING_NOTICE_RPA_SHARED_SCOPE_ID" = $ScopeId
|
||||
"SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_SECONDS" = "20"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_MOCK" = "false"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_HEADLESS" = "false"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL" = "msedge"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS" = "3"
|
||||
"SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR" = Join-Path $DataRoot "inventory_triggers"
|
||||
"SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR" = Join-Path $DataRoot "inventory_drop"
|
||||
"SHIPPING_NOTICE_RPA_SHARED_UPLOAD_TRIGGER_DIR" = Join-Path $DataRoot "upload_triggers"
|
||||
"SHIPPING_NOTICE_RPA_SHARED_UPLOAD_QUEUE_DIR" = Join-Path $DataRoot "upload_queue"
|
||||
# 上传站点配置通过受控环境变量单独注入;部署脚本永远不默认开启浏览器提交。
|
||||
"SHIPPING_NOTICE_RPA_WORKER_UPLOAD_ENABLED" = "false"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_UPLOAD_CONFIRM_SUBMIT" = "false"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR" = Join-Path $DataRoot "browser_profile"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_LOG_FILE" = Join-Path $DataRoot "logs\worker.log"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_LOG_MAX_BYTES" = "10485760"
|
||||
"SHIPPING_NOTICE_RPA_WORKER_LOG_BACKUP_COUNT" = "5"
|
||||
}
|
||||
|
||||
if ($DsvUsername) { $Vars["SHIPPING_NOTICE_RPA_WORKER_DSV_USERNAME"] = $DsvUsername }
|
||||
if ($DsvPassword) { $Vars["SHIPPING_NOTICE_RPA_WORKER_DSV_PASSWORD"] = $DsvPassword }
|
||||
if ($CraneUsername) { $Vars["SHIPPING_NOTICE_RPA_WORKER_CRANE_USERNAME"] = $CraneUsername }
|
||||
if ($CranePassword) { $Vars["SHIPPING_NOTICE_RPA_WORKER_CRANE_PASSWORD"] = $CranePassword }
|
||||
|
||||
$SensitiveKeys = @(
|
||||
"SHIPPING_NOTICE_TOOL_API_KEY",
|
||||
"SHIPPING_NOTICE_RPA_CREDENTIAL_KEY",
|
||||
"SHIPPING_NOTICE_RPA_WORKER_DSV_PASSWORD",
|
||||
"SHIPPING_NOTICE_RPA_WORKER_CRANE_PASSWORD"
|
||||
)
|
||||
|
||||
$UsernameKeys = @(
|
||||
"SHIPPING_NOTICE_RPA_WORKER_DSV_USERNAME",
|
||||
"SHIPPING_NOTICE_RPA_WORKER_CRANE_USERNAME"
|
||||
)
|
||||
|
||||
function Get-MaskedUsername {
|
||||
param([string]$Value)
|
||||
if (-not $Value) { return $Value }
|
||||
if ($Value -match '^([^@]+)@(.+)$') {
|
||||
$local = $Matches[1]
|
||||
$domain = $Matches[2]
|
||||
if ($local.Length -le 3) {
|
||||
return "***@$domain"
|
||||
}
|
||||
return ($local.Substring(0, 3) + "***@" + $domain)
|
||||
}
|
||||
if ($Value.Length -le 3) {
|
||||
return "***"
|
||||
}
|
||||
return ($Value.Substring(0, 3) + "***")
|
||||
}
|
||||
|
||||
function Get-DisplayValue {
|
||||
param(
|
||||
[string]$Key,
|
||||
[string]$Value
|
||||
)
|
||||
if ($SensitiveKeys -contains $Key -and $Value) {
|
||||
return "******"
|
||||
}
|
||||
if ($UsernameKeys -contains $Key -and $Value) {
|
||||
return Get-MaskedUsername -Value $Value
|
||||
}
|
||||
return $Value
|
||||
}
|
||||
|
||||
foreach ($entry in $Vars.GetEnumerator()) {
|
||||
[Environment]::SetEnvironmentVariable($entry.Key, [string]$entry.Value, "User")
|
||||
$display = Get-DisplayValue -Key $entry.Key -Value ([string]$entry.Value)
|
||||
Write-Host ("[ok] {0}={1}" -f $entry.Key, $display)
|
||||
}
|
||||
$CredentialKeyPlainText = $null
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Environment=$Environment scope_id=$ScopeId root=$Root"
|
||||
Write-Host "请关闭并重新打开 PowerShell,然后验证:"
|
||||
Write-Host " echo `$env:SHIPPING_NOTICE_RPA_SHARED_SCOPE_ID"
|
||||
Write-Host " cd $Root"
|
||||
Write-Host " python scripts\rpa\freight_rpa_worker.py"
|
||||
@@ -0,0 +1,99 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
在当前 PowerShell 进程树中启动指定环境的 RPA Worker。
|
||||
|
||||
.DESCRIPTION
|
||||
该脚本只写入 Process 级环境变量,绝不调用 User/Machine 环境变量 API。
|
||||
test/prod 可由同一 Windows 用户、同一交互式桌面、两个独立计划任务同时运行。
|
||||
每个环境必须有独立 root、scope、共享目录、browser profile、日志和 DPAPI Secret 文件。
|
||||
DSV/Crane 登录地址、账号和密码来自 HXOPS trigger 的 credential_envelope,
|
||||
不从本机 Secret 文件读取。
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet("test", "prod")]
|
||||
[string]$Environment,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ApiBase,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$WorkerRoot,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$SecretFile,
|
||||
|
||||
[string]$PythonExe = "python.exe",
|
||||
[switch]$Mock,
|
||||
[switch]$Headless
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
if (-not (Test-Path -LiteralPath $SecretFile -PathType Leaf)) {
|
||||
throw "Secret 文件不存在:$SecretFile。请先运行 new_rpa_worker_secret.ps1。"
|
||||
}
|
||||
$workerScript = Join-Path $WorkerRoot "scripts\rpa\freight_rpa_worker.py"
|
||||
if (-not (Test-Path -LiteralPath $workerScript -PathType Leaf)) {
|
||||
throw "Worker 不存在:$workerScript"
|
||||
}
|
||||
|
||||
if ($Environment -eq "test") {
|
||||
$scopeId = "hxops-rpa-test-data"
|
||||
} else {
|
||||
$scopeId = "hxops-rpa-prod-data"
|
||||
}
|
||||
$dataRoot = Join-Path $WorkerRoot "data"
|
||||
|
||||
function ConvertTo-PlainText {
|
||||
param([Parameter(Mandatory = $true)][System.Security.SecureString]$Value)
|
||||
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($Value)
|
||||
try { return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||||
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer) }
|
||||
}
|
||||
|
||||
$secret = Import-Clixml -LiteralPath $SecretFile
|
||||
foreach ($required in @("ToolApiKey", "CredentialKey")) {
|
||||
if (-not ($secret.PSObject.Properties.Name -contains $required)) {
|
||||
throw "Secret 文件缺少字段:$required"
|
||||
}
|
||||
}
|
||||
|
||||
# 只设置当前 launcher 及其 Worker 子进程可见的环境变量;不写 User/Machine 持久配置。
|
||||
$processVars = [ordered]@{
|
||||
HXOPS_API_BASE = $ApiBase
|
||||
SHIPPING_NOTICE_TOOL_API_KEY = ConvertTo-PlainText $secret.ToolApiKey
|
||||
SHIPPING_NOTICE_RPA_CREDENTIAL_KEY = ConvertTo-PlainText $secret.CredentialKey
|
||||
SHIPPING_NOTICE_RPA_WORKER_ENVIRONMENT = $Environment
|
||||
SHIPPING_NOTICE_RPA_SHARED_SCOPE_ID = $scopeId
|
||||
SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_SECONDS = "20"
|
||||
SHIPPING_NOTICE_RPA_WORKER_MOCK = $(if ($Mock) { "true" } else { "false" })
|
||||
SHIPPING_NOTICE_RPA_WORKER_HEADLESS = $(if ($Headless) { "true" } else { "false" })
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = "msedge"
|
||||
SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = "3"
|
||||
SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR = Join-Path $dataRoot "inventory_triggers"
|
||||
SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR = Join-Path $dataRoot "inventory_drop"
|
||||
SHIPPING_NOTICE_RPA_SHARED_UPLOAD_TRIGGER_DIR = Join-Path $dataRoot "upload_triggers"
|
||||
SHIPPING_NOTICE_RPA_SHARED_UPLOAD_QUEUE_DIR = Join-Path $dataRoot "upload_queue"
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR = Join-Path $dataRoot "browser_profile"
|
||||
SHIPPING_NOTICE_RPA_WORKER_LOG_FILE = Join-Path $dataRoot "logs\worker.log"
|
||||
SHIPPING_NOTICE_RPA_WORKER_LOG_MAX_BYTES = "10485760"
|
||||
SHIPPING_NOTICE_RPA_WORKER_LOG_BACKUP_COUNT = "5"
|
||||
SHIPPING_NOTICE_RPA_WORKER_UPLOAD_ENABLED = "false"
|
||||
SHIPPING_NOTICE_RPA_WORKER_UPLOAD_CONFIRM_SUBMIT = "false"
|
||||
}
|
||||
|
||||
foreach ($entry in $processVars.GetEnumerator()) {
|
||||
[Environment]::SetEnvironmentVariable($entry.Key, [string]$entry.Value, "Process")
|
||||
}
|
||||
|
||||
Write-Host "Starting RPA Worker: environment=$Environment scope=$scopeId root=$WorkerRoot"
|
||||
try {
|
||||
& $PythonExe $workerScript
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
finally {
|
||||
foreach ($entry in $processVars.GetEnumerator()) {
|
||||
[Environment]::SetEnvironmentVariable($entry.Key, $null, "Process")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user