Skip to content

Commit

Permalink
Merge pull request #318 from SteveL-MSFT/config-result
Browse files Browse the repository at this point in the history
Enable group resource output schema to simplify config output that uses groups
  • Loading branch information
SteveL-MSFT authored Feb 27, 2024
2 parents 31f7e17 + c8075a1 commit af3403e
Show file tree
Hide file tree
Showing 19 changed files with 691 additions and 204 deletions.
9 changes: 7 additions & 2 deletions dsc/assertion.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
"executable": "dsc",
"args": [
"config",
"test"
"--as-group",
"test",
"--as-get"
],
"input": "stdin"
},
"set": {
"executable": "dsc",
"args": [
"config",
"--as-group",
"test"
],
"input": "stdin",
Expand All @@ -25,7 +28,9 @@
"executable": "dsc",
"args": [
"config",
"test"
"--as-group",
"test",
"--as-get"
],
"input": "stdin",
"return": "state"
Expand Down
2 changes: 1 addition & 1 deletion dsc/examples/brew.dsc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resources:
- name: os_check
type: Microsoft/OSInfo
properties:
family: MacOS
family: macOS
- name: brew
type: DSC.PackageManagement/Brew
properties:
Expand Down
38 changes: 38 additions & 0 deletions dsc/examples/groups.dsc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Example for grouping and groups in groups
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: Last Group
type: DSC/Group
properties:
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: Last
type: Test/Echo
properties:
output: Last
dependsOn:
- "[resourceId('DSC/Group','First Group')]"
- name: First Group
type: DSC/Group
properties:
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: First
type: Test/Echo
properties:
output: First
- name: Nested Group
type: DSC/Group
properties:
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: Nested Second
type: Test/Echo
properties:
output: Nested Second
dependsOn:
- "[resourceId('Test/Echo','Nested First')]"
- name: Nested First
type: Test/Echo
properties:
output: Nested First
3 changes: 3 additions & 0 deletions dsc/group.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"executable": "dsc",
"args": [
"config",
"--as-group",
"get"
],
"input": "stdin"
Expand All @@ -15,6 +16,7 @@
"executable": "dsc",
"args": [
"config",
"--as-group",
"set"
],
"input": "stdin",
Expand All @@ -25,6 +27,7 @@
"executable": "dsc",
"args": [
"config",
"--as-group",
"test"
],
"input": "stdin",
Expand Down
3 changes: 3 additions & 0 deletions dsc/parallel.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"args": [
"config",
"--parallel",
"--as-group",
"get"
],
"input": "stdin"
Expand All @@ -17,6 +18,7 @@
"args": [
"config",
"--parallel",
"--as-group",
"set"
],
"input": "stdin",
Expand All @@ -28,6 +30,7 @@
"args": [
"config",
"--parallel",
"--as-group",
"test"
],
"input": "stdin",
Expand Down
6 changes: 6 additions & 0 deletions dsc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum SubCommand {
parameters: Option<String>,
#[clap(short = 'f', long, help = "Parameters to pass to the configuration as a JSON or YAML file", conflicts_with = "parameters")]
parameters_file: Option<String>,
#[clap(long, hide = true)]
as_group: bool,
},
#[clap(name = "resource", about = "Invoke a specific DSC resource")]
Resource {
Expand Down Expand Up @@ -97,13 +99,17 @@ pub enum ConfigSubCommand {
path: Option<String>,
#[clap(short = 'f', long, help = "The output format to use")]
format: Option<OutputFormat>,
#[clap(long, hide = true)]
as_get: bool,
},
#[clap(name = "validate", about = "Validate the current configuration", hide = true)]
Validate {
#[clap(short = 'd', long, help = "The document to pass to the configuration or resource", conflicts_with = "path")]
document: Option<String>,
#[clap(short = 'p', long, help = "The path to a file used as input to the configuration or resource", conflicts_with = "document")]
path: Option<String>,
#[clap(short = 'f', long, help = "The output format to use")]
format: Option<OutputFormat>,
},
#[clap(name = "export", about = "Export the current configuration")]
Export {
Expand Down
14 changes: 10 additions & 4 deletions dsc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ fn main() {
let mut cmd = Args::command();
generate(shell, &mut cmd, "dsc", &mut io::stdout());
},
SubCommand::Config { subcommand, parameters, parameters_file } => {
SubCommand::Config { subcommand, parameters, parameters_file, as_group } => {
if let Some(file_name) = parameters_file {
info!("Reading parameters from file {}", file_name);
match std::fs::read_to_string(file_name) {
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), &input),
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), &input, &as_group),
Err(err) => {
error!("Error: Failed to read parameters file: {err}");
exit(util::EXIT_INVALID_INPUT);
}
}
}
else {
subcommand::config(&subcommand, &parameters, &input);
subcommand::config(&subcommand, &parameters, &input, &as_group);
}
},
SubCommand::Resource { subcommand } => {
Expand Down Expand Up @@ -136,7 +136,13 @@ fn check_debug() {
if env::var("DEBUG_DSC").is_ok() {
eprintln!("attach debugger to pid {} and press a key to continue", std::process::id());
loop {
let event = event::read().unwrap();
let event = match event::read() {
Ok(event) => event,
Err(err) => {
eprintln!("Error: Failed to read event: {err}");
break;
}
};
if let event::Event::Key(key) = event {
// workaround bug in 0.26+ https://github.com/crossterm-rs/crossterm/issues/752#issuecomment-1414909095
if key.kind == event::KeyEventKind::Press {
Expand Down
6 changes: 3 additions & 3 deletions dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::args::OutputFormat;
use crate::util::{EXIT_DSC_ERROR, EXIT_INVALID_ARGS, EXIT_JSON_ERROR, add_type_name_to_json, write_output};
use dsc_lib::configure::config_doc::Configuration;
use dsc_lib::configure::add_resource_export_results_to_configuration;
use dsc_lib::dscresources::invoke_result::GetResult;
use dsc_lib::dscresources::invoke_result::{GetResult, ResourceGetResponse};
use dsc_lib::dscerror::DscError;
use tracing::{error, debug};

Expand Down Expand Up @@ -79,9 +79,9 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm

for instance in export_result.actual_state
{
let get_result = GetResult {
let get_result = GetResult::Resource(ResourceGetResponse {
actual_state: instance.clone(),
};
});

let json = match serde_json::to_string(&get_result) {
Ok(json) => json,
Expand Down
Loading

0 comments on commit af3403e

Please sign in to comment.