use serde::{Deserialize, Serialize};
use super::{CapabilityMapV1, StringWebcPackageIdent, WebcPackageIdentifierV1};
#[doc(inline)]
pub use wcgi_host::CgiDialect;
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WorkloadV2 {
pub source: StringWebcPackageIdent,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum RunnerV2 {
#[serde(rename = "wasi")]
Wasi(RunnerWasiV1),
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct RunnerWasiV1 {
#[serde(default)]
pub capabilities: CapabilityMapV1,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum SourceSpecV1 {
#[serde(rename = "webc")]
Webc(SourceWebcV1),
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct SourceWebcV1 {
pub command: Option<String>,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WorkloadV1 {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
pub runner: WorkloadRunnerV1,
#[serde(default)]
pub capabilities: CapabilityMapV1,
}
impl WorkloadV1 {
pub fn webc(&self) -> Option<&WebcPackageIdentifierV1> {
self.runner.webc()
}
pub fn webc_mut(&mut self) -> Option<&mut WebcPackageIdentifierV1> {
self.runner.webc_mut()
}
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum WorkloadRunnerV1 {
#[serde(rename = "wasm")]
Wasm(WorkloadRunnerWasmV1),
#[serde(rename = "webc_command")]
WebcCommand(WorkloadRunnerWebcCommandV1),
#[serde(rename = "wcgi")]
WCgi(RunnerWCgiV1),
#[serde(rename = "web_proxy")]
WebProxy(RunnerWebProxyV1),
#[serde(rename = "tcp_proxy")]
TcpProxy(RunnerTcpProxyV1),
}
impl WorkloadRunnerV1 {
pub fn webc(&self) -> Option<&WebcPackageIdentifierV1> {
match self {
WorkloadRunnerV1::Wasm(w) => w.source.webc(),
WorkloadRunnerV1::WebcCommand(w) => Some(&w.package),
WorkloadRunnerV1::WCgi(w) => w.source.webc(),
WorkloadRunnerV1::WebProxy(p) => p.source.webc(),
WorkloadRunnerV1::TcpProxy(p) => p.source.webc(),
}
}
pub fn webc_mut(&mut self) -> Option<&mut WebcPackageIdentifierV1> {
match self {
WorkloadRunnerV1::Wasm(w) => w.source.webc_mut(),
WorkloadRunnerV1::WebcCommand(w) => Some(&mut w.package),
WorkloadRunnerV1::WCgi(w) => w.source.webc_mut(),
WorkloadRunnerV1::WebProxy(p) => p.source.webc_mut(),
WorkloadRunnerV1::TcpProxy(p) => p.source.webc_mut(),
}
}
pub fn as_web_proxy(&self) -> Option<&RunnerWebProxyV1> {
if let Self::WebProxy(v) = self {
Some(v)
} else {
None
}
}
pub fn as_tcp_proxy(&self) -> Option<&RunnerTcpProxyV1> {
if let Self::TcpProxy(v) = self {
Some(v)
} else {
None
}
}
pub fn as_wcgi(&self) -> Option<&RunnerWCgiV1> {
if let Self::WCgi(v) = self {
Some(v)
} else {
None
}
}
pub fn as_webc_command(&self) -> Option<&WorkloadRunnerWebcCommandV1> {
if let Self::WebcCommand(v) = self {
Some(v)
} else {
None
}
}
pub fn as_wasm(&self) -> Option<&WorkloadRunnerWasmV1> {
if let Self::Wasm(v) = self {
Some(v)
} else {
None
}
}
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct RunnerWCgiV1 {
pub source: WorkloadRunnerWasmSourceV1,
pub dialect: Option<CgiDialect>,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct RunnerWebProxyV1 {
pub source: WorkloadRunnerWasmSourceV1,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct RunnerTcpProxyV1 {
pub source: WorkloadRunnerWasmSourceV1,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WorkloadRunnerWasmV1 {
pub source: WorkloadRunnerWasmSourceV1,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum WorkloadRunnerWasmSourceV1 {
#[serde(rename = "webc")]
Webc(WebcSourceV1),
#[serde(rename = "package")]
Package(StringWebcPackageIdent),
#[serde(rename = "fetch")]
Fetch(WorkloadRunnerWasmSourceFetchV1),
#[serde(rename = "local_path")]
LocalPath(WorkloadRunnerWasmSourceLocalPathV1),
}
impl WorkloadRunnerWasmSourceV1 {
pub fn webc(&self) -> Option<&WebcPackageIdentifierV1> {
match self {
Self::Webc(w) => Some(&w.package),
Self::Fetch(_) => None,
Self::LocalPath(_) => None,
Self::Package(p) => Some(&p.0),
}
}
pub fn webc_mut(&mut self) -> Option<&mut WebcPackageIdentifierV1> {
match self {
Self::Webc(w) => Some(&mut w.package),
Self::Fetch(_) => None,
Self::LocalPath(_) => None,
Self::Package(p) => Some(&mut p.0),
}
}
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WebcSourceV1 {
#[serde(flatten)]
pub package: WebcPackageIdentifierV1,
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_token: Option<String>,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WorkloadRunnerWasmSourceFetchV1 {
pub url: url::Url,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WorkloadRunnerWasmSourceLocalPathV1 {
pub path: String,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum WorkloadRunnerWasmFileSourceV1 {
Webc(WebcSourceV1),
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct WorkloadRunnerWebcCommandV1 {
pub package: WebcPackageIdentifierV1,
pub command: String,
}