-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathconfig_doc.rs
203 lines (187 loc) · 7.27 KB
/
config_doc.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use std::{collections::HashMap, hash::Hash};
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum ContextKind {
Configuration,
Resource,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum SecurityContextKind {
Current,
Elevated,
Restricted,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum Operation {
Get,
Set,
Test,
Export,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum ExecutionKind {
Actual,
WhatIf,
}
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub struct MicrosoftDscMetadata {
/// Version of DSC
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
/// The operation being performed
#[serde(skip_serializing_if = "Option::is_none")]
pub operation: Option<Operation>,
/// The type of execution
#[serde(rename = "executionType", skip_serializing_if = "Option::is_none")]
pub execution_type: Option<ExecutionKind>,
/// The start time of the configuration operation
#[serde(rename = "startDatetime", skip_serializing_if = "Option::is_none")]
pub start_datetime: Option<String>,
/// The end time of the configuration operation
#[serde(rename = "endDatetime", skip_serializing_if = "Option::is_none")]
pub end_datetime: Option<String>,
/// The duration of the configuration operation
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<String>,
/// The security context of the configuration operation, can be specified to be required
#[serde(rename = "securityContext", skip_serializing_if = "Option::is_none")]
pub security_context: Option<SecurityContextKind>,
/// Identifies if the operation is part of a configuration
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<ContextKind>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub struct Metadata {
#[serde(rename = "Microsoft.DSC", skip_serializing_if = "Option::is_none")]
pub microsoft: Option<MicrosoftDscMetadata>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Configuration {
#[serde(rename = "$schema")]
pub schema: DocumentSchemaUri,
#[serde(rename = "contentVersion")]
pub content_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<HashMap<String, Parameter>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub variables: Option<HashMap<String, Value>>,
pub resources: Vec<Resource>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub struct Parameter {
#[serde(rename = "type")]
pub parameter_type: DataType,
#[serde(rename = "defaultValue", skip_serializing_if = "Option::is_none")]
pub default_value: Option<Value>,
#[serde(rename = "allowedValues", skip_serializing_if = "Option::is_none")]
pub allowed_values: Option<Vec<Value>>,
#[serde(rename = "minValue", skip_serializing_if = "Option::is_none")]
pub min_value: Option<i64>,
#[serde(rename = "maxValue", skip_serializing_if = "Option::is_none")]
pub max_value: Option<i64>,
#[serde(rename = "minLength", skip_serializing_if = "Option::is_none")]
pub min_length: Option<i64>,
#[serde(rename = "maxLength", skip_serializing_if = "Option::is_none")]
pub max_length: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, Value>>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum DataType {
#[serde(rename = "string")]
String,
#[serde(rename = "secureString")]
SecureString,
#[serde(rename = "int")]
Int,
#[serde(rename = "bool")]
Bool,
#[serde(rename = "object")]
Object,
#[serde(rename = "secureObject")]
SecureObject,
#[serde(rename = "array")]
Array,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub struct Resource {
/// The fully qualified name of the resource type
#[serde(rename = "type")]
pub resource_type: String,
/// A friendly name for the resource instance
pub name: String, // friendly unique instance name
#[serde(rename = "dependsOn", skip_serializing_if = "Option::is_none")]
#[schemars(regex(pattern = r"^\[resourceId\(\s*'[a-zA-Z0-9\.]+/[a-zA-Z0-9]+'\s*,\s*'[a-zA-Z0-9 ]+'\s*\)]$"))]
pub depends_on: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub properties: Option<Map<String, Value>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, Value>>,
}
// Defines the valid and recognized canonical URIs for the configuration schema
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum DocumentSchemaUri {
#[default]
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json")]
Version2024_04,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/config/document.json")]
Bundled2024_04,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/config/document.vscode.json")]
VSCode2024_04,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json")]
Version2023_10,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/config/document.json")]
Bundled2023_10,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/config/document.vscode.json")]
VSCode2023_10,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json")]
Version2023_08,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/config/document.json")]
Bundled2023_08,
#[serde(rename = "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/config/document.vscode.json")]
VSCode2023_08,
}
impl Default for Configuration {
fn default() -> Self {
Self::new()
}
}
impl Configuration {
#[must_use]
pub fn new() -> Self {
Self {
schema: DocumentSchemaUri::Version2024_04,
content_version: Some("1.0.0".to_string()),
parameters: None,
variables: None,
resources: Vec::new(),
metadata: None,
}
}
}
impl Resource {
#[must_use]
pub fn new() -> Self {
Self {
resource_type: String::new(),
name: String::new(),
depends_on: None,
properties: None,
metadata: None,
}
}
}
impl Default for Resource {
fn default() -> Self {
Self::new()
}
}