@@ -100,9 +100,11 @@ impl DscResource {
100
100
let mut property_map = Map :: new ( ) ;
101
101
property_map. insert ( "name" . to_string ( ) , Value :: String ( self . type_name . clone ( ) ) ) ;
102
102
property_map. insert ( "type" . to_string ( ) , Value :: String ( self . type_name . clone ( ) ) ) ;
103
- let resource_properties: Value = serde_json:: from_str ( input) ?;
103
+ if !input. is_empty ( ) {
104
+ let resource_properties: Value = serde_json:: from_str ( input) ?;
105
+ property_map. insert ( "properties" . to_string ( ) , resource_properties) ;
106
+ }
104
107
let mut resources_map = Map :: new ( ) ;
105
- property_map. insert ( "properties" . to_string ( ) , resource_properties) ;
106
108
resources_map. insert ( "resources" . to_string ( ) , Value :: Array ( vec ! [ Value :: Object ( property_map) ] ) ) ;
107
109
let adapter_resource = Resource {
108
110
name : self . type_name . clone ( ) ,
@@ -222,10 +224,10 @@ impl Invoke for DscResource {
222
224
return Err ( DscError :: Operation ( t ! ( "dscresources.dscresource.invokeReturnedWrongResult" , operation = "get" , resource = self . type_name) . to_string ( ) ) ) ;
223
225
} ;
224
226
let properties = resource_result. actual_state
225
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "actualState" , r#type = "object" ) . to_string ( ) ) ) ?
227
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "actualState" , property_type = "object" ) . to_string ( ) ) ) ?
226
228
. get ( "result" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "result" ) . to_string ( ) ) ) ?
227
- . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "array" ) . to_string ( ) ) ) ?[ 0 ]
228
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "object" ) . to_string ( ) ) ) ?
229
+ . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "array" ) . to_string ( ) ) ) ?[ 0 ]
230
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "object" ) . to_string ( ) ) ) ?
229
231
. get ( "properties" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "properties" ) . to_string ( ) ) ) ?. clone ( ) ;
230
232
let get_result = GetResult :: Resource ( ResourceGetResponse {
231
233
actual_state : properties. clone ( ) ,
@@ -256,16 +258,16 @@ impl Invoke for DscResource {
256
258
return Err ( DscError :: Operation ( t ! ( "dscresources.dscresource.invokeReturnedWrongResult" , operation = "set" , resource = self . type_name) . to_string ( ) ) ) ;
257
259
} ;
258
260
let before_state = resource_result. before_state
259
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "beforeState" , r#type = "object" ) . to_string ( ) ) ) ?
261
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "beforeState" , property_type = "object" ) . to_string ( ) ) ) ?
260
262
. get ( "result" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "result" ) . to_string ( ) ) ) ?
261
- . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "array" ) . to_string ( ) ) ) ?[ 0 ]
262
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "object" ) . to_string ( ) ) ) ?
263
+ . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "array" ) . to_string ( ) ) ) ?[ 0 ]
264
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "object" ) . to_string ( ) ) ) ?
263
265
. get ( "properties" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "properties" ) . to_string ( ) ) ) ?. clone ( ) ;
264
266
let after_state = resource_result. after_state
265
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "afterState" , r#type = "object" ) . to_string ( ) ) ) ?
267
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "afterState" , property_type = "object" ) . to_string ( ) ) ) ?
266
268
. get ( "result" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "result" ) . to_string ( ) ) ) ?
267
- . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "array" ) . to_string ( ) ) ) ?[ 0 ]
268
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "object" ) . to_string ( ) ) ) ?
269
+ . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "array" ) . to_string ( ) ) ) ?[ 0 ]
270
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "object" ) . to_string ( ) ) ) ?
269
271
. get ( "properties" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "properties" ) . to_string ( ) ) ) ?. clone ( ) ;
270
272
let diff = get_diff ( & before_state, & after_state) ;
271
273
let set_result = SetResult :: Resource ( ResourceSetResponse {
@@ -299,16 +301,16 @@ impl Invoke for DscResource {
299
301
return Err ( DscError :: Operation ( t ! ( "dscresources.dscresource.invokeReturnedWrongResult" , operation = "test" , resource = self . type_name) . to_string ( ) ) ) ;
300
302
} ;
301
303
let desired_state = resource_result. desired_state
302
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "desiredState" , r#type = "object" ) . to_string ( ) ) ) ?
304
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "desiredState" , property_type = "object" ) . to_string ( ) ) ) ?
303
305
. get ( "resources" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "resources" ) . to_string ( ) ) ) ?
304
- . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "resources" , r#type = "array" ) . to_string ( ) ) ) ?[ 0 ]
305
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "resources" , r#type = "object" ) . to_string ( ) ) ) ?
306
+ . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "resources" , property_type = "array" ) . to_string ( ) ) ) ?[ 0 ]
307
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "resources" , property_type = "object" ) . to_string ( ) ) ) ?
306
308
. get ( "properties" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "properties" ) . to_string ( ) ) ) ?. clone ( ) ;
307
309
let actual_state = resource_result. actual_state
308
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "actualState" , r#type = "object" ) . to_string ( ) ) ) ?
310
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "actualState" , property_type = "object" ) . to_string ( ) ) ) ?
309
311
. get ( "result" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "result" ) . to_string ( ) ) ) ?
310
- . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "array" ) . to_string ( ) ) ) ?[ 0 ]
311
- . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , r#type = "object" ) . to_string ( ) ) ) ?
312
+ . as_array ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "array" ) . to_string ( ) ) ) ?[ 0 ]
313
+ . as_object ( ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyIncorrectType" , property = "result" , property_type = "object" ) . to_string ( ) ) ) ?
312
314
. get ( "properties" ) . ok_or ( DscError :: Operation ( t ! ( "dscresources.dscresource.propertyNotFound" , property = "properties" ) . to_string ( ) ) ) ?. clone ( ) ;
313
315
let diff_properties = get_diff ( & desired_state, & actual_state) ;
314
316
let test_result = TestResult :: Resource ( ResourceTestResponse {
@@ -436,8 +438,10 @@ impl Invoke for DscResource {
436
438
actual_state : Vec :: new ( ) ,
437
439
} ;
438
440
for resource in configuration. resources {
439
- let value = serde_json:: to_value ( resource) ?;
440
- export_result. actual_state . push ( value) ;
441
+ let Some ( properties) = resource. properties else {
442
+ return Err ( DscError :: Operation ( t ! ( "dscresources.dscresource.invokeExportReturnedNoResult" , resource = self . type_name) . to_string ( ) ) ) ;
443
+ } ;
444
+ export_result. actual_state . push ( serde_json:: to_value ( properties[ "properties" ] . clone ( ) ) ?) ;
441
445
}
442
446
return Ok ( export_result) ;
443
447
}
0 commit comments