use serde::Deserialize;
use std::collections::HashMap;
pub mod data_entry;
pub mod github;
pub mod severity;
use data_entry::*;
pub const API_VERSION: &str = "decision.api.shisho.dev/v1beta";
#[derive(Deserialize, Debug, Default)]
pub struct Decision<T> {
pub header: DecisionHeader,
pub entries: Vec<DecisionEntry<T>>,
}
#[derive(Deserialize, Debug, Default)]
pub struct DecisionHeader {
pub api_version: String,
pub kind: String,
pub subject: String,
#[serde(rename = "type")]
pub decision_type: DecisionType,
pub labels: Vec<String>,
pub annotations: HashMap<String, String>,
}
#[derive(Deserialize, Debug, Default)]
pub enum DecisionType {
#[default]
Allow = 1,
Deny = 2,
}
#[derive(Deserialize, Debug, Default)]
pub struct DecisionHeaderBuilder {
h: DecisionHeader,
}
impl DecisionHeaderBuilder {
pub fn new() -> Self {
Default::default()
}
pub fn with_api_version(mut self) -> Self {
self.h.api_version = API_VERSION.to_string();
self
}
pub fn with_kind(mut self, kind: &str) -> Self {
self.h.kind = kind.to_string();
self
}
pub fn with_subject(mut self, subject: Subject) -> Self {
self.h.subject = subject.value;
self
}
pub fn with_decision_type(mut self, decision_type: DecisionType) -> Self {
self.h.decision_type = decision_type;
self
}
pub fn with_labels(mut self, labels: Vec<String>) -> Self {
self.h.labels = labels;
self
}
pub fn with_annotations(mut self, annotations: HashMap<String, String>) -> Self {
self.h.annotations = annotations;
self
}
pub fn build(self) -> DecisionHeader {
self.h
}
}
#[derive(Deserialize, Debug, Default)]
pub struct Subject {
value: String,
}
impl Subject {
pub fn new(subject: &str) -> Subject {
Subject {
value: subject.to_string(),
}
}
}