Skip to main content

agent_deploy_contract/
provider_resource.rs

1use crate::{BuildBackend, CursorPage};
2use serde::{Deserialize, Serialize};
3use std::collections::BTreeMap;
4
5/// Provider-owned assets projected into Deploy's tenant ownership boundary.
6///
7/// The provider remains the lifecycle owner. Deploy owns this inventory and
8/// never infers tenancy from a caller-supplied provider reference.
9#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
10#[serde(rename_all = "snake_case")]
11pub enum ProviderResourceKind {
12    BuildArtifact,
13    DeploymentInstance,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
17#[serde(rename_all = "camelCase")]
18pub struct ProviderResource {
19    pub id: String,
20    pub tenant_id: String,
21    pub project_id: String,
22    pub app_id: String,
23    pub deployment_id: String,
24    pub backend: BuildBackend,
25    pub kind: ProviderResourceKind,
26    pub provider_ref: String,
27    pub state: String,
28    #[serde(default)]
29    pub metadata: BTreeMap<String, String>,
30    pub created_at: String,
31    pub updated_at: String,
32}
33
34pub type ProviderResourcePage = CursorPage<ProviderResource>;
35
36impl ProviderResourceKind {
37    pub fn as_str(self) -> &'static str {
38        match self {
39            Self::BuildArtifact => "build_artifact",
40            Self::DeploymentInstance => "deployment_instance",
41        }
42    }
43
44    pub fn parse(value: &str) -> Option<Self> {
45        match value {
46            "build_artifact" => Some(Self::BuildArtifact),
47            "deployment_instance" => Some(Self::DeploymentInstance),
48            _ => None,
49        }
50    }
51}
52
53pub fn provider_backend_name(backend: &BuildBackend) -> &'static str {
54    match backend {
55        BuildBackend::Moulin => "moulin",
56        BuildBackend::External => "external",
57    }
58}
59
60pub fn parse_provider_backend(value: &str) -> Option<BuildBackend> {
61    match value {
62        "moulin" => Some(BuildBackend::Moulin),
63        "external" => Some(BuildBackend::External),
64        _ => None,
65    }
66}