@@ -495,72 +495,6 @@ fn name_schema(
495495 . into ( )
496496}
497497
498- /// Name for a built-in role
499- #[ derive(
500- Clone ,
501- Debug ,
502- DeserializeFromStr ,
503- Display ,
504- Eq ,
505- FromStr ,
506- Ord ,
507- PartialEq ,
508- PartialOrd ,
509- SerializeDisplay ,
510- ) ]
511- #[ display( "{resource_type}.{role_name}" ) ]
512- pub struct RoleName {
513- // "resource_type" is generally the String value of one of the
514- // `ResourceType` variants. We could store the parsed `ResourceType`
515- // instead, but it's useful to be able to represent RoleNames for resource
516- // types that we don't know about. That could happen if we happen to find
517- // them in the database, for example.
518- #[ from_str( regex = "[a-z-]+" ) ]
519- resource_type : String ,
520- #[ from_str( regex = "[a-z-]+" ) ]
521- role_name : String ,
522- }
523-
524- impl RoleName {
525- pub fn new ( resource_type : & str , role_name : & str ) -> RoleName {
526- RoleName {
527- resource_type : String :: from ( resource_type) ,
528- role_name : String :: from ( role_name) ,
529- }
530- }
531- }
532-
533- /// Custom JsonSchema implementation to encode the constraints on RoleName
534- impl JsonSchema for RoleName {
535- fn schema_name ( ) -> String {
536- "RoleName" . to_string ( )
537- }
538- fn json_schema (
539- _: & mut schemars:: gen:: SchemaGenerator ,
540- ) -> schemars:: schema:: Schema {
541- schemars:: schema:: Schema :: Object ( schemars:: schema:: SchemaObject {
542- metadata : Some ( Box :: new ( schemars:: schema:: Metadata {
543- title : Some ( "A name for a built-in role" . to_string ( ) ) ,
544- description : Some (
545- "Role names consist of two string components \
546- separated by dot (\" .\" )."
547- . to_string ( ) ,
548- ) ,
549- ..Default :: default ( )
550- } ) ) ,
551- instance_type : Some ( schemars:: schema:: SingleOrVec :: Single (
552- Box :: new ( schemars:: schema:: InstanceType :: String ) ,
553- ) ) ,
554- string : Some ( Box :: new ( schemars:: schema:: StringValidation {
555- max_length : Some ( 63 ) ,
556- min_length : None ,
557- pattern : Some ( "[a-z-]+\\ .[a-z-]+" . to_string ( ) ) ,
558- } ) ) ,
559- ..Default :: default ( )
560- } )
561- }
562- }
563-
564498/// Byte count to express memory or storage capacity.
565499//
566500// The maximum supported byte count is [`i64::MAX`]. This makes it somewhat
@@ -1040,6 +974,7 @@ pub enum ResourceType {
1040974 RouterRoute ,
1041975 Oximeter ,
1042976 MetricProducer ,
977+ RoleBuiltin ,
1043978 TufRepo ,
1044979 TufArtifact ,
1045980 SwitchPort ,
@@ -3324,8 +3259,8 @@ mod test {
33243259 use super :: VpcFirewallRuleHostFilter ;
33253260 use super :: VpcFirewallRuleTarget ;
33263261 use super :: {
3327- ByteCount , Digest , L4Port , L4PortRange , Name , RoleName ,
3328- VpcFirewallRuleAction , VpcFirewallRuleDirection , VpcFirewallRuleFilter ,
3262+ ByteCount , Digest , L4Port , L4PortRange , Name , VpcFirewallRuleAction ,
3263+ VpcFirewallRuleDirection , VpcFirewallRuleFilter ,
33293264 VpcFirewallRulePriority , VpcFirewallRuleProtocol ,
33303265 VpcFirewallRuleStatus , VpcFirewallRuleUpdate ,
33313266 VpcFirewallRuleUpdateParams ,
@@ -3408,54 +3343,6 @@ mod test {
34083343 }
34093344 }
34103345
3411- #[ test]
3412- fn test_role_name_parse ( ) {
3413- // Error cases
3414- let bad_inputs = vec ! [
3415- // empty string is always worth testing
3416- "" ,
3417- // missing dot
3418- "project" ,
3419- // extra dot (or, illegal character in the second component)
3420- "project.admin.super" ,
3421- // missing resource type (or, another bogus resource type)
3422- ".admin" ,
3423- // missing role name
3424- "project." ,
3425- // illegal characters in role name
3426- "project.not_good" ,
3427- ] ;
3428-
3429- for input in bad_inputs {
3430- eprintln ! ( "check name {:?} (expecting error)" , input) ;
3431- let result =
3432- input. parse :: < RoleName > ( ) . expect_err ( "unexpectedly succeeded" ) ;
3433- eprintln ! ( "(expected) error: {:?}" , result) ;
3434- }
3435-
3436- eprintln ! ( "check name \" project.admin\" (expecting success)" ) ;
3437- let role_name =
3438- "project.admin" . parse :: < RoleName > ( ) . expect ( "failed to parse" ) ;
3439- assert_eq ! ( role_name. to_string( ) , "project.admin" ) ;
3440- assert_eq ! ( role_name. resource_type, "project" ) ;
3441- assert_eq ! ( role_name. role_name, "admin" ) ;
3442-
3443- eprintln ! ( "check name \" barf.admin\" (expecting success)" ) ;
3444- let role_name =
3445- "barf.admin" . parse :: < RoleName > ( ) . expect ( "failed to parse" ) ;
3446- assert_eq ! ( role_name. to_string( ) , "barf.admin" ) ;
3447- assert_eq ! ( role_name. resource_type, "barf" ) ;
3448- assert_eq ! ( role_name. role_name, "admin" ) ;
3449-
3450- eprintln ! ( "check name \" organization.super-user\" (expecting success)" ) ;
3451- let role_name = "organization.super-user"
3452- . parse :: < RoleName > ( )
3453- . expect ( "failed to parse" ) ;
3454- assert_eq ! ( role_name. to_string( ) , "organization.super-user" ) ;
3455- assert_eq ! ( role_name. resource_type, "organization" ) ;
3456- assert_eq ! ( role_name. role_name, "super-user" ) ;
3457- }
3458-
34593346 #[ test]
34603347 fn test_resource_name_parse ( ) {
34613348 let bad_inputs = vec ! [
0 commit comments