Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/sonatype-state-preflight.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Read-only Sonatype deployment-state census

on:
workflow_dispatch:

permissions:
contents: read

jobs:
state-census:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out the exact workflow source
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Read account-visible deployment IDs and states only
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
run: python3 -B scripts/sonatype_deployment_states.py --output sonatype-deployment-states.json
- name: Retain the bounded state-only report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: sonatype-deployment-states-${{ github.run_id }}-${{ github.run_attempt }}
path: sonatype-deployment-states.json
if-no-files-found: error
retention-days: 7
46 changes: 46 additions & 0 deletions docs/central-deployment-state-inventory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Account-visible deployment-state census

This is a separate GET-only observation. The existing coordinate inventory and its
INCOMPLETE results retain their original meaning. A state census never establishes
complete GAVs, reservation history or version allocation.

The default-branch-only manual `Read-only Sonatype deployment-state census`
workflow queries only the fixed authenticated GET
`https://central.sonatype.com/api/v1/publisher/deployments` for exact namespace
`io.fireflysoftware`, without a state filter. It reuses the reviewed transport,
in-memory credential encoding, no-proxy/no-redirect behavior and strict bounded
JSON parsing. It never calls POST status, upload, publish, delete, Maven or signing.
Names, paths, PURLs, errors and other component values do not supply coordinates
and do not appear in the report.

Every row must have an exact supported deployment ID, namespace, GET-supported
state and timestamps. The component array must have known bounded cardinality;
its items are objects, but their coordinate fields may be missing, null or
unsupported. The state census accepts empty component arrays because it does not
claim coordinate coverage. Missing/malformed arrays still refuse. Pagination is
complete and cardinality-consistent with unique deployment IDs. Both full sweeps
must match IDs, states, timestamps and component counts. Original limits remain:
120-second outer worker,2MiB per response,100 pages and100000 components per sweep,
up to100 rows per page and10000 component entries per deployment. No retry or
separate per-phase budget is added.

A complete report has `ACCOUNT_VISIBLE_STATE_CENSUS_STABLE_TWO_SWEEPS`, scope
`GET_ACCOUNT_VISIBLE_DEPLOYMENT_ID_STATE_ONLY`, explicit pagination and counts,
`coordinateInventoryAccepted=false`, `versionAllocated=false` and
`releasePublished=false`. `noPendingDeploymentsGatePassed` is true only if every
observed deployment is PUBLISHED; authenticated empty is explicit zero. FAILED,
VALIDATING, VALIDATED and PUBLISHING remain in `pendingDeployments` and block that
separate gate. Unsupported states, partial/unstable pagination, transport or shape
failures produce INCOMPLETE. Pending but complete state evidence is retained with
worker/CLI exit1; it is never relabeled an ordinary success. No raw body or private
display text crosses the report/log boundary.

