@@ -17,7 +17,7 @@ use dsc_lib::{
1717 config_result:: ResourceGetResult ,
1818 Configurator ,
1919 } ,
20- discovery:: discovery_trait:: DiscoveryKind ,
20+ discovery:: discovery_trait:: { DiscoveryFilter , DiscoveryKind } ,
2121 discovery:: command_discovery:: ImportedManifest ,
2222 dscerror:: DscError ,
2323 DscManager ,
@@ -35,6 +35,7 @@ use dsc_lib::{
3535} ;
3636use regex:: RegexBuilder ;
3737use rust_i18n:: t;
38+ use core:: convert:: AsRef ;
3839use std:: {
3940 collections:: HashMap ,
4041 io:: { self , IsTerminal } ,
@@ -490,17 +491,12 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
490491 } ;
491492
492493 // discover the resources
493- let mut resource_types = Vec :: new ( ) ;
494+ let mut resource_types = Vec :: < DiscoveryFilter > :: new ( ) ;
494495 for resource_block in resources {
495496 let Some ( type_name) = resource_block[ "type" ] . as_str ( ) else {
496497 return Err ( DscError :: Validation ( t ! ( "subcommand.resourceTypeNotSpecified" ) . to_string ( ) ) ) ;
497498 } ;
498-
499- if resource_types. contains ( & type_name. to_lowercase ( ) ) {
500- continue ;
501- }
502-
503- resource_types. push ( type_name. to_lowercase ( ) . to_string ( ) ) ;
499+ resource_types. push ( DiscoveryFilter :: new ( type_name, resource_block[ "api_version" ] . as_str ( ) . map ( std:: string:: ToString :: to_string) ) ) ;
504500 }
505501 dsc. find_resources ( & resource_types, progress_format) ;
506502
@@ -512,7 +508,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
512508 trace ! ( "{} '{}'" , t!( "subcommand.validatingResource" ) , resource_block[ "name" ] . as_str( ) . unwrap_or_default( ) ) ;
513509
514510 // get the actual resource
515- let Some ( resource) = get_resource ( & dsc, type_name) else {
511+ let Some ( resource) = get_resource ( & mut dsc, type_name, resource_block [ "api_version" ] . as_str ( ) ) else {
516512 return Err ( DscError :: Validation ( format ! ( "{}: '{type_name}'" , t!( "subcommand.resourceNotFound" ) ) ) ) ;
517513 } ;
518514
@@ -579,43 +575,43 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
579575 ResourceSubCommand :: List { resource_name, adapter_name, description, tags, output_format } => {
580576 list_resources ( & mut dsc, resource_name. as_ref ( ) , adapter_name. as_ref ( ) , description. as_ref ( ) , tags. as_ref ( ) , output_format. as_ref ( ) , progress_format) ;
581577 } ,
582- ResourceSubCommand :: Schema { resource , output_format } => {
583- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
584- resource_command:: schema ( & dsc, resource, output_format. as_ref ( ) ) ;
578+ ResourceSubCommand :: Schema { resource , version , output_format } => {
579+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource, version . clone ( ) ) ] , progress_format) ;
580+ resource_command:: schema ( & mut dsc, resource, version . as_deref ( ) , output_format. as_ref ( ) ) ;
585581 } ,
586- ResourceSubCommand :: Export { resource, input, file, output_format } => {
587- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
582+ ResourceSubCommand :: Export { resource, version , input, file, output_format } => {
583+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource, version . clone ( ) ) ] , progress_format) ;
588584 let parsed_input = get_input ( input. as_ref ( ) , file. as_ref ( ) , false ) ;
589- resource_command:: export ( & mut dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
585+ resource_command:: export ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
590586 } ,
591- ResourceSubCommand :: Get { resource, input, file : path, all, output_format } => {
592- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
587+ ResourceSubCommand :: Get { resource, version , input, file : path, all, output_format } => {
588+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource, version . clone ( ) ) ] , progress_format) ;
593589 if * all {
594- resource_command:: get_all ( & dsc, resource, output_format. as_ref ( ) ) ;
590+ resource_command:: get_all ( & mut dsc, resource, version . as_deref ( ) , output_format. as_ref ( ) ) ;
595591 }
596592 else {
597593 if * output_format == Some ( GetOutputFormat :: JsonArray ) {
598594 error ! ( "{}" , t!( "subcommand.jsonArrayNotSupported" ) ) ;
599595 exit ( EXIT_INVALID_ARGS ) ;
600596 }
601597 let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
602- resource_command:: get ( & dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
598+ resource_command:: get ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
603599 }
604600 } ,
605- ResourceSubCommand :: Set { resource, input, file : path, output_format } => {
606- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
601+ ResourceSubCommand :: Set { resource, version , input, file : path, output_format } => {
602+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource, version . clone ( ) ) ] , progress_format) ;
607603 let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
608- resource_command:: set ( & dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
604+ resource_command:: set ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
609605 } ,
610- ResourceSubCommand :: Test { resource, input, file : path, output_format } => {
611- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
606+ ResourceSubCommand :: Test { resource, version , input, file : path, output_format } => {
607+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource, version . clone ( ) ) ] , progress_format) ;
612608 let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
613- resource_command:: test ( & dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
609+ resource_command:: test ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
614610 } ,
615- ResourceSubCommand :: Delete { resource, input, file : path } => {
616- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
611+ ResourceSubCommand :: Delete { resource, version , input, file : path } => {
612+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource, version . clone ( ) ) ] , progress_format) ;
617613 let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
618- resource_command:: delete ( & dsc, resource, & parsed_input) ;
614+ resource_command:: delete ( & mut dsc, resource, version . as_deref ( ) , & parsed_input) ;
619615 } ,
620616 }
621617}
0 commit comments