agent-deploy-contract 0.2.0

Transport-neutral deploy contracts for Agent Infra
Documentation
use crate::{BuildBackend, CursorPage};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

/// Provider-owned assets projected into Deploy's tenant ownership boundary.
///
/// The provider remains the lifecycle owner. Deploy owns this inventory and
/// never infers tenancy from a caller-supplied provider reference.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ProviderResourceKind {
    BuildArtifact,
    DeploymentInstance,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ProviderResource {
    pub id: String,
    pub tenant_id: String,
    pub project_id: String,
    pub app_id: String,
    pub deployment_id: String,
    pub backend: BuildBackend,
    pub kind: ProviderResourceKind,
    pub provider_ref: String,
    pub state: String,
    #[serde(default)]
    pub metadata: BTreeMap<String, String>,
    pub created_at: String,
    pub updated_at: String,
}

pub type ProviderResourcePage = CursorPage<ProviderResource>;

impl ProviderResourceKind {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::BuildArtifact => "build_artifact",
            Self::DeploymentInstance => "deployment_instance",
        }
    }

    pub fn parse(value: &str) -> Option<Self> {
        match value {
            "build_artifact" => Some(Self::BuildArtifact),
            "deployment_instance" => Some(Self::DeploymentInstance),
            _ => None,
        }
    }
}

pub fn provider_backend_name(backend: &BuildBackend) -> &'static str {
    match backend {
        BuildBackend::Moulin => "moulin",
        BuildBackend::Luban => "luban",
    }
}

pub fn parse_provider_backend(value: &str) -> Option<BuildBackend> {
    match value {
        "moulin" => Some(BuildBackend::Moulin),
        "luban" => Some(BuildBackend::Luban),
        _ => None,
    }
}