From b8449743a2cf8aa16c61b394b4efca411a7e8259 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Wed, 18 Sep 2024 16:53:10 -0700 Subject: [PATCH] Change `Echo` test resource to `Microsoft.DSC.Debug/Echo` resource --- .vscode/settings.json | 6 +- build.ps1 | 7 + dsc/examples/groups.dsc.yaml | 10 +- dsc/examples/multiline.dsc.yaml | 4 +- dsc/examples/osinfo_parameters.dsc.yaml | 2 +- dsc/examples/reference.dsc.yaml | 2 +- dsc/examples/secure_parameters.dsc.yaml | 4 +- dsc/examples/variables.dsc.yaml | 2 +- dsc/tests/dsc_args.tests.ps1 | 2 +- dsc/tests/dsc_config_get.tests.ps1 | 4 +- dsc/tests/dsc_expressions.tests.ps1 | 4 +- dsc/tests/dsc_functions.tests.ps1 | 2 +- dsc/tests/dsc_group.tests.ps1 | 8 +- dsc/tests/dsc_include.tests.ps1 | 8 +- dsc/tests/dsc_parameters.tests.ps1 | 24 +- dsc/tests/dsc_schema.tests.ps1 | 2 +- dsc/tests/dsc_test.tests.ps1 | 2 +- dsc/tests/dsc_variables.tests.ps1 | 4 +- dsc/tests/dsc_whatif.tests.ps1 | 2 +- dscecho/Cargo.lock | 354 ++++++++++++++++++ dscecho/Cargo.toml | 10 + .../echo.dsc.resource.json | 20 +- dscecho/src/args.rs | 11 + {tools/dsctest => dscecho}/src/echo.rs | 0 dscecho/src/main.rs | 35 ++ tools/dsctest/src/args.rs | 7 - tools/dsctest/src/main.rs | 15 - 27 files changed, 471 insertions(+), 80 deletions(-) create mode 100644 dscecho/Cargo.lock create mode 100644 dscecho/Cargo.toml rename tools/dsctest/dscecho.dsc.resource.json => dscecho/echo.dsc.resource.json (64%) create mode 100644 dscecho/src/args.rs rename {tools/dsctest => dscecho}/src/echo.rs (100%) create mode 100644 dscecho/src/main.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 95742eed..54f38dc4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "rust-analyzer.linkedProjects": [ "./dsc/Cargo.toml", "./dsc_lib/Cargo.toml", + "./echo/Cargo.toml", "./osinfo/Cargo.toml", "./registry/Cargo.toml", "./runcommandonset/Cargo.toml", @@ -21,5 +22,8 @@ "schemas/2024/04/bundled/config/document.vscode.json": "**.dsc.{yaml,yml,config.yaml,config.yml}", "schemas/2024/04/bundled/resource/manifest.vscode.json": "**.dsc.resource.{yaml,yml}" }, - "sarif-viewer.connectToGithubCodeScanning": "off" + "sarif-viewer.connectToGithubCodeScanning": "off", + "vscode-nmake-tools.workspaceBuildDirectories": [ + "." + ] } \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 16520484..b3ab7ed1 100644 --- a/build.ps1 +++ b/build.ps1 @@ -28,6 +28,8 @@ if ($GetPackageVersion) { $filesForWindowsPackage = @( 'dsc.exe', + 'dscecho.exe', + 'echo.dsc.resource.json', 'assertion.dsc.resource.json', 'group.dsc.resource.json', 'powershell.dsc.resource.json', @@ -45,6 +47,8 @@ $filesForWindowsPackage = @( $filesForLinuxPackage = @( 'dsc', + 'dscecho', + 'echo.dsc.resource.json', 'assertion.dsc.resource.json', 'apt.dsc.resource.json', 'apt.dsc.resource.sh', @@ -57,6 +61,8 @@ $filesForLinuxPackage = @( $filesForMacPackage = @( 'dsc', + 'dscecho', + 'echo.dsc.resource.json', 'assertion.dsc.resource.json', 'brew.dsc.resource.json', 'brew.dsc.resource.sh', @@ -209,6 +215,7 @@ if (!$SkipBuild) { "security_context_lib", "dsc_lib", "dsc", + "dscecho", "osinfo", "powershell-adapter", "process", diff --git a/dsc/examples/groups.dsc.yaml b/dsc/examples/groups.dsc.yaml index f755e449..199923eb 100644 --- a/dsc/examples/groups.dsc.yaml +++ b/dsc/examples/groups.dsc.yaml @@ -10,7 +10,7 @@ resources: $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: Last - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: Last dependsOn: @@ -21,7 +21,7 @@ resources: $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: First - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: First - name: Nested Group @@ -30,12 +30,12 @@ resources: $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: Nested Second - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: Nested Second dependsOn: - - "[resourceId('Test/Echo','Nested First')]" + - "[resourceId('Microsoft.DSC.Debug/Echo','Nested First')]" - name: Nested First - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: Nested First diff --git a/dsc/examples/multiline.dsc.yaml b/dsc/examples/multiline.dsc.yaml index cefede6f..a67dadac 100644 --- a/dsc/examples/multiline.dsc.yaml +++ b/dsc/examples/multiline.dsc.yaml @@ -1,13 +1,13 @@ $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: test multi-line - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: | This is a 'multi-line' string. - name: test single-quote escaping - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[concat('This is a single-quote: ', '''')]" diff --git a/dsc/examples/osinfo_parameters.dsc.yaml b/dsc/examples/osinfo_parameters.dsc.yaml index 876b2b71..396471b4 100644 --- a/dsc/examples/osinfo_parameters.dsc.yaml +++ b/dsc/examples/osinfo_parameters.dsc.yaml @@ -18,6 +18,6 @@ resources: properties: family: macOS - name: path - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[envvar('PATH')]" diff --git a/dsc/examples/reference.dsc.yaml b/dsc/examples/reference.dsc.yaml index 6591adba..e830741d 100644 --- a/dsc/examples/reference.dsc.yaml +++ b/dsc/examples/reference.dsc.yaml @@ -5,7 +5,7 @@ resources: type: Microsoft/OSInfo properties: {} - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[concat('The OS is ', reference(resourceId('Microsoft/OSInfo','os')).actualState.family)]" dependsOn: diff --git a/dsc/examples/secure_parameters.dsc.yaml b/dsc/examples/secure_parameters.dsc.yaml index b88e6803..4a7c17c5 100644 --- a/dsc/examples/secure_parameters.dsc.yaml +++ b/dsc/examples/secure_parameters.dsc.yaml @@ -6,10 +6,10 @@ parameters: type: secureObject resources: - name: Echo 1 - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[parameters('myString')]" - name: Echo 2 - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[parameters('myObject').myProperty]" diff --git a/dsc/examples/variables.dsc.yaml b/dsc/examples/variables.dsc.yaml index 9b70dade..53b472ce 100644 --- a/dsc/examples/variables.dsc.yaml +++ b/dsc/examples/variables.dsc.yaml @@ -10,6 +10,6 @@ variables: test: baz resources: - name: test - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[concat('myOutput is: ', variables('myOutput'), ', myObject is: ', variables('myObject').test)]" diff --git a/dsc/tests/dsc_args.tests.ps1 b/dsc/tests/dsc_args.tests.ps1 index 2019fe14..70752a40 100644 --- a/dsc/tests/dsc_args.tests.ps1 +++ b/dsc/tests/dsc_args.tests.ps1 @@ -65,7 +65,7 @@ Describe 'config argument tests' { '@ } ) { param($text) - $output = $text | dsc resource get -r Test/Echo + $output = $text | dsc resource get -r Microsoft.DSC.Debug/Echo $output = $output | ConvertFrom-Json $output.actualState.output | Should -BeExactly 'Hello There' } diff --git a/dsc/tests/dsc_config_get.tests.ps1 b/dsc/tests/dsc_config_get.tests.ps1 index 6016835c..b1e4a586 100644 --- a/dsc/tests/dsc_config_get.tests.ps1 +++ b/dsc/tests/dsc_config_get.tests.ps1 @@ -37,7 +37,7 @@ 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: Microsoft.DSC.Debug/Echo properties: output: hello "@ @@ -45,7 +45,7 @@ Describe 'dsc config get tests' { $result.hadErrors | Should -BeFalse $result.results.Count | Should -Be 1 $result.results[0].Name | Should -Be 'Echo' - $result.results[0].type | Should -BeExactly 'test/echo' + $result.results[0].type | Should -BeExactly 'Microsoft.DSC.Debug/Echo' $result.results[0].result.actualState.output | Should -Be 'hello' $result.metadata.'Microsoft.DSC'.version | Should -BeLike '3.*' $result.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'Get' diff --git a/dsc/tests/dsc_expressions.tests.ps1 b/dsc/tests/dsc_expressions.tests.ps1 index 02425b79..7cc765d3 100644 --- a/dsc/tests/dsc_expressions.tests.ps1 +++ b/dsc/tests/dsc_expressions.tests.ps1 @@ -37,7 +37,7 @@ parameters: value: 3 resources: - name: echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "$text" "@ @@ -58,7 +58,7 @@ resources: `$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "$expression" "@ diff --git a/dsc/tests/dsc_functions.tests.ps1 b/dsc/tests/dsc_functions.tests.ps1 index c625b008..53db473a 100644 --- a/dsc/tests/dsc_functions.tests.ps1 +++ b/dsc/tests/dsc_functions.tests.ps1 @@ -17,7 +17,7 @@ Describe 'tests for function expressions' { `$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '$escapedText' "@ diff --git a/dsc/tests/dsc_group.tests.ps1 b/dsc/tests/dsc_group.tests.ps1 index 90c89780..e549c1e4 100644 --- a/dsc/tests/dsc_group.tests.ps1 +++ b/dsc/tests/dsc_group.tests.ps1 @@ -26,7 +26,7 @@ results: Microsoft.DSC: duration: * name: First - type: Test/Echo + type: Microsoft.DSC.Debug/Echo result: actualState: output: First @@ -40,7 +40,7 @@ results: Microsoft.DSC: duration: * name: Nested First - type: Test/Echo + type: Microsoft.DSC.Debug/Echo result: actualState: output: Nested First @@ -48,7 +48,7 @@ results: Microsoft.DSC: duration: * name: Nested Second - type: Test/Echo + type: Microsoft.DSC.Debug/Echo result: actualState: output: Nested Second @@ -62,7 +62,7 @@ results: Microsoft.DSC: duration: * name: Last - type: Test/Echo + type: Microsoft.DSC.Debug/Echo result: actualState: output: Last diff --git a/dsc/tests/dsc_include.tests.ps1 b/dsc/tests/dsc_include.tests.ps1 index 1f6a2c3e..5fc1df6d 100644 --- a/dsc/tests/dsc_include.tests.ps1 +++ b/dsc/tests/dsc_include.tests.ps1 @@ -128,7 +128,7 @@ Describe 'Include tests' { $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: one - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: one '@ @@ -171,7 +171,7 @@ resources: $out.results[1].result[0].name | Should -Be 'nested' $out.results[1].result[0].type | Should -Be 'Microsoft.DSC/Include' $out.results[1].result[0].result.actualState.name | Should -Be 'one' - $out.results[1].result[0].result.actualState.type | Should -Be 'Test/Echo' + $out.results[1].result[0].result.actualState.type | Should -Be 'Microsoft.DSC.Debug/Echo' $out.results[1].result[0].result.actualState.result.actualState.output | Should -Be 'one' } @@ -180,7 +180,7 @@ resources: $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json resources: - name: one - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: Hello World '@ @@ -204,7 +204,7 @@ resources: $out = dsc config set -d $includeConfig | ConvertFrom-Json $LASTEXITCODE | Should -Be 0 $out.results[0].result.beforeState[0].name | Should -Be 'one' - $out.results[0].result.beforeState[0].type | Should -Be 'Test/Echo' + $out.results[0].result.beforeState[0].type | Should -Be 'Microsoft.DSC.Debug/Echo' $out.results[0].result.afterState[0].result.afterState.output | Should -Be 'Hello World' $out.hadErrors | Should -Be $false } diff --git a/dsc/tests/dsc_parameters.tests.ps1 b/dsc/tests/dsc_parameters.tests.ps1 index cd6586fc..3ece6180 100644 --- a/dsc/tests/dsc_parameters.tests.ps1 +++ b/dsc/tests/dsc_parameters.tests.ps1 @@ -15,7 +15,7 @@ Describe 'Parameters tests' { type: string resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -49,7 +49,7 @@ Describe 'Parameters tests' { type: $type resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -75,7 +75,7 @@ Describe 'Parameters tests' { type: $type resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -103,7 +103,7 @@ Describe 'Parameters tests' { maxLength: 3 resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -130,7 +130,7 @@ Describe 'Parameters tests' { maxValue: $max resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -155,7 +155,7 @@ Describe 'Parameters tests' { allowedValues: $($allowed | ConvertTo-Json -Compress) resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -182,7 +182,7 @@ Describe 'Parameters tests' { ${constraint}: 3 resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param1'')]' "@ @@ -211,19 +211,19 @@ Describe 'Parameters tests' { defaultValue: ['hello', 'world'] resources: - name: String - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''paramString'')]' - name: Int - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''paramInt'')]' - name: Bool - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''paramBool'')]' - name: Array - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''paramArray'')]' "@ @@ -299,7 +299,7 @@ Describe 'Parameters tests' { type: $type resources: - name: Echo - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: '[parameters(''param'')]' "@ diff --git a/dsc/tests/dsc_schema.tests.ps1 b/dsc/tests/dsc_schema.tests.ps1 index 1bcef876..65536a10 100644 --- a/dsc/tests/dsc_schema.tests.ps1 +++ b/dsc/tests/dsc_schema.tests.ps1 @@ -30,7 +30,7 @@ Describe 'config schema tests' { } It 'can accept the use of --format as a subcommand' { - $schema = dsc resource schema -r Test/Echo -f pretty-json + $schema = dsc resource schema -r Microsoft.DSC.Debug/Echo -f pretty-json $LASTEXITCODE | Should -Be 0 $schema | Should -Not -BeNullOrEmpty $schema = $schema | ConvertFrom-Json diff --git a/dsc/tests/dsc_test.tests.ps1 b/dsc/tests/dsc_test.tests.ps1 index 35999f48..037e9c42 100644 --- a/dsc/tests/dsc_test.tests.ps1 +++ b/dsc/tests/dsc_test.tests.ps1 @@ -55,7 +55,7 @@ Describe 'resource test tests' { } It 'can accept the use of --format as a subcommand' { - $null = "output: hello" | dsc resource test -r Test/Echo --format pretty-json + $null = "output: hello" | dsc resource test -r Microsoft.DSC.Debug/Echo --format pretty-json $LASTEXITCODE | Should -Be 0 } } diff --git a/dsc/tests/dsc_variables.tests.ps1 b/dsc/tests/dsc_variables.tests.ps1 index 48b4999a..8a983249 100644 --- a/dsc/tests/dsc_variables.tests.ps1 +++ b/dsc/tests/dsc_variables.tests.ps1 @@ -17,7 +17,7 @@ variables: myVariable: bar resources: - name: test - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[variables('myVariable')]" '@ @@ -34,7 +34,7 @@ variables: hello: world resources: - name: test - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: "[variables('myVariable')]" '@ diff --git a/dsc/tests/dsc_whatif.tests.ps1 b/dsc/tests/dsc_whatif.tests.ps1 index 9eb0a073..3795c9fa 100644 --- a/dsc/tests/dsc_whatif.tests.ps1 +++ b/dsc/tests/dsc_whatif.tests.ps1 @@ -10,7 +10,7 @@ Describe 'whatif tests' { `$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json resources: - name: Hello - type: Test/Echo + type: Microsoft.DSC.Debug/Echo properties: output: hello "@ diff --git a/dscecho/Cargo.lock b/dscecho/Cargo.lock new file mode 100644 index 00000000..aafb786b --- /dev/null +++ b/dscecho/Cargo.lock @@ -0,0 +1,354 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "dscecho" +version = "1.0.0" +dependencies = [ + "clap", + "schemars", + "serde", + "serde_json", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "indexmap", + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/dscecho/Cargo.toml b/dscecho/Cargo.toml new file mode 100644 index 00000000..04a41cec --- /dev/null +++ b/dscecho/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "dscecho" +version = "1.0.0" +edition = "2021" + +[dependencies] +clap = { version = "4.1", features = ["derive"] } +schemars = { version = "0.8" } +serde = { version = "1.0", features = ["derive"] } +serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/tools/dsctest/dscecho.dsc.resource.json b/dscecho/echo.dsc.resource.json similarity index 64% rename from tools/dsctest/dscecho.dsc.resource.json rename to dscecho/echo.dsc.resource.json index e7b3d201..5f556894 100644 --- a/tools/dsctest/dscecho.dsc.resource.json +++ b/dscecho/echo.dsc.resource.json @@ -1,11 +1,10 @@ { "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json", - "type": "Test/Echo", - "version": "0.1.0", + "type": "Microsoft.DSC.Debug/Echo", + "version": "1.0.0", "get": { - "executable": "dsctest", + "executable": "dscecho", "args": [ - "echo", { "jsonInputArg": "--input", "mandatory": true @@ -13,9 +12,8 @@ ] }, "set": { - "executable": "dsctest", + "executable": "dscecho", "args": [ - "echo", { "jsonInputArg": "--input", "mandatory": true @@ -23,9 +21,8 @@ ] }, "test": { - "executable": "dsctest", + "executable": "dscecho", "args": [ - "echo", { "jsonInputArg": "--input", "mandatory": true @@ -34,12 +31,7 @@ }, "schema": { "command": { - "executable": "dsctest", - "args": [ - "schema", - "-s", - "echo" - ] + "executable": "dscecho" } } } diff --git a/dscecho/src/args.rs b/dscecho/src/args.rs new file mode 100644 index 00000000..fcca1ce4 --- /dev/null +++ b/dscecho/src/args.rs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use clap::Parser; + +#[derive(Debug, Parser)] +#[clap(name = "dscecho", version = "1.0.0", about = "Debugging helper resource that echos the input.", long_about = None)] +pub struct Args { + #[clap(short, long, help = "The input to the echo command as JSON. If no input is provided the JSON schema for the input is returned.")] + pub input: Option, +} diff --git a/tools/dsctest/src/echo.rs b/dscecho/src/echo.rs similarity index 100% rename from tools/dsctest/src/echo.rs rename to dscecho/src/echo.rs diff --git a/dscecho/src/main.rs b/dscecho/src/main.rs new file mode 100644 index 00000000..ac823683 --- /dev/null +++ b/dscecho/src/main.rs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +mod args; +mod echo; + +use args::Args; +use clap::Parser; +use schemars::schema_for; +use crate::echo::Echo; + +fn main() { + let args = Args::parse(); + match args.input { + Some(input) => { + let echo = match serde_json::from_str::(&input) { + Ok(echo) => echo, + Err(err) => { + eprintln!("Error JSON does not match schema: {err}"); + std::process::exit(1); + } + }; + let json = serde_json::to_string(&echo).unwrap(); + println!("{json}"); + return; + }, + None => { + eprintln!("No input provided."); + } + } + + let schema = schema_for!(Echo); + let json = serde_json::to_string_pretty(&schema).unwrap(); + println!("{json}"); +} diff --git a/tools/dsctest/src/args.rs b/tools/dsctest/src/args.rs index e394a8a8..17127461 100644 --- a/tools/dsctest/src/args.rs +++ b/tools/dsctest/src/args.rs @@ -6,7 +6,6 @@ use clap::{Parser, Subcommand, ValueEnum}; #[derive(Debug, Clone, PartialEq, Eq, ValueEnum)] pub enum Schemas { Delete, - Echo, Exist, ExitCode, Sleep, @@ -30,12 +29,6 @@ pub enum SubCommand { input: String, }, - #[clap(name = "echo", about = "Return the input")] - Echo { - #[clap(name = "input", short, long, help = "The input to the echo command as JSON")] - input: String, - }, - #[clap(name = "exist", about = "Check if a resource exists")] Exist { #[clap(name = "input", short, long, help = "The input to the exist command as JSON")] diff --git a/tools/dsctest/src/main.rs b/tools/dsctest/src/main.rs index 91760736..400fa2ad 100644 --- a/tools/dsctest/src/main.rs +++ b/tools/dsctest/src/main.rs @@ -3,7 +3,6 @@ mod args; mod delete; -mod echo; mod exist; mod exit_code; mod sleep; @@ -14,7 +13,6 @@ use args::{Args, Schemas, SubCommand}; use clap::Parser; use schemars::schema_for; use crate::delete::Delete; -use crate::echo::Echo; use crate::exist::{Exist, State}; use crate::exit_code::ExitCode; use crate::sleep::Sleep; @@ -37,16 +35,6 @@ fn main() { delete.delete_called = Some(true); serde_json::to_string(&delete).unwrap() }, - SubCommand::Echo { input } => { - let echo = match serde_json::from_str::(&input) { - Ok(echo) => echo, - Err(err) => { - eprintln!("Error JSON does not match schema: {err}"); - std::process::exit(1); - } - }; - serde_json::to_string(&echo).unwrap() - }, SubCommand::Exist { input } => { let mut exist = match serde_json::from_str::(&input) { Ok(exist) => exist, @@ -82,9 +70,6 @@ fn main() { Schemas::Delete => { schema_for!(Delete) }, - Schemas::Echo => { - schema_for!(Echo) - }, Schemas::Exist => { schema_for!(Exist) },