Skip to content

Commit 33ab856

Browse files
committed
modify export behavior
1 parent 11702a0 commit 33ab856

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

dsc/tests/dsc_sshdconfig.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ resources:
9696
if ($command -eq 'export') {
9797
$out.resources.count | Should -Be 1
9898
$out.resources[0].properties.loglevel | Should -Be 'debug3'
99-
$out.resources[0].properties._inheritedDefaults | Should -Contain 'port'
99+
$out.resources[0].properties.port | Should -Be 22
100+
$out.resources[0].properties._inheritedDefaults | Should -BeNullOrEmpty
100101
} else {
101102
$out.results.count | Should -Be 1
102103
($out.results.result.actualState.psobject.properties | Measure-Object).count | Should -Be 2

sshdconfig/src/get.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn invoke_get(input: Option<&String>, setting: &Setting) -> Result<Map<Strin
3333
match *setting {
3434
Setting::SshdConfig => {
3535
let cmd_info = build_command_info(input, true)?;
36-
get_sshd_settings(&cmd_info)
36+
get_sshd_settings(&cmd_info, true)
3737
},
3838
Setting::WindowsGlobal => {
3939
get_default_shell()?;
@@ -102,12 +102,12 @@ fn get_default_shell() -> Result<(), SshdConfigError> {
102102
///
103103
/// # Arguments
104104
///
105-
/// * `cmd_info` - CommandInfo struct containing optional filters, metadata, and includeDefaults flag.
105+
/// * `cmd_info` - `CommandInfo` struct containing optional filters, metadata, and includeDefaults flag.
106106
///
107107
/// # Errors
108108
///
109109
/// This function will return an error if it cannot retrieve the sshd settings.
110-
pub fn get_sshd_settings(cmd_info: &CommandInfo) -> Result<Map<String, Value>, SshdConfigError> {
110+
pub fn get_sshd_settings(cmd_info: &CommandInfo, is_get: bool) -> Result<Map<String, Value>, SshdConfigError> {
111111
let sshd_config_text = invoke_sshd_config_validation(cmd_info.sshd_args.clone())?;
112112
let mut result = parse_text_to_map(&sshd_config_text)?;
113113
let mut inherited_defaults: Vec<String> = Vec::new();
@@ -161,7 +161,7 @@ pub fn get_sshd_settings(cmd_info: &CommandInfo) -> Result<Map<String, Value>, S
161161
if cmd_info.metadata.filepath.is_some() {
162162
result.insert("_metadata".to_string(), serde_json::to_value(cmd_info.metadata.clone())?);
163163
}
164-
if cmd_info.include_defaults {
164+
if cmd_info.include_defaults && is_get {
165165
result.insert("_inheritedDefaults".to_string(), serde_json::to_value(inherited_defaults)?);
166166
}
167167
Ok(result)

sshdconfig/src/inputs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub struct CommandInfo {
1919

2020
impl CommandInfo {
2121
/// Create a new `CommandInfo` instance.
22-
pub fn new(is_get: bool) -> Self {
22+
pub fn new(include_defaults: bool) -> Self {
2323
Self {
24-
include_defaults: is_get,
24+
include_defaults,
2525
input: Map::new(),
2626
metadata: Metadata::new(),
2727
sshd_args: None

sshdconfig/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
let result = match &args.command {
3737
Command::Export { input } => {
3838
match build_command_info(input.as_ref(), false) {
39-
Ok(cmd_info) => get_sshd_settings(&cmd_info),
39+
Ok(cmd_info) => get_sshd_settings(&cmd_info, false),
4040
Err(e) => Err(e),
4141
}
4242
},

0 commit comments

Comments
 (0)