Initial project import

This commit is contained in:
2026-08-14 09:40:51 +03:00
parent 00040e5ce4
commit d7099bf80d
146 changed files with 30509 additions and 1055 deletions
+67 -1
View File
@@ -84,7 +84,8 @@ while ($listener.IsListening) {
$context = $listener.GetContext()
try {
if ($context.Request.HttpMethod -eq 'GET' -and $context.Request.Url.AbsolutePath -eq '/healthz') { Send-Json $context 200 @{status='ok';service='onec-repository-runner'}; continue }
if ($context.Request.HttpMethod -ne 'POST' -or $context.Request.Url.AbsolutePath -ne '/repository/execute') { Send-Json $context 404 @{status='not_found'}; continue }
$requestPath = $context.Request.Url.AbsolutePath
if ($context.Request.HttpMethod -ne 'POST' -or $requestPath -notin @('/repository/execute', '/configuration/activation/debug')) { Send-Json $context 404 @{status='not_found'}; continue }
$expected = [Environment]::GetEnvironmentVariable('ONEC_REPOSITORY_RUNNER_TOKEN', 'Process')
if (-not $expected) { $expected = [Environment]::GetEnvironmentVariable('ONEC_REPOSITORY_RUNNER_TOKEN', 'Machine') }
if (-not $expected -or $context.Request.Headers['Authorization'] -ne "Bearer $expected") { Send-Json $context 401 @{status='unauthorized'}; continue }
@@ -93,6 +94,71 @@ while ($listener.IsListening) {
$all = Get-Content -LiteralPath $ConfigPath -Raw -Encoding UTF8 | ConvertFrom-Json
$base = $all.([string]$payload.base_id)
if (-not $base -or -not $base.repository) { Send-Json $context 400 @{status='not_configured'}; continue }
if ($requestPath -eq '/configuration/activation/debug') {
$layer = if ($payload.layer) { [string]$payload.layer } else { 'all' }
$mode = if ($payload.mode) { ([string]$payload.mode).ToLowerInvariant() } else { 'debug' }
$requestId = [string]$payload.request_id
$fingerprint = ([string]$payload.fingerprint).ToLowerInvariant()
if ($layer -notin @('all', 'base_saved_state', 'extension_saved_state') -or $mode -ne 'debug') {
Send-Json $context 400 @{status='invalid_request';message='a supported layer and mode=debug are required'}
continue
}
if ([bool]$requestId -ne [bool]$fingerprint -or ($requestId -and ($requestId -notmatch '^actreq-[0-9a-fA-F]{32}$' -or $fingerprint -notmatch '^[0-9a-f]{64}$'))) {
Send-Json $context 400 @{status='invalid_request';message='request_id and a 64-hex fingerprint must be supplied together'}
continue
}
$config = $base.repository
$selectorCount = 0
foreach ($selectorKey in @('file', 'server', 'name')) {
if ([string]$config.infobase.$selectorKey) { $selectorCount++ }
}
$designerConfigured = [bool]([string]$config.designer_path)
$designerAvailable = $designerConfigured -and (Test-Path -LiteralPath ([string]$config.designer_path) -PathType Leaf)
$selectorConfigured = $selectorCount -eq 1
$ready = $designerAvailable -and $selectorConfigured
$debugAcceptance = $null
if ($requestId) {
$receiptText = "base_id=$([string]$payload.base_id)`nlayer=$layer`nrequest_id=$requestId`nfingerprint=$fingerprint`nmode=debug"
$receiptBytes = [Text.Encoding]::UTF8.GetBytes($receiptText)
$receiptHash = [Security.Cryptography.SHA256]::Create()
try {
$receipt = if ($ready) { -join ($receiptHash.ComputeHash($receiptBytes) | ForEach-Object { $_.ToString('x2') }) } else { $null }
} finally { $receiptHash.Dispose() }
$debugAcceptance = @{
accepted=$ready
request_id=$requestId
fingerprint=$fingerprint
receipt=$receipt
}
}
$result = @{
schema='onec_configuration_activation_runner_probe.v1'
status=$(if ($ready) {'ready'} else {'not_ready'})
base_id=[string]$payload.base_id
layer=$layer
runner=@{
kind='local'
reachable=$true
designer_path_configured=$designerConfigured
designer_available=$designerAvailable
infobase_selector_configured=$selectorConfigured
}
operation=@{
kind=$(if ($layer -eq 'base_saved_state') {'/UpdateDBCfg'} else {$null})
execution_supported=$false
extension_manual_only=$layer -in @('all', 'extension_saved_state')
}
debug_acceptance=$debugAcceptance
execution=@{
mode='debug'
performed=$false
designer_started=$false
active_configuration_changed=$false
}
}
Send-Json $context 200 $result
continue
}
$result = Invoke-RepositoryAction $base.repository $payload
Send-Json $context $(if ($result.status -eq 'ok') {200} else {409}) $result
} catch { Send-Json $context 500 @{status='runner_error';message=$_.Exception.Message} }