#![allow(missing_copy_implementations)]
use bytes::Bytes;
use rand_core::{OsRng, RngCore};
use serde::{Deserialize, Serialize};
use ssh_key::Fingerprint;
use std::collections::{BTreeMap, BTreeSet};
use url::Url;
use uuid::Uuid;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct JobRequest {}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ClientHello {
pub fingerprint: Fingerprint,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct Challenge {
pub payload: Bytes,
}
impl Challenge {
pub fn random() -> Self {
let mut data = [0u8; 16];
OsRng.fill_bytes(&mut data);
Challenge {
payload: data.to_vec().into(),
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct JobList {
pub jobs: Vec<Job>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Job {
pub uuid: Uuid,
pub name: String,
pub version: String,
pub source: Url,
pub kind: JobKind,
}
#[derive(
Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug, Default,
)]
#[serde(rename_all = "snake_case")]
pub enum NamedVariant {
#[default]
Default,
}
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)]
#[serde(untagged)]
pub enum Variant {
Named(NamedVariant),
Custom(String),
}
impl Default for Variant {
fn default() -> Self {
Variant::Named(NamedVariant::default())
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BuildEnv {
pub variant: Variant,
pub target: String,
pub features: BTreeSet<String>,
pub default_features: bool,
pub environment: BTreeMap<String, String>,
pub dependencies: BTreeMap<String, String>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum JobKind {
Metadata,
Binary(BuildEnv),
Debian(BuildEnv),
Coverage(BuildEnv),
}
#[cfg(test)]
mod tests {
use super::*;
use serde_test::{assert_tokens, Token};
#[test]
fn default_variant() {
assert_eq!(Variant::default(), Variant::Named(NamedVariant::Default));
}
#[test]
fn variant_serialize_default() {
assert_tokens(
&Variant::Named(NamedVariant::Default),
&[Token::UnitVariant {
name: "NamedVariant",
variant: "default",
}],
);
}
#[test]
fn variant_serialize_custom() {
assert_tokens(&Variant::Custom("custom".into()), &[Token::Str("custom")]);
}
}