Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Include resource via new Import resource kind and resolve operation #429

Merged
merged 15 commits into from
May 10, 2024

Conversation

SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented May 3, 2024

PR Summary

Note that this solution is not quite complete yet as it only works for get. However, through this work, I've realized I need to refactor resource get, set, test responses so it is always a list even if just one element. The current separation of a singleton vs list makes it too complicated to complete the work for set and test.

  • New Microsoft.DSC/Include resource which includes a file for configuration and also parameters
  • The example include.dsc.yaml shows usage
  • Needed to add new DSC_TRACE_LEVEL env var so that child dsc processes will emit the same level of traces as I needed it to diagnose problems
    • if --trace-level is specified, it will replace any existing DSC_TRACE_LEVEL env var with the new value, dsc now uses this env var unless --trace-level is specified
    • Renamed warning level to warn to match the code to keep it simple
  • New Import resource kind that needs to support a resolve operation and return a ResolveResult
    • As part of adding resolve, I've also made get optional since it doesn't make sense for an Import resource
    • After the files have been resolved to JSON, then a new instance of configurator is created to perform the operation against the resolved content
  • Needed to change how find_resources() works by internally handling case-insensitivity for searching. This removed a bunch of code that made things lowercase before calling this function.
  • helper parse_input_to_json() that will accept JSON or YAML and emit JSON since the file pointed to by Include may either be JSON or YAML for the configuration and parameters file

PR Context

Fix #412

@SteveL-MSFT SteveL-MSFT marked this pull request as ready for review May 4, 2024 04:36
@michaeltlombardi michaeltlombardi added the Schema-Impact Change requires updating a canonical schema for configs or manifests label May 7, 2024
Copy link
Collaborator

@anmenaga anmenaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
}
// convert the buffer to a string
let include_content = match String::from_utf8(buffer) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me that we need to put somewhere in the docs, that input documents for dsc.exe have to be in UTF-8.
This is important for non-English users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

// combine the current directory with the Include path
Ok(Path::new(&current_directory).join(path))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the path in the include file is a fully-specified one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already handled on line 127 above

#[clap(short = 'l', long, help = "Trace level to use", value_enum, default_value = "warning")]
pub trace_level: TraceLevel,
#[clap(short = 'l', long, help = "Trace level to use", value_enum)]
pub trace_level: Option<TraceLevel>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment that default value will be assigned in the code as "warn".

@@ -37,15 +37,15 @@ Describe 'dsc config get tests' {
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo
type: Test/Echo
type: test/echo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change to lower case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was to explicitly test case-insensitivity and result is case preserving

for trace_line in stderr.lines() {
if let Result::Ok(json_obj) = serde_json::from_str::<Value>(trace_line) {
if let Some(msg) = json_obj.get("Error") {
error!("Process '{process_name}' id {process_id} : {}", msg.as_str().unwrap_or_default());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to make "Process '{process_name}' id {process_id} part shorter; with it trace lines are too long.
Maybe [<processname>:<procId>]: <text>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that in a follow-up PR along with handling the tracing crate JSON format

@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue May 10, 2024
Merged via the queue into PowerShell:main with commit 2fc0525 May 10, 2024
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the include branch May 10, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Doc-Impact Schema-Impact Change requires updating a canonical schema for configs or manifests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IncludeGroup to include an external configuration
3 participants