Skip to content

Commit fb82b79

Browse files
(SCHEMA) Update resource manifest schema source for whatIf
This change updates the schema source definitions for the resource manifest and the `dsc resource list` output to account for the new `whatIf` property and `WhatIf` resource capability. A future commit will regenerate the schemas.
1 parent c739e44 commit fb82b79

File tree

3 files changed

+283
-0
lines changed

3 files changed

+283
-0
lines changed

schemas/src/outputs/resource/list.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ properties:
3434
- Get
3535
- Set
3636
- SetHandlesExist
37+
- WhatIf
3738
- Test
3839
- Delete
3940
- Export
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
# yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema
2+
$schema: https://json-schema.org/draft/2020-12/schema
3+
$id: <HOST>/<PREFIX>/<VERSION>/resource/manifest.whatIf.yaml
4+
5+
title: What-if method
6+
description: >-
7+
Defines how DSC must call the DSC Resource to indicate whether and how the set command will
8+
modify an instance and how to process the output from the DSC Resource.
9+
markdownDescription: | # VS Code only
10+
***
11+
[_Online Documentation_][01]
12+
***
13+
14+
Defines how DSC must call the DSC Resource to indicate whether and how the set command will
15+
modify an instance and how to process the output from the DSC Resource. If a resource doesn't
16+
define this method in the manifest, DSC synthesizes this behavior by converting the result of
17+
the test operation for the resource into the [set result][02].
18+
19+
This method definition has the same structure as the [set method][03] in the resource manifest.
20+
21+
DSC sends data to the command in three ways:
22+
23+
1. When `input` is `stdin`, DSC sends the data as a string representing the data as a compressed
24+
JSON object without spaces or newlines between the object properties.
25+
1. When `input` is `env`, DSC sends the data as environment variables. It creates an environment
26+
variable for each property in the input data object, using the name and value of the property.
27+
1. When the `args` array includes a JSON input argument definition, DSC sends the data as a string
28+
representing the data as a compressed JSON object to the specified argument.
29+
30+
If you don't define the `input` property and don't define a JSON input argument, DSC can't pass
31+
the input JSON to the resource. You can only define one JSON input argument for a command.
32+
33+
You must define the `input` property, one JSON input argument in the `args` property array, or
34+
both.
35+
36+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>
37+
[02]: <DOCS_BASE_URL>/reference/schemas/outputs/resource/set?<DOCS_VERSION_PIN>
38+
[03]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/set?<DOCS_VERSION_PIN>
39+
40+
type: object
41+
required:
42+
- executable
43+
properties:
44+
executable:
45+
$ref: /<PREFIX>/<VERSION>/definitions/commandExecutable.yaml
46+
markdownDescription: |
47+
***
48+
[_Online Documentation_][01]
49+
***
50+
51+
Defines the name of the command to run. The value must be the name of a command discoverable
52+
in the system's `PATH` environment variable or the full path to the command. A file extension
53+
is only required when the command isn't recognizable by the operating system as an
54+
executable.
55+
56+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>#executable
57+
args:
58+
$ref: /<PREFIX>/<VERSION>/definitions/commandArgs.yaml
59+
markdownDescription: |
60+
***
61+
[_Online Documentation_][01]
62+
***
63+
64+
Defines an array of strings to pass as arguments to the command. DSC passes the arguments to
65+
the command in the order they're specified.
66+
67+
For example, the given the following definition:
68+
69+
```json
70+
{
71+
"executable": "myresource",
72+
"args": ["config", "set", "--what-if"],
73+
}
74+
```
75+
76+
DSC invokes the command for the resource as:
77+
78+
```bash
79+
myresource config set --what-if
80+
```
81+
82+
If you want to pass the JSON object representing the property bag for a resource instance to
83+
an argument, you can define a single item in the array as a JSON object. Indicate the name of
84+
the argument with the `jsonInputArg` string property and whether the argument is mandatory
85+
for the command with the `mandatory` boolean property.` When the `mandatory` property is
86+
defined as `true`, DSC passes an empty string to the argument when no JSON input is
87+
available. When the `mandatory` property is undefined or defined as `false`, DSC doesn't pass
88+
the argument at all when no JSON input is available. The default value for the `mandatory`
89+
property is `false`.
90+
91+
For example, given the following definition:
92+
93+
```json
94+
{
95+
"executable": "myresource"
96+
"args": [
97+
"config",
98+
"set",
99+
"--what-if",
100+
{ "jsonInputArg": "--properties" }
101+
]
102+
}
103+
```
104+
105+
DSC invokes the command for the resource as:
106+
107+
```bash
108+
myresource config set --what-if --properties <JSON string of instance properties>
109+
```
110+
111+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>#args
112+
input:
113+
$ref: /<PREFIX>/<VERSION>/definitions/inputKind.yaml
114+
markdownDescription: |
115+
***
116+
[_Online Documentation_][01]
117+
***
118+
119+
Defines how DSC should pass input to the command, either as environment variables or JSON
120+
over `stdin`. This property is optional when you define an object in the `args` list. If
121+
you define a JSON input argument and an `input`, DSC sends the JSON data both ways:
122+
123+
- If you define `input` as `env` and a JSON input argument, DSC sets an environment variable
124+
for each property in the JSON input and passes the JSON input object as a string to the
125+
defined argument.
126+
- If you define `input` as `stdin` and a JSON input argument, DSC passes the JSON input over
127+
stdin and as a string to the defined argument.
128+
- If you define a JSON input argument without defining the `input` property, DSC only passes
129+
the JSON input as a string to the defined argument.
130+
131+
If you don't define the `input` property and don't define a JSON input argument, DSC can't
132+
pass the input JSON to the resource. This makes the manifest invalid. You must define the
133+
`input` property, a JSON input argument in the `args` property array, or both.
134+
135+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>#input
136+
implementsPretest:
137+
title: Resource Performs Pre-Test
138+
description: >-
139+
Defines whether the DSC Resource performs its own test to ensure idempotency when calling the
140+
`set --what-if` command. Set this value to `true` if the DSC Resource tests input before
141+
processing how it will modify system state.
142+
type: boolean
143+
default: false
144+
# VS Code only
145+
markdownDescription: |
146+
***
147+
[_Online Documentation_][01]
148+
***
149+
150+
Defines whether the DSC Resource performs its own test to ensure idempotency when calling the
151+
`set --what-if` command . Set this value to `true` if the DSC Resource tests input before
152+
processing how it will modify system state.
153+
154+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>#implementspretest
155+
handlesExist:
156+
title: Resource handles _exist property
157+
description: >-
158+
Defines whether the DSC Resource has its own built-in handling for the `_exist` common
159+
property. Set this value to `true` if the DSC Resource handles instance deletion internally
160+
when receiving a `set --what-if` command where the instance defines the `_exist` property as
161+
`false`.
162+
type: boolean
163+
default: false
164+
# VS Code only
165+
markdownDescription: |
166+
***
167+
[_Online Documentation_][01]
168+
***
169+
170+
Defines whether the DSC Resource has its own built-in handling for the [`_exist`][02] common
171+
property. Set this value to `true` if the DSC Resource handles instance deletion internally
172+
when receiving a `set --what-if` command where the instance defines the `_exist` property as
173+
`false`.
174+
175+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>#handlesExist
176+
[02]: <DOCS_BASE_URL>/reference/schemas/resource/properties/exist?<DOCS_VERSION_PIN>
177+
return:
178+
description: >-
179+
Defines whether the command returns a JSON blob of the DSC Resource's expected state after a
180+
set operation in what-if mode or the state and an array of the properties the DSC Resource
181+
would modify.
182+
$ref: /<PREFIX>/<VERSION>/definitions/returnKind.yaml
183+
# VS Code only
184+
markdownDescription: |
185+
***
186+
[_Online Documentation_][01]
187+
***
188+
189+
Defines whether the command returns a JSON blob of the DSC Resource's expected state after a
190+
set operation in what-if mode or the state and an array of the properties the DSC Resource
191+
would modify.
192+
193+
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>#return
194+
markdownEnumDescriptions:
195+
- | # state
196+
_Final state only_
197+
198+
> Indicates that the resource returns only the instance's expected final state after the
199+
> set operation as a JSON blob.
200+
- | # stateAndDiff
201+
_Final state and changed properties_
202+
203+
> Indicates that the resource returns the instance's expected final state and an array of
204+
> property names that the resource would modify.
205+
206+
# Need to use a oneOf with three possibilities because YAML extension in VS Code doesn't understand
207+
# minContains - so we can't use a single if/else/then. Note that JSON, but not YAML, will fail when
208+
# the manifest defines more than one JSON input argument. If/when the YAML extension is updated to
209+
# support 2019-09 and later, we can simplify this to two schemas.
210+
#
211+
# We use long lines for error messages, which can't use Markdown.
212+
oneOf:
213+
- # What-if command with explicit input kind - when `input` is defined and `args` is only strings.
214+
# This subschema never triggers an error in testing.
215+
required: [input]
216+
not:
217+
properties: { args: { contains: { type: object } } }
218+
- # What-if command with JSON input argument - when `input` isn't defined and `args` doesn't
219+
# include a JSON input argument. Only raises an error when `args` has zero JSON input arguments
220+
# or more than one.
221+
not: { required: [input] }
222+
properties:
223+
args:
224+
errorMessage: |-
225+
The `whatIf` command doesn't define either the `input` property or a JSON input argument, or it defines more than one JSON input argument. If you don't define the `input` property and don't define a JSON input argument, DSC can't pass the input JSON to the resource. You can only define one JSON input argument for a command.
226+
227+
You must define the `input` property, one JSON input argument in the `args` property array, or both. For more information, see:
228+
229+
<DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>
230+
contains: { type: object }
231+
minContains: 1
232+
maxContains: 1
233+
- # What-if command with explicit input kind and JSON input argument - when `input` is defined and
234+
# args includes a JSON input argument. Only raises an error when `input` is defined and `args`
235+
# contains more than one JSON input argument.
236+
required: [input]
237+
properties:
238+
args:
239+
errorMessage: |-
240+
You can only specify one JSON input argument for the `whatIf` command. Remove the extra JSON input argument. When you use the JSON input argument, DSC sends the full JSON object as a string to the named argument.
241+
242+
For more information, see:
243+
244+
<DOCS_BASE_URL>/reference/schemas/resource/manifest/whatif?<DOCS_VERSION_PIN>
245+
contains: { type: object }
246+
minContains: 1
247+
maxContains: 1
248+
249+
defaultSnippets: # VS Code only
250+
- label: ' Define without arguments'
251+
markdownDescription: |
252+
Define the `whatIf` command for the resource when no arguments are required and the JSON
253+
input is sent over stdin or as environment variables.
254+
body:
255+
input: ${1|stdin,env|}
256+
implementsPretest: ^${2|true,false|}
257+
return: ${3|state,stateAndDiff|}
258+
executable: ${4:executable_name}
259+
- label: ' Define with string arguments'
260+
markdownDescription: |-
261+
Define the `whatIf` command for the resource when at least one argument is required and the
262+
JSON input is sent over stdin or as environment variables.
263+
body:
264+
input: ${1|stdin,env|}
265+
implementsPretest: ^${2|true,false|}
266+
return: ${3|state,stateAndDiff|}
267+
executable: ${4:executable_name}
268+
args:
269+
- ${5:--first-argument}
270+
- label: ' Define with a JSON input argument'
271+
markdownDescription: |-
272+
Define the `whatIf` command for the resource where the JSON input is passed as a one-line
273+
JSON object string to the specified argument.
274+
body:
275+
implementsPretest: ^${1|true,false|}
276+
return: ${2|state,stateAndDiff|}
277+
executable: ${3:executable_name}
278+
args:
279+
- jsonInputArg: ${4:argument_name}
280+
mandatory: ^$5

schemas/src/resource/manifest.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ properties:
445445
$ref: /<PREFIX>/<VERSION>/resource/manifest.get.yaml
446446
set:
447447
$ref: /<PREFIX>/<VERSION>/resource/manifest.set.yaml
448+
whatIf:
449+
$ref: /<PREFIX>/<VERSION>/resource/manifest.whatIf.yaml
448450
test:
449451
$ref: /<PREFIX>/<VERSION>/resource/manifest.test.yaml
450452
delete:

0 commit comments

Comments
 (0)