dev_scope/models/v1alpha/
report_definition.rs

1use crate::models::core::ModelMetadata;
2
3use crate::models::v1alpha::V1AlphaApiVersion;
4use derive_builder::Builder;
5
6use crate::models::{HelpMetadata, InternalScopeModel, ScopeModel};
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9use std::collections::BTreeMap;
10
11/// Definition of the Report Definition
12#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Builder, JsonSchema)]
13#[serde(rename_all = "camelCase")]
14#[schemars(deny_unknown_fields)]
15pub struct ReportDefinitionSpec {
16    #[serde(default)]
17    /// defines additional data that needs to be pulled from the system when reporting a bug.
18    /// `additionalData` is a map of `string:string`, the value is a command that should be run.
19    /// When a report is built, the commands will be run and automatically included in the report.
20    pub additional_data: BTreeMap<String, String>,
21
22    /// a Jinja2 style template, to be included. The text should be in Markdown format. Scope
23    /// injects `command` as the command that was run.
24    pub template: String,
25}
26
27#[derive(Serialize, Deserialize, Debug, strum::Display, Clone, PartialEq, JsonSchema)]
28pub enum ReportDefinitionKind {
29    #[strum(serialize = "ScopeReportDefinition")]
30    ScopeReportDefinition,
31}
32
33/// A `ScopeReportDefinition` tells scope how to collect details about the system when there
34/// is an issue they need to report.
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Builder, JsonSchema)]
36#[builder(setter(into))]
37#[serde(rename_all = "camelCase")]
38#[schemars(deny_unknown_fields)]
39pub struct V1AlphaReportDefinition {
40    /// API version of the resource
41    pub api_version: V1AlphaApiVersion,
42    /// The type of resource.
43    pub kind: ReportDefinitionKind,
44    /// Standard set of options including name, description for the resource.
45    /// Together `kind` and `metadata.name` are required to be unique. If there are duplicate, the
46    /// resources "closest" to the execution dir will take precedence.
47    pub metadata: ModelMetadata,
48    /// Options for the resource.
49    pub spec: ReportDefinitionSpec,
50}
51
52impl HelpMetadata for V1AlphaReportDefinition {
53    fn metadata(&self) -> &ModelMetadata {
54        &self.metadata
55    }
56
57    fn full_name(&self) -> String {
58        format!("{}/{}", self.kind(), self.name())
59    }
60}
61
62impl ScopeModel<ReportDefinitionSpec> for V1AlphaReportDefinition {
63    fn api_version(&self) -> String {
64        Self::int_api_version()
65    }
66
67    fn kind(&self) -> String {
68        Self::int_kind()
69    }
70
71    fn spec(&self) -> &ReportDefinitionSpec {
72        &self.spec
73    }
74}
75
76impl InternalScopeModel<ReportDefinitionSpec, V1AlphaReportDefinition> for V1AlphaReportDefinition {
77    fn int_api_version() -> String {
78        V1AlphaApiVersion::ScopeV1Alpha.to_string()
79    }
80
81    fn int_kind() -> String {
82        ReportDefinitionKind::ScopeReportDefinition.to_string()
83    }
84    #[cfg(test)]
85    fn examples() -> Vec<String> {
86        vec!["v1alpha/ReportDefinition.yaml".to_string()]
87    }
88}