@@ -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 } ,
@@ -490,17 +491,12 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
490
491
} ;
491
492
492
493
// discover the resources
493
- let mut resource_types = Vec :: new ( ) ;
494
+ let mut resource_types = Vec :: < DiscoveryFilter > :: new ( ) ;
494
495
for resource_block in resources {
495
496
let Some ( type_name) = resource_block[ "type" ] . as_str ( ) else {
496
497
return Err ( DscError :: Validation ( t ! ( "subcommand.resourceTypeNotSpecified" ) . to_string ( ) ) ) ;
497
498
} ;
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) ) ) ;
504
500
}
505
501
dsc. find_resources ( & resource_types, progress_format) ;
506
502
@@ -512,7 +508,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
512
508
trace ! ( "{} '{}'" , t!( "subcommand.validatingResource" ) , resource_block[ "name" ] . as_str( ) . unwrap_or_default( ) ) ;
513
509
514
510
// 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 {
516
512
return Err ( DscError :: Validation ( format ! ( "{}: '{type_name}'" , t!( "subcommand.resourceNotFound" ) ) ) ) ;
517
513
} ;
518
514
@@ -579,43 +575,43 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
579
575
ResourceSubCommand :: List { resource_name, adapter_name, description, tags, output_format } => {
580
576
list_resources ( & mut dsc, resource_name. as_ref ( ) , adapter_name. as_ref ( ) , description. as_ref ( ) , tags. as_ref ( ) , output_format. as_ref ( ) , progress_format) ;
581
577
} ,
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 ( ) ) ;
585
581
} ,
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) ;
588
584
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 ( ) ) ;
590
586
} ,
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) ;
593
589
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 ( ) ) ;
595
591
}
596
592
else {
597
593
if * output_format == Some ( GetOutputFormat :: JsonArray ) {
598
594
error ! ( "{}" , t!( "subcommand.jsonArrayNotSupported" ) ) ;
599
595
exit ( EXIT_INVALID_ARGS ) ;
600
596
}
601
597
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 ( ) ) ;
603
599
}
604
600
} ,
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) ;
607
603
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 ( ) ) ;
609
605
} ,
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) ;
612
608
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 ( ) ) ;
614
610
} ,
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) ;
617
613
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) ;
619
615
} ,
620
616
}
621
617
}
0 commit comments