-
Notifications
You must be signed in to change notification settings - Fork 47
Add sshdconfig get #1004
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
Open
tgauth
wants to merge
21
commits into
PowerShell:main
Choose a base branch
from
tgauth:add-sshdconfig-get
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add sshdconfig get #1004
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d268733
add sshdcmdargs struct and method to retrieve defaults
tgauth ebe3308
add default option to get
tgauth f169871
cleanup get
tgauth b8356b2
fix merge conflicts
tgauth 0d65d5d
add e2e sshdconfig tests for get/export and update schema
tgauth 2e82fc7
cleanup get/export display
tgauth 812e1cc
update get to read _metadata
tgauth 8bf176d
support custom sshdconfig filepath for get tests
tgauth b881d7d
update toml
tgauth 894c9b0
add comment to struct
tgauth 011bd8c
fix clippy
tgauth db2d25a
fix skip logic
tgauth af54285
fix i8n
tgauth 4695d56
Revert "fix i8n"
tgauth 3acbbdd
fix i8n take 2
tgauth c72f6a5
fix i8n take 3
tgauth 484003c
use copilot suggestions
tgauth f5b619f
address Steve's feedback
tgauth 5e2ab58
Update en-us.toml
tgauth 85f9a7b
Merge branch 'main' into add-sshdconfig-get
tgauth 64e1dfc
add check for sshd in test discovery
tgauth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
BeforeDiscovery { | ||
if ($IsWindows) { | ||
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | ||
$principal = [System.Security.Principal.WindowsPrincipal]::new($identity) | ||
$isElevated = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) | ||
$sshdExists = ($null -ne (Get-Command sshd -CommandType Application -ErrorAction Ignore)) | ||
$skipTest = !$isElevated -or !$sshdExists | ||
} | ||
} | ||
|
||
Describe 'SSHDConfig resource tests' -Skip:(!$IsWindows -or $skipTest) { | ||
BeforeAll { | ||
$yaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
metadata: | ||
Microsoft.DSC: | ||
securityContext: elevated | ||
resources: | ||
- name: sshdconfig | ||
type: Microsoft.OpenSSH.SSHD/sshd_config | ||
properties: | ||
'@ | ||
# set a non-default value in a temporary sshd_config file | ||
"LogLevel Debug3" | Set-Content -Path $TestDrive/test_sshd_config | ||
} | ||
|
||
It 'Export works' { | ||
$out = dsc config export -i "$yaml" | ConvertFrom-Json -Depth 10 | ||
$LASTEXITCODE | Should -Be 0 | ||
$out.resources.count | Should -Be 1 | ||
$out.resources[0].properties | Should -Not -BeNullOrEmpty | ||
$out.resources[0].properties.port[0] | Should -Be 22 | ||
} | ||
|
||
It 'Get works'{ | ||
$out = dsc config get -i "$yaml" | ConvertFrom-Json -Depth 10 | ||
$LASTEXITCODE | Should -Be 0 | ||
$out.results.count | Should -Be 1 | ||
$out.results.metadata.includeDefaults | Should -Be $true | ||
$out.results.result.actualState | Should -Not -BeNullOrEmpty | ||
$out.results.result.actualState.port | Should -Be 22 | ||
$out.results.result.actualState.passwordAuthentication | Should -Be 'yes' | ||
} | ||
|
||
It 'Get with a specific setting works' { | ||
$get_yaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
metadata: | ||
Microsoft.DSC: | ||
securityContext: elevated | ||
resources: | ||
- name: sshdconfig | ||
type: Microsoft.OpenSSH.SSHD/sshd_config | ||
properties: | ||
passwordauthentication: 'no' | ||
'@ | ||
$out = dsc config get -i "$get_yaml" | ConvertFrom-Json -Depth 10 | ||
$LASTEXITCODE | Should -Be 0 | ||
$out.results.count | Should -Be 1 | ||
($out.results.result.actualState.psobject.properties | measure-object).count | Should -Be 1 | ||
$out.results.result.actualState.passwordauthentication | Should -Be 'yes' | ||
} | ||
|
||
It 'Get with defaults excluded works' { | ||
$filepath = Join-Path $TestDrive 'test_sshd_config' | ||
$get_yaml = @" | ||
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
metadata: | ||
Microsoft.DSC: | ||
securityContext: elevated | ||
resources: | ||
- name: sshdconfig | ||
type: Microsoft.OpenSSH.SSHD/sshd_config | ||
properties: | ||
_metadata: | ||
includeDefaults: false | ||
filepath: $filepath | ||
"@ | ||
$out = dsc config get -i "$get_yaml" | ConvertFrom-Json -Depth 10 | ||
$LASTEXITCODE | Should -Be 0 | ||
$out.results.count | Should -Be 1 | ||
$out.results.metadata.includeDefaults | Should -Be $false | ||
$out.results.result.actualState.count | Should -Be 1 | ||
$out.results.result.actualState.port | Should -Not -Be 22 | ||
$out.results.result.actualState.loglevel | Should -Be 'debug3' | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use serde_json::{Map, Value}; | ||
|
||
use crate::error::SshdConfigError; | ||
use crate::inputs::SshdCommandArgs; | ||
use crate::parser::parse_text_to_map; | ||
use crate::util::invoke_sshd_config_validation; | ||
|
||
/// Invoke the export command. | ||
/// Invoke the export command and return a map. | ||
/// | ||
/// # Errors | ||
/// | ||
/// This function will return an error if the command cannot invoke sshd -T, parse the return, or convert it to json. | ||
pub fn invoke_export() -> Result<(), SshdConfigError> { | ||
let sshd_config_text = invoke_sshd_config_validation()?; | ||
let sshd_config: serde_json::Map<String, serde_json::Value> = parse_text_to_map(&sshd_config_text)?; | ||
let json = serde_json::to_string(&sshd_config)?; | ||
println!("{json}"); | ||
Ok(()) | ||
/// | ||
/// # Returns | ||
/// | ||
/// This function will return `Ok(Map<String, Value>)` if the export is successful. | ||
pub fn invoke_export(sshd_args: Option<SshdCommandArgs>) -> Result<Map<String, Value>, SshdConfigError> { | ||
let sshd_config_text = invoke_sshd_config_validation(sshd_args)?; | ||
let sshd_config: Map<String, Value> = parse_text_to_map(&sshd_config_text)?; | ||
Ok(sshd_config) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.