Skip to content

Commit ff1ae6f

Browse files
author
Andrew
committed
feedback 1
1 parent b32ac65 commit ff1ae6f

File tree

7 files changed

+38
-23
lines changed

7 files changed

+38
-23
lines changed

dsc/default_settings.v1.dsc.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"resource_path": {
3-
"allow_env_override": true,
4-
"append_env_path": true,
2+
"resourcePath": {
3+
"allowEnvOverride": true,
4+
"appendEnvPath": true,
55
"directories": []
66
},
77
"tracing": {
88
"level": "WARN",
99
"format": "Default",
10-
"allow_override": true
10+
"allowOverride": true
1111
}
1212
}

dsc/settings.dsc.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"resource_path": {
3-
"allow_env_override": true,
4-
"append_env_path": true,
2+
"resourcePath": {
3+
"allowEnvOverride": true,
4+
"appendEnvPath": true,
55
"directories": []
66
},
77
"tracing": {
88
"level": "WARN",
99
"format": "Default",
10-
"allow_override": true
10+
"allowOverride": true
1111
}
1212
}

dsc/src/util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use syntect::{
4141
parsing::SyntaxSet,
4242
util::{as_24_bit_terminal_escaped, LinesWithEndings}
4343
};
44-
use tracing::{Level, info, debug, error, warn, trace};
44+
use tracing::{Level, debug, error, info, warn, trace};
4545
use tracing_subscriber::{filter::EnvFilter, layer::SubscriberExt, Layer};
4646
use tracing_indicatif::IndicatifLayer;
4747

@@ -59,8 +59,12 @@ pub const DSC_TRACE_LEVEL: &str = "DSC_TRACE_LEVEL";
5959

6060
#[derive(Deserialize)]
6161
pub struct TracingSetting {
62+
/// Trace level to use - see pub enum TraceLevel in dsc_lib\src\dscresources\command_resource.rs
6263
level: TraceLevel,
64+
/// Trace format to use - see pub enum TraceFormat in dsc\src\args.rs
6365
format: TraceFormat,
66+
/// Whether the 'level' can be overrridden by DSC_TRACE_LEVEL environment variable
67+
#[serde(rename = "allowOverride")]
6468
allow_override: bool
6569
}
6670

dsc/tests/dsc_settings.tests.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Describe 'tests for dsc settings' {
77
$script:policyFilePath = if ($IsWindows) {
88
Join-Path $env:ProgramData "dsc" "settings.dsc.json"
99
} else {
10-
"/etc/.dsc/settings.dsc.json"
10+
"/etc/dsc/settings.dsc.json"
1111
}
1212

1313
$script:dscHome = (Get-Command dsc).Path | Split-Path
@@ -53,9 +53,12 @@ Describe 'tests for dsc settings' {
5353

5454
It 'ensure a new resource_path value in settings has effect' {
5555

56-
$script:dscDefaultv1SettingsJson.Replace('"directories": []', '"directories": ["TestDir"]') | Set-Content -Force -Path $script:dscSettingsFilePath
56+
$script:dscDefaultv1SettingsJson.Replace('"directories": []', '"directories": ["TestDir1","TestDir2"]') | Set-Content -Force -Path $script:dscSettingsFilePath
57+
copy-Item -Recurse -Force -Path $script:dscSettingsFilePath -Destination "C:\Temp\"
5758
dsc -l debug resource list 2> $TestDrive/tracing.txt
58-
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: "TestDir'
59+
copy-Item -Recurse -Force -Path $TestDrive/tracing.txt -Destination "C:\Temp\"
60+
$expectedString = 'Using Resource Path: "TestDir1'+[System.IO.Path]::PathSeparator+'TestDir2'
61+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly $expectedString
5962
}
6063

6164
It 'Confirm settings override priorities' {

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ pub struct CommandDiscovery {
3434

3535
#[derive(Deserialize)]
3636
pub struct ResourcePathSetting {
37+
/// whether to allow overriding with the DSC_RESOURCE_PATH environment variable
38+
#[serde(rename = "allowEnvOverride")]
3739
allow_env_override: bool,
40+
/// whether to append the PATH environment variable to the list of resource directories
41+
#[serde(rename = "appendEnvPath")]
3842
append_env_path: bool,
43+
/// array of directories that DSC should search for non-built-in resources
3944
directories: Vec<String>
4045
}
4146

@@ -60,26 +65,26 @@ impl CommandDiscovery {
6065

6166
fn get_resource_path_setting() -> Result<ResourcePathSetting, DscError>
6267
{
63-
if let Ok(v) = get_setting("resource_path") {
68+
if let Ok(v) = get_setting("resourcePath") {
6469
// if there is a policy value defined - use it; otherwise use setting value
6570
if v.policy != serde_json::Value::Null {
6671
match serde_json::from_value::<ResourcePathSetting>(v.policy) {
6772
Ok(v) => {
6873
return Ok(v);
6974
},
70-
Err(e) => { return Err(DscError::Operation(format!("{e}"))); }
75+
Err(e) => { return Err(DscError::Setting(format!("{e}"))); }
7176
}
7277
} else if v.setting != serde_json::Value::Null {
7378
match serde_json::from_value::<ResourcePathSetting>(v.setting) {
7479
Ok(v) => {
7580
return Ok(v);
7681
},
77-
Err(e) => { return Err(DscError::Operation(format!("{e}"))); }
82+
Err(e) => { return Err(DscError::Setting(format!("{e}"))); }
7883
}
7984
}
8085
}
8186

82-
Err(DscError::Operation("Could not read 'resource_path' setting".to_string()))
87+
Err(DscError::Setting("Could not read 'resourcePath' setting".to_string()))
8388
}
8489

8590
fn get_resource_paths() -> Result<Vec<PathBuf>, DscError>
@@ -112,7 +117,7 @@ impl CommandDiscovery {
112117
}
113118

114119
if resource_path_setting.append_env_path {
115-
trace!("Appending PATH to resource_path");
120+
debug!("Appending PATH to resourcePath");
116121
match env::var_os("PATH") {
117122
Some(value) => {
118123
trace!("Original PATH: {:?}", value.to_string_lossy());

dsc_lib/src/dscerror.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@ pub enum DscError {
117117

118118
#[error("YAML: {0}")]
119119
Yaml(#[from] serde_yaml::Error),
120+
121+
#[error("Setting: {0}")]
122+
Setting(String),
120123
}

dsc_lib/src/util.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use std::env;
1111
use tracing::debug;
1212

1313
pub struct DscSettingValue {
14-
pub setting: serde_json::Value,
15-
pub policy: serde_json::Value,
14+
pub setting: Value,
15+
pub policy: Value,
1616
}
1717

1818
impl Default for DscSettingValue {
1919
fn default() -> DscSettingValue {
2020
DscSettingValue {
21-
setting: serde_json::Value::Null,
22-
policy: serde_json::Value::Null,
21+
setting: Value::Null,
22+
policy: Value::Null,
2323
}
2424
}
2525
}
@@ -148,7 +148,7 @@ fn get_settings_policy_file_path() -> String
148148
#[cfg(not(target_os = "windows"))]
149149
fn get_settings_policy_file_path() -> String
150150
{
151-
// "/etc/.dsc/settings.dsc.json"
151+
// "/etc/dsc/settings.dsc.json"
152152
// This location is writable only by admins, but readable by all users
153-
Path::new("/etc").join(".dsc").join("settings.dsc.json").display().to_string()
153+
Path::new("/etc").join("dsc").join("settings.dsc.json").display().to_string()
154154
}

0 commit comments

Comments
 (0)