feat(import): complete OpenAPI onboarding and verify delivery
This commit is contained in:
1 parent
bb3e376767
commit
e93de7015a
244 files changed
+57020
-5139
No files matched your search
@@ -0,0 +1,80 @@
|
||||
use crank_artifacts::ArtifactRef;
|
||||
use crank_core::{Workspace, WorkspaceId, WorkspaceStatus};
|
||||
use crank_registry::{
|
||||
ArtifactSourceId, CreateImportJobRequest, CreateWorkspaceRequest, ImportJobId, ImportJobKind,
|
||||
ImportJobSourceEnvelope, ImportJobStatus,
|
||||
};
|
||||
use serde_json::json;
|
||||
use time::OffsetDateTime;
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
|
||||
mod apply;
|
||||
mod cleanup;
|
||||
mod create;
|
||||
mod preview_v2;
|
||||
pub(super) fn parse_ts(value: &str) -> OffsetDateTime {
|
||||
OffsetDateTime::parse(value, &Rfc3339).unwrap()
|
||||
}
|
||||
|
||||
pub(super) async fn create_workspace(
|
||||
registry: &crank_registry::PostgresRegistry,
|
||||
id: &str,
|
||||
) -> WorkspaceId {
|
||||
let workspace_id = WorkspaceId::new(id);
|
||||
let created_at = parse_ts("2026-09-26T10:00:00Z");
|
||||
registry
|
||||
.create_workspace(CreateWorkspaceRequest {
|
||||
workspace: &Workspace {
|
||||
id: workspace_id.clone(),
|
||||
slug: id.replace('_', "-"),
|
||||
display_name: id.to_owned(),
|
||||
status: WorkspaceStatus::Active,
|
||||
settings: json!({}),
|
||||
created_at,
|
||||
updated_at: created_at,
|
||||
},
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
workspace_id
|
||||
}
|
||||
|
||||
/// Creates a well-formed, pending, non-expired OpenAPI import job carrying a
|
||||
/// verifiable source envelope, exactly as the legacy ingress path does.
|
||||
pub(super) async fn create_pending_openapi_job(
|
||||
registry: &crank_registry::PostgresRegistry,
|
||||
workspace_id: &WorkspaceId,
|
||||
job_id: &str,
|
||||
now: OffsetDateTime,
|
||||
job_expires_at: OffsetDateTime,
|
||||
) -> ImportJobId {
|
||||
let job = ImportJobId::new(job_id);
|
||||
let source_id = ArtifactSourceId::new("src_openapi_test");
|
||||
let digest = ArtifactRef::from_digest_hex(&"ab".repeat(32)).unwrap();
|
||||
let preview_payload = json!({
|
||||
"source": {
|
||||
"source_id": source_id.as_str(),
|
||||
"digest": digest.as_str(),
|
||||
},
|
||||
"preview": { "ops": ["a", "b"] }
|
||||
});
|
||||
registry
|
||||
.create_import_job(CreateImportJobRequest {
|
||||
id: &job,
|
||||
workspace_id,
|
||||
kind: ImportJobKind::OpenApi,
|
||||
source_format: "openapi",
|
||||
source_version: Some("3.1.0"),
|
||||
status: ImportJobStatus::Pending,
|
||||
source: &ImportJobSourceEnvelope {
|
||||
source_id,
|
||||
digest: digest.clone(),
|
||||
},
|
||||
preview_payload: &preview_payload,
|
||||
created_at: &now,
|
||||
expires_at: &job_expires_at,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
job
|
||||
}
|
||||
Reference in new issue
Block a user