Добавить обзор решений Aurora и скрипты сбора снимков

This commit is contained in:
2026-12-02 19:39:26 +03:00
parent f18e3bcce6
commit 941490732f
9 changed files with 729 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
# Requires PowerShell 7. Reads ZIP snapshots without extracting or running their contents.
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Priority,
[Parameter(Mandatory)][string]$Bulk,
[Parameter(Mandatory)][string]$Output
)
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Get-ArchiveProfile($File, $Tier) {
$name = $File.BaseName -replace '^\d+-instance-aurora-', '' -replace '-(master|main)$', ''
$row = [ordered]@{
archive = $File.Name; name = $name; tier = $Tier; status = 'ok'
root = ''; revision = ''; signature = ''; bytes = $File.Length
files = 0; source_files = 0; entrypoints = @(); stack = @(); signals = @(); evidence = @()
}
try {
$zip = [IO.Compression.ZipFile]::OpenRead($File.FullName)
try {
$files = @($zip.Entries | Where-Object Name)
$row.files = $files.Count
$roots = @($files | ForEach-Object { ($_.FullName -split '/', 2)[0] } | Sort-Object -Unique)
$stripRoot = $roots.Count -eq 1 -and $files.Count -gt 0 -and $files[0].FullName.Contains('/')
if ($stripRoot) {
$row.root = $roots[0]
if ($row.root -match '-([a-f0-9]{7,40})$') { $row.revision = $Matches[1] }
}
$entries = foreach ($entry in $files) {
$path = $entry.FullName
if ($stripRoot) { $path = $path.Substring($row.root.Length + 1) }
[pscustomobject]@{ path = $path; entry = $entry }
}
$sha = [Security.Cryptography.SHA256]::Create()
try {
$manifest = foreach ($item in ($entries | Sort-Object path -CaseSensitive)) {
$stream = $item.entry.Open()
try { $hash = [Convert]::ToHexString($sha.ComputeHash($stream)) }
finally { $stream.Dispose() }
"$($item.path)`t$hash"
}
$row.signature = [Convert]::ToHexString($sha.ComputeHash(
[Text.Encoding]::UTF8.GetBytes(($manifest -join "`n"))
))
} finally { $sha.Dispose() }
$sources = @($entries | Where-Object {
$_.path -match '\.(py|tsx?|jsx?|sql|vue)$' -and
$_.path -notmatch '(^|/)(tests?|node_modules|vendor|dist|build|static|migrations|alembic|fixtures)(/|$)|(^|/)test_'
})
$row.source_files = $sources.Count
$row.entrypoints = @($sources | Where-Object {
$_.path -match '(^|/)(main|app|router|routes|pipeline)\.(py|tsx?|jsx?)$|(^|/)dags/[^/]+\.py$'
} | Select-Object -First 4 -ExpandProperty path)
if (-not $row.entrypoints.Count) {
$row.entrypoints = @($sources | Select-Object -First 2 -ExpandProperty path)
}
$stackPatterns = [ordered]@{
FastAPI = '\bfastapi\b'; React = '["'']react["'']'; Streamlit = '\bstreamlit\b'
Airflow = '\b(?:apache-airflow|airflow)\b'; SQLAlchemy = '\bsqlalchemy\b'
Greenplum = '\bgreenplum\b'; PostgreSQL = '\b(?:psycopg2?|asyncpg|postgresql)\b'
}
$signalPatterns = [ordered]@{
Airflow = '\b(?:ExternalTaskSensor|PythonOperator|BranchPythonOperator|BaseSensorOperator|TriggerDagRunOperator|DagRun|DAG)\b'
'S3/MinIO' = '\b(?:boto3|aioboto3|Minio|S3Hook|presigned_url)\b'
'Файлы и Excel' = '\b(?:openpyxl|xlsxwriter|read_excel|UploadFile|StreamingResponse)\b'
'PDF' = '\b(?:pdfplumber|pypdf|PyPDF2|fitz)\b'
'SOAP' = '\b(?:zeep|suds|soapaction)\b'
'LDAP/Kerberos' = '\b(?:ldap3|requests_kerberos|gssapi)\b'
'Очереди и фоновые задачи' = '\b(?:Celery|BackgroundTasks|BackgroundTask|TaskiqScheduler|KafkaConsumer|RedisBroker)\b'
'Пакетная запись в БД' = '\b(?:execute_values|copy_expert|copy_from|to_sql)\b'
'UI-таблицы' = '\b(?:AgGrid|AgGridReact|useReactTable|Handsontable|st\.data_editor)\b'
'Версии и блокировки' = '(version_compare|compare_versions|directory.lock|with_for_update|advisory_lock|undo.manager)'
'Прикладной аудит' = '(audit_log|audit_journal|auditlog)'
}
$stack = [Collections.Generic.HashSet[string]]::new()
$hits = [ordered]@{}
$sourcePaths = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
foreach ($source in $sources) { [void]$sourcePaths.Add($source.path) }
$review = $entries | Where-Object {
$sourcePaths.Contains($_.path) -or $_.path -match '(^|/)(requirements[^/]*\.txt|pyproject\.toml|package\.json)$'
}
foreach ($item in $review) {
if ($item.entry.Length -gt 256KB) { continue }
$reader = [IO.StreamReader]::new($item.entry.Open())
try { $body = $reader.ReadToEnd() } finally { $reader.Dispose() }
foreach ($key in $stackPatterns.Keys) {
if ($body -match $stackPatterns[$key]) { [void]$stack.Add($key) }
}
foreach ($key in $signalPatterns.Keys) {
if ($item.path -notmatch $signalPatterns[$key] -and $body -notmatch $signalPatterns[$key]) { continue }
if (-not $hits.Contains($key)) { $hits[$key] = @() }
if ($hits[$key].Count -lt 3) { $hits[$key] += $item.path }
}
}
$row.stack = @($stack | Sort-Object)
$row.signals = @($hits.Keys)
$row.evidence = @($hits.GetEnumerator() | ForEach-Object {
@{ signal = $_.Key; paths = @($_.Value) }
})
} finally { $zip.Dispose() }
} catch {
$row.status = 'unreadable'
}
[pscustomobject]$row
}
$rows = @(
foreach ($pair in @(@{root = $Priority; tier = 'priority'}, @{root = $Bulk; tier = 'bulk'})) {
foreach ($file in (Get-ChildItem -LiteralPath $pair.root -File -Filter '*.zip' | Sort-Object Name)) {
if ($file.Extension -ne '.zip') { continue }
Get-ArchiveProfile $file $pair.tier
}
}
)
if ($rows.Count -eq 0) { throw 'No ZIP files found in either input directory.' }
ConvertTo-Json -InputObject $rows -Depth 7 | Set-Content -LiteralPath $Output -Encoding utf8
$rows | Group-Object tier,status | Select-Object Name,Count