Skip to content

Commit e9ec9d5

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
Change secret extensions to emit secret without JSON wrapping
1 parent 7a0bda5 commit e9ec9d5

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

dsc_lib/src/extensions/dscextension.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ use schemars::JsonSchema;
99
use std::{fmt::Display, path::Path};
1010
use tracing::{debug, info, trace};
1111

12-
use crate::{discovery::command_discovery::{load_manifest, ImportedManifest}, dscerror::DscError, dscresources::{command_resource::{invoke_command, process_args}, dscresource::DscResource}, extensions::{import::ImportArgKind, secret::SecretResult}};
12+
use crate::{
13+
discovery::command_discovery::{
14+
load_manifest, ImportedManifest
15+
},
16+
dscerror::DscError,
17+
dscresources::{
18+
command_resource::{
19+
invoke_command,
20+
process_args
21+
},
22+
dscresource::DscResource
23+
},
24+
extensions::import::ImportArgKind
25+
};
1326

1427
use super::{discover::DiscoverResult, extension_manifest::ExtensionManifest, secret::SecretArgKind};
1528

@@ -232,18 +245,8 @@ impl DscExtension {
232245
info!("{}", t!("extensions.dscextension.secretNoResults", extension = self.type_name));
233246
Ok(None)
234247
} else {
235-
let result: SecretResult = match serde_json::from_str(&stdout) {
236-
Ok(value) => value,
237-
Err(err) => {
238-
return Err(DscError::Extension(t!("extensions.dscextension.secretExtensionReturnedInvalidJson", extension = self.type_name, error = err).to_string()));
239-
}
240-
};
241-
if result.secure_string.is_some() {
242-
debug!("{}", t!("extensions.dscextension.extensionReturnedSecret", extension = self.type_name));
243-
} else {
244-
debug!("{}", t!("extensions.dscextension.extensionReturnedNoSecret", extension = self.type_name));
245-
}
246-
Ok(result.secure_string)
248+
debug!("{}", t!("extensions.dscextension.extensionReturnedSecret", extension = self.type_name));
249+
Ok(Some(stdout))
247250
}
248251
} else {
249252
Err(DscError::UnsupportedCapability(

dsc_lib/src/extensions/secret.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,3 @@ pub struct SecretMethod {
3030
/// The arguments to pass to the command to perform a Get.
3131
pub args: Option<Vec<SecretArgKind>>,
3232
}
33-
34-
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
35-
pub struct SecretResult {
36-
#[serde(rename = "secureString")]
37-
pub secure_string: Option<String>,
38-
}

extensions/bicep/bicep.dsc.extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
2+
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/extension/manifest.json",
33
"type": "Microsoft.DSC.Extension/Bicep",
44
"version": "0.1.0",
55
"description": "Enable passing Bicep file directly to DSC, but requires bicep executable to be available.",

extensions/test/secret/secret.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ function get-secret($hashtable, $name, $vault) {
4343
return $null
4444
}
4545

46-
$secret = if ($Second) {
46+
if ($Second) {
4747
get-secret -hashtable $secretTwo -name $Name -vault $Vault
4848
} else {
4949
get-secret -hashtable $secretsOne -name $Name -vault $Vault
5050
}
51-
52-
@{ secureString = $secret } | ConvertTo-Json -Compress | Write-Output

extensions/test/secret/testSecret.dsc.extension.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
2+
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/extension/manifest.json",
33
"type": "Test/Secret",
44
"version": "0.1.0",
5-
"description": "Example secret resource for testing.",
5+
"description": "Example secret extension for testing.",
66
"secret": {
77
"executable": "pwsh",
88
"args": [

extensions/test/secret/testSecret2.dsc.extension.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
2+
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/extension/manifest.json",
33
"type": "Test/Secret2",
44
"version": "0.1.0",
5-
"description": "Duplicate secret resource for testing.",
5+
"description": "Duplicate secret extension for testing.",
66
"secret": {
77
"executable": "pwsh",
88
"args": [

0 commit comments

Comments
 (0)