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

fix build and add resource type to command error #52

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else {
}

$windows_projects = @("ntreg","ntstatuserror","ntuserinfo","registry")
$projects = @("dsc","osinfo","y2j")
$projects = @("dsc","osinfo","y2j")
if ($IsWindows) {
$projects += $windows_projects
}
Expand Down Expand Up @@ -54,15 +54,9 @@ foreach ($project in $projects) {
Copy-Item "$path/$project" $target -ErrorAction Ignore
}

if (Test-Path "$project.resource.json") {
Copy-Item "$project.resource.json" $target -ErrorAction Ignore
}

if (Test-Path "$project.command.json") {
Copy-Item "$project.command.json" $target -ErrorAction Ignore
}
Copy-Item "*.resource.json" $target -Force -ErrorAction Ignore
Copy-Item "*.command.json" $target -Force -ErrorAction Ignore

Copy-Item *.command.json $target
} finally {
Pop-Location
}
Expand Down Expand Up @@ -107,7 +101,7 @@ if ($Test) {
try {
Push-Location "$PSScriptRoot/$project"
cargo test

if ($LASTEXITCODE -ne 0) {
$failed = $true
}
Expand Down
12 changes: 12 additions & 0 deletions dsc/examples/osinfo.dsc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schemas.microsoft.com/dsc/2023/03/configuration.schema.json",
"resources": [
{
"name": "os",
"type": "Microsoft/OSInfo",
"properties": {
"family": "Windows"
}
}
]
}
4 changes: 2 additions & 2 deletions dsc_lib/src/dscerror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum DscError {
#[error("Command: [{0}] {1}")]
Command(i32, String),
#[error("Command: Resource '{0}' [Exit code {1}] {2}")]
Command(String, i32, String),

#[error("HTTP: {0}")]
Http(#[from] reqwest::Error),
Expand Down
10 changes: 5 additions & 5 deletions dsc_lib/src/dscresources/command_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn invoke_get(resource: &ResourceManifest, filter: &str) -> Result<GetResult

let (exit_code, stdout, stderr) = invoke_command(&resource.get.executable, resource.get.args.clone().unwrap_or_default(), Some(filter))?;
if exit_code != 0 {
return Err(DscError::Command(exit_code, stderr.to_string()));
return Err(DscError::Command(resource.resource_type.clone(), exit_code, stderr.to_string()));
}

let result: Value = serde_json::from_str(&stdout)?;
Expand Down Expand Up @@ -46,15 +46,15 @@ pub fn invoke_set(resource: &ResourceManifest, desired: &str) -> Result<SetResul
let pre_state: Value;
let (exit_code, stdout, stderr) = invoke_command(&resource.get.executable, resource.get.args.clone().unwrap_or_default(), Some(desired))?;
if exit_code != 0 {
return Err(DscError::Command(exit_code, stderr.to_string()));
return Err(DscError::Command(resource.resource_type.clone(), exit_code, stderr.to_string()));
}
else {
pre_state = serde_json::from_str(&stdout)?;
}

let (exit_code, stdout, stderr) = invoke_command(&set.executable, set.args.clone().unwrap_or_default(), Some(desired))?;
if exit_code != 0 {
return Err(DscError::Command(exit_code, stderr.to_string()));
return Err(DscError::Command(resource.resource_type.clone(), exit_code, stderr.to_string()));
}

match set.returns {
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn invoke_test(resource: &ResourceManifest, expected: &str) -> Result<TestRe
let test = resource.test.as_ref().unwrap();
let (exit_code, stdout, stderr) = invoke_command(&test.executable, test.args.clone().unwrap_or_default(), Some(expected))?;
if exit_code != 0 {
return Err(DscError::Command(exit_code, stderr.to_string()));
return Err(DscError::Command(resource.resource_type.clone(), exit_code, stderr.to_string()));
}

let expected_value: Value = serde_json::from_str(expected)?;
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn get_schema(resource: &ResourceManifest) -> Result<String, DscError> {
SchemaKind::Command(ref command) => {
let (exit_code, stdout, stderr) = invoke_command(&command.executable, command.args.clone().unwrap_or_default(), None)?;
if exit_code != 0 {
return Err(DscError::Command(exit_code, stderr.to_string()));
return Err(DscError::Command(resource.resource_type.clone(), exit_code, stderr.to_string()));
}
Ok(stdout)
},
Expand Down