Skip to content

Conversation

@david-crespo
Copy link
Contributor

@david-crespo david-crespo commented Jan 18, 2025

Pulling these refactors out of #7339 because they're mechanical and just add noise. The point is to make it a cleaner diff when we add the function calls or wrapper code that creates audit log entries, as well as to clean up the device_auth (eliminated) and console_api (shrunken substantially) files, which have always been a little out of place.

Refactors

With the change to a trait-based Dropshot API, the already weird console_api and device_auth modules became even weirder, because the actual endpoint definitions were moved out of those files and into http_entrypoints.rs, but they still called functions that lived in the other files. These functions were redundant and had signatures more or less identical to the endpoint handlers. That's the main reason we lose 90 lines here.

Before we had

http_entrypoints.rs -> console_api/device_auth -> nexus/src/app functions

Now we (mostly) cut out the middleman:

http_entrypoints.rs -> nexus/src/app functions

Some of what was in the middle moved up into the endpoint handlers, some moved "down" into the nexus "service layer" functions.

One (1) functional change

The one functional change is that the console endpoints are all instrumented now.

Ok(_) => Ok(true),
}

Ok(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I still don't like this method, but at least it's a few lines shorter now

_path_params: Path<params::LoginToProviderPathParam>,
_query_params: Query<params::LoginUrlQuery>,
) -> Result<Response<Body>, HttpError> {
console_api::login_saml_begin(rqctx, path_params, query_params).await
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All this function did was call service_console_index. That's the kind of thing we're fixing here.

path_params: Path<params::LoginToProviderPathParam>,
query_params: Query<params::LoginUrlQuery>,
) -> Result<HttpResponseFound, HttpError> {
console_api::login_saml_redirect(rqctx, path_params, query_params).await
Copy link
Contributor Author

@david-crespo david-crespo Jan 22, 2025

Choose a reason for hiding this comment

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

Some of these are slightly more interesting than inlining a function call. This helper function did all the stuff you normally see here at top level in the endpoint handlers (instrumentation call, pulling stuff out of path and query params, etc), and the nitty gritty datastore logic that normally goes inside nexus/src/app. So I pulled the former out to here and the latter into nexus/src/app/login.rs.

The idea was to make these look more like the other handlers.

console_page!(console_silo_images);
console_page!(console_silo_utilization);
console_page!(console_silo_access);

Copy link
Contributor Author

@david-crespo david-crespo Jan 22, 2025

Choose a reason for hiding this comment

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

I created these to reduce boilerplate back when the actual endpoint handlers were defined here (rather that silly little helper functions called by the endpoint handlers, which is what they are now). Because of the change to Dropshot API, we kinda have to have the boilerplate over in http_entrypoints.rs anyway, so these are pointless. Deleting this section is why we now inline console_index_or_login_redirect(rqctx).await calls in a ton of handlers.

@david-crespo david-crespo changed the title Refactor login endpoints Refactor login endpoints, instrument console endpoints Jan 22, 2025
@david-crespo david-crespo marked this pull request as ready for review January 22, 2025 20:45
@david-crespo david-crespo force-pushed the refactor-login-endpoints branch from e578e4e to 8d193d5 Compare January 22, 2025 20:46
@david-crespo david-crespo enabled auto-merge (squash) January 22, 2025 22:38
@david-crespo david-crespo merged commit 773b7b8 into main Jan 22, 2025
16 checks passed
@david-crespo david-crespo deleted the refactor-login-endpoints branch January 22, 2025 22:46
david-crespo added a commit that referenced this pull request Mar 18, 2025
david-crespo added a commit that referenced this pull request Mar 18, 2025
david-crespo added a commit that referenced this pull request Mar 21, 2025
There should be no functional changes here, though the internal error
messages are now slightly different between saml login and local login,
where before they were the same. Ran into this while working #7339. This
logic (which I wrote originally and shuffled around in #7374) never
really made sense, and I figured it's good prep for #7818 and friends to
clean it up.

The core of the change here is updating two existing functions that
returned `Result<Option<User>, Error>` to just return `Result<User,
Error>` and move the logic about what we do when the user was `None`
inside each function. In both cases, when the user was `None` we ended
up with an `Error::Unauthenticated` anyway, so we can just do that a
moment earlier and eliminate a lot of misdirection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants