@@ -8,7 +8,7 @@ use schemars::JsonSchema;
8
8
use std:: { fmt:: Display , path:: Path } ;
9
9
use tracing:: { debug, info, trace} ;
10
10
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 } ;
12
12
13
13
use super :: { discover:: DiscoverResult , extension_manifest:: ExtensionManifest , secret:: SecretArgKind } ;
14
14
@@ -129,7 +129,21 @@ impl DscExtension {
129
129
}
130
130
}
131
131
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 > {
133
147
if self . capabilities . contains ( & Capability :: Secret ) {
134
148
let extension = match serde_json:: from_value :: < ExtensionManifest > ( self . manifest . clone ( ) ) {
135
149
Ok ( manifest) => manifest,
@@ -151,12 +165,15 @@ impl DscExtension {
151
165
) ?;
152
166
if stdout. is_empty ( ) {
153
167
info ! ( "{}" , t!( "extensions.dscextension.secretNoResults" , extension = self . type_name) ) ;
154
- Ok ( Value :: Null )
168
+ Ok ( None )
155
169
} 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 ) )
160
177
}
161
178
} else {
162
179
Err ( DscError :: UnsupportedCapability (
0 commit comments