use std::fmt;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use crate::capabilities::CapabilityReport;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum BindingTarget {
Airflow,
Dagster,
Prefect,
Temporal,
Kubernetes,
}
impl BindingTarget {
pub fn as_str(self) -> &'static str {
match self {
Self::Airflow => "airflow",
Self::Dagster => "dagster",
Self::Prefect => "prefect",
Self::Temporal => "temporal",
Self::Kubernetes => "kubernetes",
}
}
pub fn is_experimental(self) -> bool {
matches!(self, Self::Temporal | Self::Kubernetes)
}
pub fn all() -> &'static [BindingTarget] {
&[
Self::Airflow,
Self::Dagster,
Self::Prefect,
Self::Temporal,
Self::Kubernetes,
]
}
}
impl fmt::Display for BindingTarget {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl FromStr for BindingTarget {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"airflow" => Ok(Self::Airflow),
"dagster" => Ok(Self::Dagster),
"prefect" => Ok(Self::Prefect),
"temporal" => Ok(Self::Temporal),
"kubernetes" | "k8s" => Ok(Self::Kubernetes),
other => Err(format!(
"unknown binding target `{other}`; expected one of: airflow, dagster, prefect, temporal, kubernetes"
)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct BindingFile {
pub relative_path: String,
pub media_type: String,
pub content: String,
}
impl BindingFile {
pub fn new(
relative_path: impl Into<String>,
media_type: impl Into<String>,
content: impl Into<String>,
) -> Self {
Self {
relative_path: relative_path.into(),
media_type: media_type.into(),
content: content.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct BindingBundle {
pub target: BindingTarget,
pub contract_id: String,
pub contract_version: String,
pub profile_identity: String,
pub files: Vec<BindingFile>,
pub capability: CapabilityReport,
}