@@ -537,72 +537,6 @@ impl JsonSchema for SemverVersion {
537537 }
538538}
539539
540- /// Name for a built-in role
541- #[ derive(
542- Clone ,
543- Debug ,
544- DeserializeFromStr ,
545- Display ,
546- Eq ,
547- FromStr ,
548- Ord ,
549- PartialEq ,
550- PartialOrd ,
551- SerializeDisplay ,
552- ) ]
553- #[ display( "{resource_type}.{role_name}" ) ]
554- pub struct RoleName {
555- // "resource_type" is generally the String value of one of the
556- // `ResourceType` variants. We could store the parsed `ResourceType`
557- // instead, but it's useful to be able to represent RoleNames for resource
558- // types that we don't know about. That could happen if we happen to find
559- // them in the database, for example.
560- #[ from_str( regex = "[a-z-]+" ) ]
561- resource_type : String ,
562- #[ from_str( regex = "[a-z-]+" ) ]
563- role_name : String ,
564- }
565-
566- impl RoleName {
567- pub fn new ( resource_type : & str , role_name : & str ) -> RoleName {
568- RoleName {
569- resource_type : String :: from ( resource_type) ,
570- role_name : String :: from ( role_name) ,
571- }
572- }
573- }
574-
575- /// Custom JsonSchema implementation to encode the constraints on RoleName
576- impl JsonSchema for RoleName {
577- fn schema_name ( ) -> String {
578- "RoleName" . to_string ( )
579- }
580- fn json_schema (
581- _: & mut schemars:: gen:: SchemaGenerator ,
582- ) -> schemars:: schema:: Schema {
583- schemars:: schema:: Schema :: Object ( schemars:: schema:: SchemaObject {
584- metadata : Some ( Box :: new ( schemars:: schema:: Metadata {
585- title : Some ( "A name for a built-in role" . to_string ( ) ) ,
586- description : Some (
587- "Role names consist of two string components \
588- separated by dot (\" .\" )."
589- . to_string ( ) ,
590- ) ,
591- ..Default :: default ( )
592- } ) ) ,
593- instance_type : Some ( schemars:: schema:: SingleOrVec :: Single (
594- Box :: new ( schemars:: schema:: InstanceType :: String ) ,
595- ) ) ,
596- string : Some ( Box :: new ( schemars:: schema:: StringValidation {
597- max_length : Some ( 63 ) ,
598- min_length : None ,
599- pattern : Some ( "[a-z-]+\\ .[a-z-]+" . to_string ( ) ) ,
600- } ) ) ,
601- ..Default :: default ( )
602- } )
603- }
604- }
605-
606540/// Byte count to express memory or storage capacity.
607541//
608542// The maximum supported byte count is [`i64::MAX`]. This makes it somewhat
@@ -3197,8 +3131,8 @@ mod test {
31973131 use super :: VpcFirewallRuleHostFilter ;
31983132 use super :: VpcFirewallRuleTarget ;
31993133 use super :: {
3200- ByteCount , Digest , L4Port , L4PortRange , Name , RoleName ,
3201- VpcFirewallRuleAction , VpcFirewallRuleDirection , VpcFirewallRuleFilter ,
3134+ ByteCount , Digest , L4Port , L4PortRange , Name , VpcFirewallRuleAction ,
3135+ VpcFirewallRuleDirection , VpcFirewallRuleFilter ,
32023136 VpcFirewallRulePriority , VpcFirewallRuleProtocol ,
32033137 VpcFirewallRuleStatus , VpcFirewallRuleUpdate ,
32043138 VpcFirewallRuleUpdateParams ,
@@ -3321,54 +3255,6 @@ mod test {
33213255 }
33223256 }
33233257
3324- #[ test]
3325- fn test_role_name_parse ( ) {
3326- // Error cases
3327- let bad_inputs = vec ! [
3328- // empty string is always worth testing
3329- "" ,
3330- // missing dot
3331- "project" ,
3332- // extra dot (or, illegal character in the second component)
3333- "project.admin.super" ,
3334- // missing resource type (or, another bogus resource type)
3335- ".admin" ,
3336- // missing role name
3337- "project." ,
3338- // illegal characters in role name
3339- "project.not_good" ,
3340- ] ;
3341-
3342- for input in bad_inputs {
3343- eprintln ! ( "check name {:?} (expecting error)" , input) ;
3344- let result =
3345- input. parse :: < RoleName > ( ) . expect_err ( "unexpectedly succeeded" ) ;
3346- eprintln ! ( "(expected) error: {:?}" , result) ;
3347- }
3348-
3349- eprintln ! ( "check name \" project.admin\" (expecting success)" ) ;
3350- let role_name =
3351- "project.admin" . parse :: < RoleName > ( ) . expect ( "failed to parse" ) ;
3352- assert_eq ! ( role_name. to_string( ) , "project.admin" ) ;
3353- assert_eq ! ( role_name. resource_type, "project" ) ;
3354- assert_eq ! ( role_name. role_name, "admin" ) ;
3355-
3356- eprintln ! ( "check name \" barf.admin\" (expecting success)" ) ;
3357- let role_name =
3358- "barf.admin" . parse :: < RoleName > ( ) . expect ( "failed to parse" ) ;
3359- assert_eq ! ( role_name. to_string( ) , "barf.admin" ) ;
3360- assert_eq ! ( role_name. resource_type, "barf" ) ;
3361- assert_eq ! ( role_name. role_name, "admin" ) ;
3362-
3363- eprintln ! ( "check name \" organization.super-user\" (expecting success)" ) ;
3364- let role_name = "organization.super-user"
3365- . parse :: < RoleName > ( )
3366- . expect ( "failed to parse" ) ;
3367- assert_eq ! ( role_name. to_string( ) , "organization.super-user" ) ;
3368- assert_eq ! ( role_name. resource_type, "organization" ) ;
3369- assert_eq ! ( role_name. role_name, "super-user" ) ;
3370- }
3371-
33723258 #[ test]
33733259 fn test_resource_name_parse ( ) {
33743260 let bad_inputs = vec ! [
0 commit comments