The official [GET listing](https://central.sonatype.com/api-doc) is account-visible,
not a global or historical registry. [Deployment retention](https://central.sonatype.org/faq/what-happened-to-my-deployments/)
can remove old records. Two equal sweeps are not an atomic cross-registry snapshot
or a lock against concurrent publishers. Root must separately review the actual
future workflow/source/artifact/account observation, exact candidate Central
coordinates/current version metadata, GitHub counters/tags, private source/staging/
reservation history and concurrency controls before any allocation or publication.
This source creates no runtime authority and chooses/reserves no monthly counter.
Parent/Jafly dependency pins and the existing coordinate API/workflow stay exact.
159 changes: 159 additions & 0 deletions scripts/sonatype_deployment_states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env python3
"""Bounded GET-only account-visible deployment states; never coordinate or version admission."""
import argparse
import json
import os
from pathlib import Path
import re
import subprocess
import sys
import sonatype_deployments as portal

STATUS = 'ACCOUNT_VISIBLE_STATE_CENSUS_STABLE_TWO_SWEEPS'
SCOPE = 'GET_ACCOUNT_VISIBLE_DEPLOYMENT_ID_STATE_ONLY'


def timestamp(value):
if (not isinstance(value, str)
or not re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:[.][0-9]{1,19})?Z', value)):
raise portal.InventoryError('Portal state timestamp must be a supported full date-time.')
return portal.timestamp(value)


def project(row):
if not isinstance(row, dict):
raise portal.InventoryError('Portal deployment state row is unsupported.')
identifier = row.get('deploymentId')
state = row.get('deploymentState')
if (not isinstance(identifier, str) or not portal.IDENTIFIER.fullmatch(identifier)
or row.get('namespace') != portal.NAMESPACE or not isinstance(state, str) or state not in portal.STATES):
raise portal.InventoryError('Portal deployment identity, namespace or state is unsupported.')
components = row.get('deploymentComponents')
if (not isinstance(components, list) or len(components) > 10000
or any(not isinstance(component, dict) for component in components)):
raise portal.InventoryError('Portal component cardinality is unsupported.')
return {'deploymentId': identifier, 'state': state, 'componentCount': len(components),
'createTimestamp': timestamp(row.get('createTimestamp')),
'updateTimestamp': timestamp(row.get('updateTimestamp'))}


def sweep(opener, bearer, page_size):
rows = []
identifiers = set()
metadata = None
components = 0
number = 0
while True:
reply = portal.fetch(opener, bearer, number, page_size)
keys = ('page', 'pageSize', 'pageCount', 'totalResultCount')
if any(type(reply.get(key)) is not int or reply[key] < 0 for key in keys):
raise portal.InventoryError('Portal state pagination metadata is unsupported.')
size, count, total = (reply[key] for key in keys[1:])
if (reply['page'] != number or not 1 <= size <= page_size
or count > portal.MAX_PAGES or total > portal.MAX_PAGES * size
or (total > 0 and count != (total + size - 1) // size)
or (total == 0 and count not in (0, 1))):
raise portal.InventoryError('Portal state pagination bounds or cardinality are inconsistent.')
current = (size, count, total)
if metadata is not None and current != metadata:
raise portal.InventoryError('Portal state inventory changed during pagination.')
metadata = current
deployments = reply.get('deployments')
if not isinstance(deployments, list) or len(deployments) != min(size, total - number * size):
raise portal.InventoryError('Portal state page is incomplete.')
for row in deployments:
safe = project(row)
if safe['deploymentId'] in identifiers:
raise portal.InventoryError('Portal state deployment was repeated across pages.')
identifiers.add(safe['deploymentId'])
components += safe['componentCount']
if components > portal.MAX_COMPONENTS:
raise portal.InventoryError('Portal state inventory exceeded the component limit.')
rows.append(safe)
number += 1
if number >= count:
break
if len(rows) != metadata[2]:
raise portal.InventoryError('Portal state inventory cardinality is incomplete.')
return metadata, components, sorted(rows, key=lambda row: row['deploymentId'])


def collect(bearer, opener=None, page_size=100):
if type(page_size) is not int or not 1 <= page_size <= 100:
raise portal.InventoryError('Portal state page size is unsupported.')
if opener is None:
opener = portal.urllib.request.build_opener(portal.urllib.request.ProxyHandler({}), portal.NoRedirect())
first = sweep(opener, bearer, page_size)
second = sweep(opener, bearer, page_size)
if first != second:
raise portal.InventoryError('Portal state inventory changed between complete sweeps.')
metadata, components, rows = first
pending = [row for row in rows if row['state'] != 'PUBLISHED']
return {'schema': 1, 'status': STATUS, 'inventoryScope': SCOPE,
'namespace': portal.NAMESPACE, 'endpoint': portal.ENDPOINT, 'httpMethod': 'GET',
'coordinateInventoryAccepted': False, 'versionAllocated': False, 'releasePublished': False,
'atomicSnapshot': False, 'matchingSweeps': 2, 'pageSize': metadata[0],
'pageCount': metadata[1], 'deploymentCount': metadata[2], 'componentCount': components,
'deployments': rows, 'pendingDeployments': pending, 'noPendingDeploymentsGatePassed': not pending,
'completenessScope': 'Only authenticated account-visible exact-namespace deployment IDs and states; no coordinate, global or historical coverage.'}


def incomplete(reason='Portal state census did not complete.'):
return {**portal.incomplete(reason), 'inventoryScope': SCOPE, 'coordinateInventoryAccepted': False,
'noPendingDeploymentsGatePassed': False}


def worker(output):
try:
bearer = portal.token(os.environ.get('SONATYPE_USERNAME', ''), os.environ.get('SONATYPE_PASSWORD', ''))
report = collect(bearer)
portal.write_report(output, report)
return 0 if report['noPendingDeploymentsGatePassed'] else 1
except portal.InventoryError as error:
portal.write_report(output, incomplete(str(error)))
return 1
except Exception:
portal.write_report(output, incomplete())
return 1


def run_bounded(output):
portal.write_report(output, incomplete())
try:
result = subprocess.run([sys.executable, '-B', str(Path(__file__).resolve()),
'--internal-worker', '--output', str(output)],
timeout=portal.WORK_SECONDS, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
check=False)
if result.returncode not in (0, 1):
raise ValueError('Worker did not complete.')
report = json.loads(Path(output).read_text())
if (report.get('inventoryScope') != SCOPE or report.get('coordinateInventoryAccepted') is not False
or report.get('versionAllocated') is not False or report.get('releasePublished') is not False):
raise ValueError('State-only report required.')
if report.get('status') == 'INCOMPLETE' and result.returncode == 1:
return 1
if report.get('status') != STATUS or type(report.get('noPendingDeploymentsGatePassed')) is not bool:
raise ValueError('Complete state census or closed failure required.')
if result.returncode != (0 if report['noPendingDeploymentsGatePassed'] else 1):
raise ValueError('Worker gate result is inconsistent.')
return result.returncode
except (subprocess.TimeoutExpired, OSError, ValueError, AttributeError):
portal.write_report(output, incomplete())
return 1


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output', required=True, type=Path)
parser.add_argument('--internal-worker', action='store_true', help=argparse.SUPPRESS)
args = parser.parse_args()
if args.internal_worker:
return worker(args.output)
code = run_bounded(args.output)
print('Account-visible state census passed its no-pending gate; coordinate and allocation gates remain separate.'
if code == 0 else 'State census or no-pending gate did not pass; allocation remains blocked.')
return code


if __name__ == '__main__':
sys.exit(main())
Loading
Loading