Skip to content

RFD-322: users list (+ filter by group)#2423

Merged
david-crespo merged 13 commits into
mainfrom
group-list-users
Feb 28, 2023
Merged

RFD-322: users list (+ filter by group)#2423
david-crespo merged 13 commits into
mainfrom
group-list-users

Conversation

@david-crespo

@david-crespo david-crespo commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

Needed to make PaginatedById take a generic Selector param so I could give it the optional group selector.

let opctx = OpContext::for_external_api(&rqctx).await?;
let users = nexus
.silo_users_list_current(&opctx, &pagparams)
.silo_users_list_current_by_id(&opctx, &pagparams)

@david-crespo david-crespo Feb 24, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make them both use the same method like @zephraph did here if the group filter query param is purely additive.
https://github.com/oxidecomputer/omicron/pull/2420/files#diff-7429b402f97c8a901b88c3599e8505de4afae78092b5f27e4542bc5818125f17R5794-R5798

}]
async fn user_list_v1(
rqctx: RequestContext<Arc<ServerContext>>,
query_params: Query<PaginatedById<params::OptionalGroupSelector>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the group selector actually optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I pictured it working was: if you don't specify a group, you get all users. If you specify a group you get the users in that group.

Comment thread nexus/src/external_api/http_entrypoints.rs Outdated
Comment thread nexus/src/app/iam.rs Outdated
self.db_datastore
.silo_users_list(opctx, &authz_silo_user_list, pagparams)
.await
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm splitting the logic here, but really these could be two Nexus functions. In fact, I'll make that change. I'm remembering the wisdom of Sandi Metz: move logic forks as high in the call stack as you can.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the quote but it does make sense to me to break this down.

let scan_params = ScanById::from_query(&query)?;
// TODO: a valid UUID gets parsed here and will 404 if it doesn't exist
// (as expected) but a non-UUID string just gets let through as None
// (i.e., ignored) instead of 400ing

@david-crespo david-crespo Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I need help with this @zephraph

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'll have to dig into the underlying mechanism here. What we could do is add validation in ScanById::from_query that returns an error if the UUID is invalid. The flow here is a bit different though so I want to make sure I'm understanding it better.

@david-crespo david-crespo Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a good point. We could also do it semi-manually here. I was thinking it might need some serde attribute thing, but that would prevent the struct from being used in a place where we don’t want it to error out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, this fixed it. The nested serde flatten was making it more lenient somehow.
5402185#diff-aee01ef600c8eb547421397e5d89c41a67dd6e6ca6033676cac47b7909e1e344

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is interesting. Once we're done with the V1 migration a next big step is wrapping up the selectors in a macro or something and potentially simplifying them. It won't result in an API change but I definitely feel like there's some improvement to be had there.

@david-crespo david-crespo marked this pull request as ready for review February 27, 2023 23:14
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ScanById",
"title": "ScanById_for_Null",

@david-crespo david-crespo Feb 28, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine. I don't think this title actually ends up being used by anything.

@david-crespo david-crespo added the api Related to the API. label Feb 28, 2023
@david-crespo david-crespo changed the title v1 silo users list endpoint with filtering by group RFD 322 users list (+ filter by group) Feb 28, 2023
@david-crespo david-crespo changed the title RFD 322 users list (+ filter by group) RFD-322: users list (+ filter by group) Feb 28, 2023
Comment thread nexus/src/db/datastore/silo_user.rs Outdated
Comment on lines +224 to +225
use db::schema::silo_group_membership as sgm;
use db::schema::silo_user as su;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing but could we change sgm to group and su to user? I think that might make it a bit easier to read the query below.

@david-crespo david-crespo enabled auto-merge (squash) February 28, 2023 20:27
@david-crespo david-crespo merged commit 25f05bd into main Feb 28, 2023
@david-crespo david-crespo deleted the group-list-users branch February 28, 2023 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants