Skip to content

Commit 38fccbf

Browse files
committed
review feedback: underscores to hyphens, extra comment
1 parent a4524ba commit 38fccbf

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

common/src/api/external/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,14 @@ impl Name {
313313
)]
314314
#[display("{resource_type}.{role_name}")]
315315
pub struct RoleName {
316-
#[from_str(regex = "[a-z_]+")]
316+
// "resource_type" is generally the String value of one of the
317+
// `ResourceType` variants. We could store the parsed `ResourceType`
318+
// instead, but it's useful to be able to represent RoleNames for resource
319+
// types that we don't know about. That could happen if we happen to find
320+
// them in the database, for example.
321+
#[from_str(regex = "[a-z-]+")]
317322
resource_type: String,
318-
#[from_str(regex = "[a-z_]+")]
323+
#[from_str(regex = "[a-z-]+")]
319324
role_name: String,
320325
}
321326

@@ -365,7 +370,7 @@ impl JsonSchema for RoleName {
365370
string: Some(Box::new(schemars::schema::StringValidation {
366371
max_length: Some(63),
367372
min_length: None,
368-
pattern: Some("[a-z_]+\\.[a-z_]+".to_string()),
373+
pattern: Some("[a-z-]+\\.[a-z-]+".to_string()),
369374
})),
370375
array: None,
371376
object: None,
@@ -557,7 +562,7 @@ impl TryFrom<i64> for Generation {
557562
PartialOrd,
558563
SerializeDisplay,
559564
)]
560-
#[display(style = "snake_case")]
565+
#[display(style = "kebab-case")]
561566
pub enum ResourceType {
562567
Fleet,
563568
Organization,
@@ -1994,7 +1999,7 @@ mod test {
19941999
// missing role name
19952000
"project.",
19962001
// illegal characters in role name
1997-
"project.not-good",
2002+
"project.not_good",
19982003
];
19992004

20002005
for input in bad_inputs {
@@ -2018,13 +2023,13 @@ mod test {
20182023
assert_eq!(role_name.resource_type, "barf");
20192024
assert_eq!(role_name.role_name, "admin");
20202025

2021-
eprintln!("check name \"organization.super_user\" (expecting success)");
2022-
let role_name = "organization.super_user"
2026+
eprintln!("check name \"organization.super-user\" (expecting success)");
2027+
let role_name = "organization.super-user"
20232028
.parse::<RoleName>()
20242029
.expect("failed to parse");
2025-
assert_eq!(role_name.to_string(), "organization.super_user");
2030+
assert_eq!(role_name.to_string(), "organization.super-user");
20262031
assert_eq!(role_name.resource_type, "organization");
2027-
assert_eq!(role_name.role_name, "super_user");
2032+
assert_eq!(role_name.role_name, "super-user");
20282033
}
20292034

20302035
#[test]
@@ -2036,6 +2041,7 @@ mod test {
20362041
"oRgAnIzAtIoN",
20372042
"organisation",
20382043
"vpc subnet",
2044+
"vpc_subnet",
20392045
];
20402046
for input in bad_inputs {
20412047
eprintln!("check resource type {:?} (expecting error)", input);
@@ -2051,7 +2057,7 @@ mod test {
20512057
);
20522058
assert_eq!(
20532059
ResourceType::VpcSubnet,
2054-
"vpc_subnet".parse::<ResourceType>().unwrap()
2060+
"vpc-subnet".parse::<ResourceType>().unwrap()
20552061
);
20562062
}
20572063

nexus/tests/integration_tests/vpc_routers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async fn test_vpc_routers(cptestctx: &ControlPlaneTestContext) {
5656
let error = client
5757
.make_request_error(Method::GET, &router_url, StatusCode::NOT_FOUND)
5858
.await;
59-
assert_eq!(error.message, "not found: vpc_router with name \"router1\"");
59+
assert_eq!(error.message, "not found: vpc-router with name \"router1\"");
6060

6161
/* Create a VPC Router. */
6262
let new_router = params::VpcRouterCreate {
@@ -91,7 +91,7 @@ async fn test_vpc_routers(cptestctx: &ControlPlaneTestContext) {
9191
StatusCode::BAD_REQUEST,
9292
)
9393
.await;
94-
assert_eq!(error.message, "already exists: vpc_router \"router1\"");
94+
assert_eq!(error.message, "already exists: vpc-router \"router1\"");
9595

9696
let router2_name = "router2";
9797
let router2_url = format!("{}/{}", routers_url, router2_name);
@@ -100,7 +100,7 @@ async fn test_vpc_routers(cptestctx: &ControlPlaneTestContext) {
100100
let error = client
101101
.make_request_error(Method::GET, &router2_url, StatusCode::NOT_FOUND)
102102
.await;
103-
assert_eq!(error.message, "not found: vpc_router with name \"router2\"");
103+
assert_eq!(error.message, "not found: vpc-router with name \"router2\"");
104104

105105
// create second custom router
106106
let new_router = params::VpcRouterCreate {
@@ -144,7 +144,7 @@ async fn test_vpc_routers(cptestctx: &ControlPlaneTestContext) {
144144
let error = client
145145
.make_request_error(Method::GET, &router_url, StatusCode::NOT_FOUND)
146146
.await;
147-
assert_eq!(error.message, "not found: vpc_router with name \"router1\"");
147+
assert_eq!(error.message, "not found: vpc-router with name \"router1\"");
148148

149149
let router_url = format!("{}/{}", routers_url, "new-name");
150150

@@ -178,13 +178,13 @@ async fn test_vpc_routers(cptestctx: &ControlPlaneTestContext) {
178178
let error = client
179179
.make_request_error(Method::GET, &router_url, StatusCode::NOT_FOUND)
180180
.await;
181-
assert_eq!(error.message, "not found: vpc_router with name \"new-name\"");
181+
assert_eq!(error.message, "not found: vpc-router with name \"new-name\"");
182182

183183
// delete router should 404
184184
let error = client
185185
.make_request_error(Method::DELETE, &router_url, StatusCode::NOT_FOUND)
186186
.await;
187-
assert_eq!(error.message, "not found: vpc_router with name \"new-name\"");
187+
assert_eq!(error.message, "not found: vpc-router with name \"new-name\"");
188188

189189
// Creating a router with the same name in a different VPC is allowed
190190
let vpc2_name = "vpc2";

nexus/tests/integration_tests/vpc_subnets.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async fn test_vpc_subnets(cptestctx: &ControlPlaneTestContext) {
6969
let error = client
7070
.make_request_error(Method::GET, &subnet_url, StatusCode::NOT_FOUND)
7171
.await;
72-
assert_eq!(error.message, "not found: vpc_subnet with name \"subnet1\"");
72+
assert_eq!(error.message, "not found: vpc-subnet with name \"subnet1\"");
7373

7474
/* Create a VPC Subnet. */
7575
let ipv4_block =
@@ -129,7 +129,7 @@ async fn test_vpc_subnets(cptestctx: &ControlPlaneTestContext) {
129129
StatusCode::BAD_REQUEST,
130130
)
131131
.await;
132-
assert_eq!(error.message, "already exists: vpc_subnet \"subnet1\"");
132+
assert_eq!(error.message, "already exists: vpc-subnet \"subnet1\"");
133133

134134
let subnet2_name = "subnet2";
135135
let subnet2_url = format!("{}/{}", subnets_url, subnet2_name);
@@ -138,7 +138,7 @@ async fn test_vpc_subnets(cptestctx: &ControlPlaneTestContext) {
138138
let error = client
139139
.make_request_error(Method::GET, &subnet2_url, StatusCode::NOT_FOUND)
140140
.await;
141-
assert_eq!(error.message, "not found: vpc_subnet with name \"subnet2\"");
141+
assert_eq!(error.message, "not found: vpc-subnet with name \"subnet2\"");
142142

143143
// create second subnet
144144
let new_subnet = params::VpcSubnetCreate {
@@ -187,7 +187,7 @@ async fn test_vpc_subnets(cptestctx: &ControlPlaneTestContext) {
187187
let error = client
188188
.make_request_error(Method::GET, &subnet_url, StatusCode::NOT_FOUND)
189189
.await;
190-
assert_eq!(error.message, "not found: vpc_subnet with name \"subnet1\"");
190+
assert_eq!(error.message, "not found: vpc-subnet with name \"subnet1\"");
191191

192192
let subnet_url = format!("{}/{}", subnets_url, "new-name");
193193

@@ -221,13 +221,13 @@ async fn test_vpc_subnets(cptestctx: &ControlPlaneTestContext) {
221221
let error = client
222222
.make_request_error(Method::GET, &subnet_url, StatusCode::NOT_FOUND)
223223
.await;
224-
assert_eq!(error.message, "not found: vpc_subnet with name \"new-name\"");
224+
assert_eq!(error.message, "not found: vpc-subnet with name \"new-name\"");
225225

226226
// delete subnet should 404
227227
let error = client
228228
.make_request_error(Method::DELETE, &subnet_url, StatusCode::NOT_FOUND)
229229
.await;
230-
assert_eq!(error.message, "not found: vpc_subnet with name \"new-name\"");
230+
assert_eq!(error.message, "not found: vpc-subnet with name \"new-name\"");
231231

232232
// Creating a subnet with the same name in a different VPC is allowed
233233
let vpc2_name = "vpc2";

openapi/nexus.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3773,7 +3773,7 @@
37733773
"title": "A name for a built-in role",
37743774
"description": "Role names consist of two string components separated by dot (\".\").",
37753775
"type": "string",
3776-
"pattern": "[a-z_]+\\.[a-z_]+",
3776+
"pattern": "[a-z-]+\\.[a-z-]+",
37773777
"maxLength": 63
37783778
},
37793779
"RoleResultsPage": {

0 commit comments

Comments
 (0)