Skip to content

Commit abf3eef

Browse files
committed
delete Role, RoleName, RolePage views and params
1 parent 887d8b2 commit abf3eef

File tree

3 files changed

+3
-142
lines changed

3 files changed

+3
-142
lines changed

common/src/api/external/mod.rs

Lines changed: 2 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -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![

nexus/types/src/external_api/params.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,22 +2206,6 @@ pub struct AllowListUpdate {
22062206
pub allowed_ips: AllowedSourceIps,
22072207
}
22082208

2209-
// Roles
2210-
2211-
// Roles have their own pagination scheme because they do not use the usual "id"
2212-
// or "name" types. For more, see the comment in dbinit.sql.
2213-
#[derive(Deserialize, JsonSchema, Serialize)]
2214-
pub struct RolePage {
2215-
pub last_seen: String,
2216-
}
2217-
2218-
/// Path parameters for global (system) role requests
2219-
#[derive(Deserialize, JsonSchema)]
2220-
pub struct RolePath {
2221-
/// The built-in role's unique name.
2222-
pub role_name: String,
2223-
}
2224-
22252209
// Console API
22262210

22272211
#[derive(Deserialize, JsonSchema)]

nexus/types/src/external_api/views.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use chrono::Utc;
1414
use diffus::Diffus;
1515
use omicron_common::api::external::{
1616
AllowedSourceIps as ExternalAllowedSourceIps, ByteCount, Digest, Error,
17-
IdentityMetadata, InstanceState, Name, ObjectIdentity, RoleName,
17+
IdentityMetadata, InstanceState, Name, ObjectIdentity,
1818
SimpleIdentityOrName,
1919
};
2020
use oxnet::{Ipv4Net, Ipv6Net};
@@ -927,15 +927,6 @@ pub struct UserBuiltin {
927927
pub identity: IdentityMetadata,
928928
}
929929

930-
// ROLES
931-
932-
/// View of a Role
933-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
934-
pub struct Role {
935-
pub name: RoleName,
936-
pub description: String,
937-
}
938-
939930
// SSH KEYS
940931

941932
/// View of an SSH Key

0 commit comments

Comments
 (0)