44use clap:: Parser ;
55use dsc_lib:: {
66 configure:: config_doc:: ExecutionKind ,
7- dscresources:: { dscresource:: Invoke , invoke_result} ,
7+ dscresources:: {
8+ dscresource:: Invoke ,
9+ invoke_result:: { GetResult , SetResult } ,
10+ } ,
811 DscManager ,
912} ;
1013use std:: { env, fs, io, process} ;
@@ -43,24 +46,19 @@ impl BicepExtension for BicepExtensionService {
4346 return Err ( Status :: invalid_argument ( "Resource not found" ) ) ;
4447 } ;
4548
46- let result = match resource. set ( & properties, false , & ExecutionKind :: Actual ) {
47- Ok ( r) => match r {
48- invoke_result:: SetResult :: Resource ( set_result) => {
49- serde_json:: to_string ( & set_result. after_state ) . map_err ( |e| {
50- Status :: internal ( format ! ( "Failed to serialize actual state: {e}" ) )
51- } ) ?
52- }
53- _ => return Err ( Status :: unimplemented ( "Group resources not yet supported" ) ) ,
54- } ,
55- Err ( e) => return Err ( Status :: internal ( format ! ( "DSC set operation failed: {e}" ) ) ) ,
49+ let SetResult :: Resource ( result) = resource
50+ . set ( & properties, false , & ExecutionKind :: Actual )
51+ . map_err ( |e| Status :: internal ( format ! ( "DSC set operation failed: {e}" ) ) ) ?
52+ else {
53+ return Err ( Status :: unimplemented ( "Group resources not supported" ) ) ;
5654 } ;
5755
5856 Ok ( Response :: new ( LocalExtensibilityOperationResponse {
5957 resource : Some ( proto:: Resource {
6058 r#type : resource_type,
6159 api_version : version,
6260 identifiers : properties,
63- properties : result,
61+ properties : result. after_state . to_string ( ) ,
6462 status : None ,
6563 } ) ,
6664 error_data : None ,
@@ -83,28 +81,19 @@ impl BicepExtension for BicepExtensionService {
8381 return Err ( Status :: invalid_argument ( "Resource not found" ) ) ;
8482 } ;
8583
86- let result = match resource. set ( & properties, false , & ExecutionKind :: WhatIf ) {
87- Ok ( r) => match r {
88- invoke_result:: SetResult :: Resource ( set_result) => {
89- serde_json:: to_string ( & set_result. after_state ) . map_err ( |e| {
90- Status :: internal ( format ! ( "Failed to serialize actual state: {e}" ) )
91- } ) ?
92- }
93- _ => return Err ( Status :: unimplemented ( "Group resources not yet supported" ) ) ,
94- } ,
95- Err ( e) => {
96- return Err ( Status :: internal ( format ! (
97- "DSC whatif operation failed: {e}"
98- ) ) )
99- }
84+ let SetResult :: Resource ( result) = resource
85+ . set ( & properties, false , & ExecutionKind :: WhatIf )
86+ . map_err ( |e| Status :: internal ( format ! ( "DSC whatif operation failed: {e}" ) ) ) ?
87+ else {
88+ return Err ( Status :: unimplemented ( "Group resources not supported" ) ) ;
10089 } ;
10190
10291 Ok ( Response :: new ( LocalExtensibilityOperationResponse {
10392 resource : Some ( proto:: Resource {
10493 r#type : resource_type,
10594 api_version : version,
10695 identifiers : properties,
107- properties : result,
96+ properties : result. after_state . to_string ( ) ,
10897 status : None ,
10998 } ) ,
11099 error_data : None ,
@@ -128,24 +117,19 @@ impl BicepExtension for BicepExtensionService {
128117 } ;
129118
130119 // TODO: DSC asks for 'properties' here but we only have 'identifiers' from Bicep.
131- let result = match resource. get ( & identifiers) {
132- Ok ( r) => match r {
133- invoke_result:: GetResult :: Resource ( get_result) => {
134- serde_json:: to_string ( & get_result. actual_state ) . map_err ( |e| {
135- Status :: internal ( format ! ( "Failed to serialize actual state: {e}" ) )
136- } ) ?
137- }
138- _ => return Err ( Status :: unimplemented ( "Group resources not yet supported" ) ) ,
139- } ,
140- Err ( e) => return Err ( Status :: internal ( format ! ( "DSC get operation failed: {e}" ) ) ) ,
120+ let GetResult :: Resource ( result) = resource
121+ . get ( & identifiers)
122+ . map_err ( |e| Status :: internal ( format ! ( "DSC get operation failed: {e}" ) ) ) ?
123+ else {
124+ return Err ( Status :: unimplemented ( "Group resources not supported" ) ) ;
141125 } ;
142126
143127 Ok ( Response :: new ( LocalExtensibilityOperationResponse {
144128 resource : Some ( proto:: Resource {
145129 r#type : resource_type,
146130 api_version : version,
147131 identifiers : identifiers,
148- properties : result,
132+ properties : result. actual_state . to_string ( ) ,
149133 status : None ,
150134 } ) ,
151135 error_data : None ,
0 commit comments