@@ -8,24 +8,28 @@ use crate::args::AdapterOperation;
88
99#[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
1010#[ serde( deny_unknown_fields) ]
11- pub struct AdaptedOne {
11+ struct AdaptedOne {
1212 pub one : String ,
1313 #[ serde( rename = "_name" , skip_serializing_if = "Option::is_none" ) ]
1414 pub name : Option < String > ,
1515 #[ serde( skip_serializing_if = "Option::is_none" ) ]
1616 pub path : Option < String > ,
1717}
1818
19+ const ADAPTED_ONE_VERSION : & str = "1.0.0" ;
20+
1921#[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
2022#[ serde( deny_unknown_fields) ]
21- pub struct AdaptedTwo {
23+ struct AdaptedTwo {
2224 pub two : String ,
2325 #[ serde( rename = "_name" , skip_serializing_if = "Option::is_none" ) ]
2426 pub name : Option < String > ,
2527 #[ serde( skip_serializing_if = "Option::is_none" ) ]
2628 pub path : Option < String > ,
2729}
2830
31+ const ADAPTED_TWO_VERSION : & str = "2.0.0" ;
32+
2933#[ derive( Clone , Debug , Deserialize , Serialize , JsonSchema ) ]
3034#[ serde( deny_unknown_fields) ]
3135pub struct DscResource {
@@ -52,13 +56,13 @@ pub struct DscResource {
5256 pub require_adapter : Option < String > ,
5357}
5458
55- pub fn adapt ( resource_type : & str , input : & str , operation : & AdapterOperation , resource_path : & Option < String > ) -> Result < String , String > {
59+ pub fn adapt ( resource_type : & str , input : & str , operation : & AdapterOperation , resource_path : & Option < String > , resource_version : & Option < String > ) -> Result < String , String > {
5660 match operation {
5761 AdapterOperation :: List => {
5862 let resource_one = DscResource {
5963 type_name : "Adapted/One" . to_string ( ) ,
6064 kind : "resource" . to_string ( ) ,
61- version : "1.0.0" . to_string ( ) ,
65+ version : ADAPTED_ONE_VERSION . to_string ( ) ,
6266 capabilities : vec ! [ "get" . to_string( ) , "set" . to_string( ) , "test" . to_string( ) , "export" . to_string( ) ] ,
6367 path : "path/to/adapted/one" . to_string ( ) ,
6468 directory : "path/to/adapted" . to_string ( ) ,
@@ -69,7 +73,7 @@ pub fn adapt(resource_type: &str, input: &str, operation: &AdapterOperation, res
6973 let resource_two = DscResource {
7074 type_name : "Adapted/Two" . to_string ( ) ,
7175 kind : "resource" . to_string ( ) ,
72- version : "1.0.0" . to_string ( ) ,
76+ version : ADAPTED_TWO_VERSION . to_string ( ) ,
7377 capabilities : vec ! [ "get" . to_string( ) , "set" . to_string( ) , "test" . to_string( ) , "export" . to_string( ) ] ,
7478 path : "path/to/adapted/two" . to_string ( ) ,
7579 directory : "path/to/adapted" . to_string ( ) ,
@@ -84,6 +88,9 @@ pub fn adapt(resource_type: &str, input: &str, operation: &AdapterOperation, res
8488 AdapterOperation :: Get => {
8589 match resource_type {
8690 "Adapted/One" => {
91+ if let Some ( version) = resource_version && version != ADAPTED_ONE_VERSION {
92+ return Err ( format ! ( "Unsupported version for Adapted/One: {version}" ) ) ;
93+ }
8794 let adapted_one = AdaptedOne {
8895 one : "value1" . to_string ( ) ,
8996 name : None ,
@@ -92,6 +99,9 @@ pub fn adapt(resource_type: &str, input: &str, operation: &AdapterOperation, res
9299 Ok ( serde_json:: to_string ( & adapted_one) . unwrap ( ) )
93100 } ,
94101 "Adapted/Two" => {
102+ if let Some ( version) = resource_version && version != ADAPTED_TWO_VERSION {
103+ return Err ( format ! ( "Unsupported version for Adapted/Two: {version}" ) ) ;
104+ }
95105 let adapted_two = AdaptedTwo {
96106 two : "value2" . to_string ( ) ,
97107 name : None ,
@@ -121,11 +131,17 @@ pub fn adapt(resource_type: &str, input: &str, operation: &AdapterOperation, res
121131 AdapterOperation :: Set | AdapterOperation :: Test => {
122132 match resource_type {
123133 "Adapted/One" => {
134+ if let Some ( version) = resource_version && version != ADAPTED_ONE_VERSION {
135+ return Err ( format ! ( "Unsupported version for {resource_type}: {version}" ) ) ;
136+ }
124137 let adapted_one: AdaptedOne = serde_json:: from_str ( input)
125138 . map_err ( |e| format ! ( "Failed to parse input for Adapted/One: {e}" ) ) ?;
126139 Ok ( serde_json:: to_string ( & adapted_one) . unwrap ( ) )
127140 } ,
128141 "Adapted/Two" => {
142+ if let Some ( version) = resource_version && version != ADAPTED_TWO_VERSION {
143+ return Err ( format ! ( "Unsupported version for {resource_type}: {version}" ) ) ;
144+ }
129145 let adapted_two: AdaptedTwo = serde_json:: from_str ( input)
130146 . map_err ( |e| format ! ( "Failed to parse input for Adapted/Two: {e}" ) ) ?;
131147 Ok ( serde_json:: to_string ( & adapted_two) . unwrap ( ) )
@@ -141,6 +157,9 @@ pub fn adapt(resource_type: &str, input: &str, operation: &AdapterOperation, res
141157 AdapterOperation :: Export => {
142158 match resource_type {
143159 "Adapted/One" => {
160+ if let Some ( version) = resource_version && version != ADAPTED_ONE_VERSION {
161+ return Err ( format ! ( "Unsupported version for {resource_type}: {version}" ) ) ;
162+ }
144163 let adapted_one = AdaptedOne {
145164 one : "first1" . to_string ( ) ,
146165 name : Some ( "first" . to_string ( ) ) ,
@@ -156,6 +175,9 @@ pub fn adapt(resource_type: &str, input: &str, operation: &AdapterOperation, res
156175 std:: process:: exit ( 0 ) ;
157176 } ,
158177 "Adapted/Two" => {
178+ if let Some ( version) = resource_version && version != ADAPTED_TWO_VERSION {
179+ return Err ( format ! ( "Unsupported version for {resource_type}: {version}" ) ) ;
180+ }
159181 let adapted_two = AdaptedTwo {
160182 two : "first2" . to_string ( ) ,
161183 name : Some ( "first" . to_string ( ) ) ,
0 commit comments