Hub clients¶
xcore_agent.agent.hub_client — the HubClient protocol, the in-memory
test double, and the HttpHubClient implementation of the proposed
.xdeploy REST contract.
xcore_agent.agent.hub_client
¶
Client interface for talking to XCore Hub.
HubClient is the contract the deployment pipeline depends on. HttpHubClient
implements it against a REST contract proposed here — inferred from the
project's architecture notes (XDevKey vs. deployment credential, the
authenticate -> request_artifact -> download -> obtain_deployment_key ->
notify sequence, the DeploymentReport shape) rather than from a published
Hub API spec, because XCore Hub itself does not exist yet. Treat the routes
below as a concrete starting point for building the real Hub against, or
adjust this client once the real Hub's endpoints are decided — nothing else
in xcore-agent needs to change either way, since everything else talks to
HubClient the protocol, not to HttpHubClient the implementation.
Proposed contract (all bodies JSON, bearer auth via the session's access token except /v1/auth itself; binary fields are base64):
POST /v1/auth
-> {xdevkey, project_id}
<- {access_token}
GET /v1/projects/{project_id}/versions/latest
<- {version}
GET /v1/projects/{project_id}/artifacts/{version}
<- {download_url, signature, signer_public_key}
GET <download_url> (may be a different host,
<- raw bytes e.g. signed blob storage)
POST /v1/deployments/authorize
-> {deployment_credential, artifact_signature}
<- {dek} (revocation is enforced here)
POST /v1/deployments/report
-> DeploymentReport fields
<- {deployment_id}
POST /v1/projects/{project_id}/publish (validated against
-> multipart/form-data: a real XCore Hub —
version, project_name, content_sha256, see app/xdeploy in
dek (base64), signature (base64), the Marketplace repo)
signer_public_key (base64), artifact (file)
-> header: X-API-Key: <xdevkey> (not session-bearer — publish is a
local build-time act, not a
deployment; no prior /v1/auth needed)
<- {artifact_id, project_id, version, content_sha256, size_bytes, created_at}
Session
dataclass
¶
An authenticated session against XCore Hub.
Source code in xcore_agent/agent/hub_client.py
ArtifactLocation
dataclass
¶
Where to fetch a specific artifact version from, plus the outer signature so the agent can verify authenticity before spending time decrypting a (possibly large) ciphertext body.
Source code in xcore_agent/agent/hub_client.py
PublishResult
dataclass
¶
What XCore Hub confirms after accepting a newly published artifact.
Source code in xcore_agent/agent/hub_client.py
artifact_id: str
instance-attribute
¶
project_id: str
instance-attribute
¶
version: str
instance-attribute
¶
content_sha256: str
instance-attribute
¶
size_bytes: int
instance-attribute
¶
created_at: str
instance-attribute
¶
__init__(artifact_id: str, project_id: str, version: str, content_sha256: str, size_bytes: int, created_at: str) -> None
¶
DeploymentReport
dataclass
¶
Source code in xcore_agent/agent/hub_client.py
project_id: str
instance-attribute
¶
deployment_id: str
instance-attribute
¶
status: str
instance-attribute
¶
version: str
instance-attribute
¶
started_at: str
instance-attribute
¶
completed_at: str
instance-attribute
¶
plugins: list[dict]
instance-attribute
¶
__init__(project_id: str, deployment_id: str, status: str, version: str, started_at: str, completed_at: str, plugins: list[dict]) -> None
¶
HubClient
¶
Bases: Protocol
Source code in xcore_agent/agent/hub_client.py
authenticate(*, xdevkey: str, project_id: str) -> Session
async
¶
Source code in xcore_agent/agent/hub_client.py
get_latest_version(session: Session, *, project_id: str) -> str
async
¶
Return the version/tag XCore Hub currently considers the latest
release for this project. This is the primitive the CI/CD watch loop
(agent.watcher.Watcher) polls to notice a new version has been
published and trigger an automatic redeploy.
Source code in xcore_agent/agent/hub_client.py
request_artifact(session: Session, *, version: str) -> ArtifactLocation
async
¶
Source code in xcore_agent/agent/hub_client.py
download(location: ArtifactLocation) -> bytes
async
¶
Source code in xcore_agent/agent/hub_client.py
obtain_deployment_key(session: Session, *, deployment_credential: str, artifact_signature: bytes) -> bytes
async
¶
Ask the Hub to unwrap and return the artifact's DEK.
The Hub is the only party that ever holds the KEK; this call is also where access revocation is enforced (a revoked XDevKey or expired deployment credential must be rejected here, before any bytes are decrypted) — see the project's architecture notes.
Source code in xcore_agent/agent/hub_client.py
notify(session: Session, report: DeploymentReport) -> None
async
¶
Source code in xcore_agent/agent/hub_client.py
publish(*, xdevkey: str, project_id: str, project_name: str, version: str, ciphertext: bytes, content_sha256: str, dek: bytes, signature: bytes, signer_public_key: bytes) -> PublishResult
async
¶
Upload a freshly built artifact (see packer.builder.build_artifact)
to XCore Hub for storage. Authenticated by raw xdevkey, not a
Session — publishing is a local build-time act performed before
any agent ever calls authenticate//v1/auth for this artifact.
Source code in xcore_agent/agent/hub_client.py
InMemoryHubClient
dataclass
¶
HubClient implemented entirely in memory, serving one pre-built
artifact — for exercising DeploymentRunner end-to-end (signature
verification, AES-GCM decryption, manifest/content-hash checks,
install/rollback) without a live Hub, since HttpHubClient speaks to a
Hub that does not exist yet (see this module's docstring).
Not a test-only mock kept private to one test file: it is the supported
way to drive the real pipeline against a real, locally-built .xdeploy
artifact — construct it with the exact (ciphertext, dek, signature,
signer_public_key) tuple packer.builder.build_artifact/seal_directory
returned, and it will behave, from DeploymentRunner's point of view,
like a Hub that already has that artifact stored and ready to serve.
notified records every notify() call for the caller to assert on.
Source code in xcore_agent/agent/hub_client.py
ciphertext: bytes
instance-attribute
¶
dek: bytes
instance-attribute
¶
signature: bytes
instance-attribute
¶
signer_public_key: bytes
instance-attribute
¶
notified: list[DeploymentReport] = None
class-attribute
instance-attribute
¶
__init__(ciphertext: bytes, dek: bytes, signature: bytes, signer_public_key: bytes, notified: list[DeploymentReport] = None) -> None
¶
__post_init__() -> None
¶
authenticate(*, xdevkey: str, project_id: str) -> Session
async
¶
get_latest_version(session: Session, *, project_id: str) -> str
async
¶
Source code in xcore_agent/agent/hub_client.py
request_artifact(session: Session, *, version: str) -> ArtifactLocation
async
¶
download(location: ArtifactLocation) -> bytes
async
¶
obtain_deployment_key(session: Session, *, deployment_credential: str, artifact_signature: bytes) -> bytes
async
¶
notify(session: Session, report: DeploymentReport) -> None
async
¶
publish(*, xdevkey: str, project_id: str, project_name: str, version: str, ciphertext: bytes, content_sha256: str, dek: bytes, signature: bytes, signer_public_key: bytes) -> PublishResult
async
¶
Source code in xcore_agent/agent/hub_client.py
HttpHubClient
¶
HTTP implementation of HubClient against the real xcore-team/xdeploy
plugin (app/xdeploy) — validated end to end against a live Hub
(build -> publish -> a real POST /app/xdeploy/v1/projects/{id}/publish
that stored the artifact).
base_url is the Hub's bare root (no /app/... segment — same
convention as marketplace_client.MarketplaceClient); every request
below prepends its own /app/xdeploy mount internally so callers never
need to know this backend's internal plugin layout. Every xcore plugin
(including this one) is mounted under /app/<plugin-name> by the xcore
router — the previous bare /v1/... paths here were a "proposed
contract" written before any real Hub existed to validate against, and
were 404ing against the real one.
transport exists so tests can inject httpx.MockTransport instead of
hitting the network; production callers leave it as None.
Source code in xcore_agent/agent/hub_client.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |