@@ -17,7 +17,7 @@ use dsc_lib::{
17
17
config_result:: ResourceGetResult ,
18
18
Configurator ,
19
19
} ,
20
- discovery:: discovery_trait:: DiscoveryKind ,
20
+ discovery:: discovery_trait:: { DiscoveryFilter , DiscoveryKind } ,
21
21
discovery:: command_discovery:: ImportedManifest ,
22
22
dscerror:: DscError ,
23
23
DscManager ,
@@ -35,6 +35,7 @@ use dsc_lib::{
35
35
} ;
36
36
use regex:: RegexBuilder ;
37
37
use rust_i18n:: t;
38
+ use core:: convert:: AsRef ;
38
39
use std:: {
39
40
collections:: HashMap ,
40
41
io:: { self , IsTerminal } ,
@@ -488,17 +489,12 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
488
489
} ;
489
490
490
491
// discover the resources
491
- let mut resource_types = Vec :: new ( ) ;
492
+ let mut resource_types = Vec :: < DiscoveryFilter > :: new ( ) ;
492
493
for resource_block in resources {
493
494
let Some ( type_name) = resource_block[ "type" ] . as_str ( ) else {
494
495
return Err ( DscError :: Validation ( t ! ( "subcommand.resourceTypeNotSpecified" ) . to_string ( ) ) ) ;
495
496
} ;
496
-
497
- if resource_types. contains ( & type_name. to_lowercase ( ) ) {
498
- continue ;
499
- }
500
-
501
- resource_types. push ( type_name. to_lowercase ( ) . to_string ( ) ) ;
497
+ resource_types. push ( DiscoveryFilter :: new ( type_name. to_lowercase ( ) . to_string ( ) , resource_block[ "api_version" ] . as_str ( ) . map ( |s| s. to_string ( ) ) ) ) ;
502
498
}
503
499
dsc. find_resources ( & resource_types, progress_format) ;
504
500
@@ -510,7 +506,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
510
506
trace ! ( "{} '{}'" , t!( "subcommand.validatingResource" ) , resource_block[ "name" ] . as_str( ) . unwrap_or_default( ) ) ;
511
507
512
508
// get the actual resource
513
- let Some ( resource) = get_resource ( & dsc, type_name) else {
509
+ let Some ( resource) = get_resource ( & mut dsc, type_name, resource_block [ "api_version" ] . as_str ( ) ) else {
514
510
return Err ( DscError :: Validation ( format ! ( "{}: '{type_name}'" , t!( "subcommand.resourceNotFound" ) ) ) ) ;
515
511
} ;
516
512
@@ -577,43 +573,43 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
577
573
ResourceSubCommand :: List { resource_name, adapter_name, description, tags, output_format } => {
578
574
list_resources ( & mut dsc, resource_name. as_ref ( ) , adapter_name. as_ref ( ) , description. as_ref ( ) , tags. as_ref ( ) , output_format. as_ref ( ) , progress_format) ;
579
575
} ,
580
- ResourceSubCommand :: Schema { resource , output_format } => {
581
- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
582
- resource_command:: schema ( & dsc, resource, output_format. as_ref ( ) ) ;
576
+ ResourceSubCommand :: Schema { resource , version , output_format } => {
577
+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource. clone ( ) , version . clone ( ) ) ] , progress_format) ;
578
+ resource_command:: schema ( & mut dsc, resource, version . as_deref ( ) , output_format. as_ref ( ) ) ;
583
579
} ,
584
- ResourceSubCommand :: Export { resource, input, file, output_format } => {
585
- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
580
+ ResourceSubCommand :: Export { resource, version , input, file, output_format } => {
581
+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource. clone ( ) , version . clone ( ) ) ] , progress_format) ;
586
582
let parsed_input = get_input ( input. as_ref ( ) , file. as_ref ( ) , false ) ;
587
- resource_command:: export ( & mut dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
583
+ resource_command:: export ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
588
584
} ,
589
- ResourceSubCommand :: Get { resource, input, file : path, all, output_format } => {
590
- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
585
+ ResourceSubCommand :: Get { resource, version , input, file : path, all, output_format } => {
586
+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource. clone ( ) , version . clone ( ) ) ] , progress_format) ;
591
587
if * all {
592
- resource_command:: get_all ( & dsc, resource, output_format. as_ref ( ) ) ;
588
+ resource_command:: get_all ( & mut dsc, resource, version . as_deref ( ) , output_format. as_ref ( ) ) ;
593
589
}
594
590
else {
595
591
if * output_format == Some ( GetOutputFormat :: JsonArray ) {
596
592
error ! ( "{}" , t!( "subcommand.jsonArrayNotSupported" ) ) ;
597
593
exit ( EXIT_INVALID_ARGS ) ;
598
594
}
599
595
let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
600
- resource_command:: get ( & dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
596
+ resource_command:: get ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
601
597
}
602
598
} ,
603
- ResourceSubCommand :: Set { resource, input, file : path, output_format } => {
604
- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
599
+ ResourceSubCommand :: Set { resource, version , input, file : path, output_format } => {
600
+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource. clone ( ) , version . clone ( ) ) ] , progress_format) ;
605
601
let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
606
- resource_command:: set ( & dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
602
+ resource_command:: set ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
607
603
} ,
608
- ResourceSubCommand :: Test { resource, input, file : path, output_format } => {
609
- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
604
+ ResourceSubCommand :: Test { resource, version , input, file : path, output_format } => {
605
+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource. clone ( ) , version . clone ( ) ) ] , progress_format) ;
610
606
let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
611
- resource_command:: test ( & dsc, resource, & parsed_input, output_format. as_ref ( ) ) ;
607
+ resource_command:: test ( & mut dsc, resource, version . as_deref ( ) , & parsed_input, output_format. as_ref ( ) ) ;
612
608
} ,
613
- ResourceSubCommand :: Delete { resource, input, file : path } => {
614
- dsc. find_resources ( & [ resource. to_string ( ) ] , progress_format) ;
609
+ ResourceSubCommand :: Delete { resource, version , input, file : path } => {
610
+ dsc. find_resources ( & [ DiscoveryFilter :: new ( resource. clone ( ) , version . clone ( ) ) ] , progress_format) ;
615
611
let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) , false ) ;
616
- resource_command:: delete ( & dsc, resource, & parsed_input) ;
612
+ resource_command:: delete ( & mut dsc, resource, version . as_deref ( ) , & parsed_input) ;
617
613
} ,
618
614
}
619
615
}
0 commit comments