@@ -8,7 +8,7 @@ use schemars::JsonSchema;
88use std:: { fmt:: Display , path:: Path } ;
99use tracing:: { debug, info, trace} ;
1010
11- use crate :: { discovery:: command_discovery:: { load_manifest, ImportedManifest } , dscerror:: DscError , dscresources:: { command_resource:: { invoke_command, process_args} , dscresource:: DscResource } } ;
11+ use crate :: { discovery:: command_discovery:: { load_manifest, ImportedManifest } , dscerror:: DscError , dscresources:: { command_resource:: { invoke_command, process_args} , dscresource:: DscResource } , extensions :: secret :: SecretResult } ;
1212
1313use super :: { discover:: DiscoverResult , extension_manifest:: ExtensionManifest , secret:: SecretArgKind } ;
1414
@@ -129,7 +129,21 @@ impl DscExtension {
129129 }
130130 }
131131
132- pub fn secret ( & self , name : & str , vault : Option < & str > ) -> Result < Value , DscError > {
132+ /// Retrieve a secret using the extension.
133+ ///
134+ /// # Arguments
135+ ///
136+ /// * `name` - The name of the secret to retrieve.
137+ /// * `vault` - An optional vault name to use for the secret.
138+ ///
139+ /// # Returns
140+ ///
141+ /// A result containing the secret as a string or an error.
142+ ///
143+ /// # Errors
144+ ///
145+ /// This function will return an error if the secret retrieval fails or if the extension does not support the secret capability.
146+ pub fn secret ( & self , name : & str , vault : Option < & str > ) -> Result < Option < String > , DscError > {
133147 if self . capabilities . contains ( & Capability :: Secret ) {
134148 let extension = match serde_json:: from_value :: < ExtensionManifest > ( self . manifest . clone ( ) ) {
135149 Ok ( manifest) => manifest,
@@ -151,12 +165,15 @@ impl DscExtension {
151165 ) ?;
152166 if stdout. is_empty ( ) {
153167 info ! ( "{}" , t!( "extensions.dscextension.secretNoResults" , extension = self . type_name) ) ;
154- Ok ( Value :: Null )
168+ Ok ( None )
155169 } else {
156- match serde_json:: from_str ( & stdout) {
157- Ok ( value) => Ok ( value) ,
158- Err ( err) => Err ( DscError :: Json ( err) ) ,
159- }
170+ let result: SecretResult = match serde_json:: from_str ( & stdout) {
171+ Ok ( value) => value,
172+ Err ( err) => {
173+ return Err ( DscError :: Json ( err) ) ;
174+ }
175+ } ;
176+ Ok ( Some ( result. secret ) )
160177 }
161178 } else {
162179 Err ( DscError :: UnsupportedCapability (
0 commit comments