33
44use clap:: Parser ;
55use dsc_lib:: {
6- configure:: config_doc:: ExecutionKind , dscresources:: dscresource:: Invoke , DscManager ,
6+ configure:: config_doc:: ExecutionKind ,
7+ dscresources:: { dscresource:: Invoke , invoke_result} ,
8+ DscManager ,
79} ;
810use std:: { env, fs, io, process} ;
911use tonic:: { transport:: Server , Request , Response , Status } ;
@@ -42,20 +44,27 @@ impl BicepExtension for BicepExtensionService {
4244 } ;
4345
4446 let result = match resource. set ( & properties, false , & ExecutionKind :: Actual ) {
45- Ok ( r) => LocalExtensibilityOperationResponse {
46- resource : Some ( proto:: Resource {
47- r#type : resource_type,
48- api_version : version,
49- identifiers : properties,
50- properties : serde_json:: to_string ( & r) . unwrap ( ) ,
51- status : None ,
52- } ) ,
53- error_data : None ,
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" ) ) ,
5454 } ,
5555 Err ( e) => return Err ( Status :: internal ( format ! ( "DSC set operation failed: {e}" ) ) ) ,
5656 } ;
5757
58- Ok ( Response :: new ( result) )
58+ Ok ( Response :: new ( LocalExtensibilityOperationResponse {
59+ resource : Some ( proto:: Resource {
60+ r#type : resource_type,
61+ api_version : version,
62+ identifiers : properties,
63+ properties : result,
64+ status : None ,
65+ } ) ,
66+ error_data : None ,
67+ } ) )
5968 }
6069
6170 async fn preview (
@@ -75,15 +84,13 @@ impl BicepExtension for BicepExtensionService {
7584 } ;
7685
7786 let result = match resource. set ( & properties, false , & ExecutionKind :: WhatIf ) {
78- Ok ( r) => LocalExtensibilityOperationResponse {
79- resource : Some ( proto:: Resource {
80- r#type : resource_type,
81- api_version : version,
82- identifiers : properties,
83- properties : serde_json:: to_string ( & r) . unwrap ( ) ,
84- status : None ,
85- } ) ,
86- error_data : None ,
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" ) ) ,
8794 } ,
8895 Err ( e) => {
8996 return Err ( Status :: internal ( format ! (
@@ -92,7 +99,16 @@ impl BicepExtension for BicepExtensionService {
9299 }
93100 } ;
94101
95- Ok ( Response :: new ( result) )
102+ Ok ( Response :: new ( LocalExtensibilityOperationResponse {
103+ resource : Some ( proto:: Resource {
104+ r#type : resource_type,
105+ api_version : version,
106+ identifiers : properties,
107+ properties : result,
108+ status : None ,
109+ } ) ,
110+ error_data : None ,
111+ } ) )
96112 }
97113
98114 async fn get (
@@ -113,20 +129,27 @@ impl BicepExtension for BicepExtensionService {
113129
114130 // TODO: DSC asks for 'properties' here but we only have 'identifiers' from Bicep.
115131 let result = match resource. get ( & identifiers) {
116- Ok ( r) => LocalExtensibilityOperationResponse {
117- resource : Some ( proto:: Resource {
118- r#type : resource_type,
119- api_version : version,
120- identifiers : identifiers,
121- properties : serde_json:: to_string ( & r) . unwrap ( ) ,
122- status : None ,
123- } ) ,
124- error_data : None ,
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" ) ) ,
125139 } ,
126140 Err ( e) => return Err ( Status :: internal ( format ! ( "DSC get operation failed: {e}" ) ) ) ,
127141 } ;
128142
129- Ok ( Response :: new ( result) )
143+ Ok ( Response :: new ( LocalExtensibilityOperationResponse {
144+ resource : Some ( proto:: Resource {
145+ r#type : resource_type,
146+ api_version : version,
147+ identifiers : identifiers,
148+ properties : result,
149+ status : None ,
150+ } ) ,
151+ error_data : None ,
152+ } ) )
130153 }
131154
132155 async fn delete (
@@ -152,24 +175,25 @@ impl BicepExtension for BicepExtensionService {
152175
153176 // TODO: DSC asks for 'properties' here but we only have 'identifiers' from Bicep.
154177 let result = match resource. delete ( & identifiers) {
155- Ok ( r) => LocalExtensibilityOperationResponse {
156- resource : Some ( proto:: Resource {
157- r#type : resource_type,
158- api_version : version,
159- identifiers : identifiers,
160- properties : serde_json:: to_string ( & r) . unwrap ( ) ,
161- status : None ,
162- } ) ,
163- error_data : None ,
164- } ,
178+ // Successful deletion returns () so we return an empty JSON object.
179+ Ok ( _) => "{}" . to_string ( ) ,
165180 Err ( e) => {
166181 return Err ( Status :: internal ( format ! (
167182 "DSC delete operation failed: {e}"
168183 ) ) )
169184 }
170185 } ;
171186
172- Ok ( Response :: new ( result) )
187+ Ok ( Response :: new ( LocalExtensibilityOperationResponse {
188+ resource : Some ( proto:: Resource {
189+ r#type : resource_type,
190+ api_version : version,
191+ identifiers : identifiers,
192+ properties : result,
193+ status : None ,
194+ } ) ,
195+ error_data : None ,
196+ } ) )
173197 }
174198
175199 async fn get_type_files (
0 commit comments