-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nexus] Endpoint to list IP pools for silo, add is_default
to silo-scoped IP pools list
#4843
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
270133e
first pass at list IP pools for silo endpoint
david-crespo 532dd5a
project IP pools endpoint also includes is_default
david-crespo 06d1fea
/v1/ip-pools/{pool} responds with SiloIpPool too
david-crespo b489f09
test for ip pools for silo endpoint
david-crespo 7685d47
views::IpPoolSilo -> views::IpPoolSiloLink, params::IpPoolSiloLink ->…
david-crespo 9e8500d
share query to fetch pools for silo
david-crespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ use omicron_common::api::external::CreateResult; | |
use omicron_common::api::external::DataPageParams; | ||
use omicron_common::api::external::DeleteResult; | ||
use omicron_common::api::external::Error; | ||
use omicron_common::api::external::InternalContext; | ||
use omicron_common::api::external::ListResultVec; | ||
use omicron_common::api::external::LookupResult; | ||
use omicron_common::api::external::NameOrId; | ||
|
@@ -74,12 +75,20 @@ impl super::Nexus { | |
} | ||
|
||
/// List IP pools in current silo | ||
pub(crate) async fn silo_ip_pools_list( | ||
pub(crate) async fn current_silo_ip_pool_list( | ||
&self, | ||
opctx: &OpContext, | ||
pagparams: &PaginatedBy<'_>, | ||
) -> ListResultVec<db::model::IpPool> { | ||
self.db_datastore.silo_ip_pools_list(opctx, pagparams).await | ||
) -> ListResultVec<(db::model::IpPool, db::model::IpPoolResource)> { | ||
let authz_silo = | ||
opctx.authn.silo_required().internal_context("listing IP pools")?; | ||
|
||
// From the developer user's point of view, we treat IP pools linked to | ||
// their silo as silo resources, so they can list them if they can list | ||
// silo children | ||
opctx.authorize(authz::Action::ListChildren, &authz_silo).await?; | ||
|
||
self.db_datastore.silo_ip_pool_list(opctx, &authz_silo, pagparams).await | ||
} | ||
|
||
// Look up pool by name or ID, but only return it if it's linked to the | ||
|
@@ -88,19 +97,19 @@ impl super::Nexus { | |
&'a self, | ||
opctx: &'a OpContext, | ||
pool: &'a NameOrId, | ||
) -> LookupResult<db::model::IpPool> { | ||
) -> LookupResult<(db::model::IpPool, db::model::IpPoolResource)> { | ||
let (authz_pool, pool) = | ||
self.ip_pool_lookup(opctx, pool)?.fetch().await?; | ||
|
||
// 404 if no link is found in the current silo | ||
let link = self.db_datastore.ip_pool_fetch_link(opctx, pool.id()).await; | ||
if link.is_err() { | ||
return Err(authz_pool.not_found()); | ||
match link { | ||
Ok(link) => Ok((pool, link)), | ||
Err(_) => Err(authz_pool.not_found()), | ||
} | ||
|
||
Ok(pool) | ||
} | ||
|
||
/// List silos for a given pool | ||
pub(crate) async fn ip_pool_silo_list( | ||
&self, | ||
opctx: &OpContext, | ||
|
@@ -109,14 +118,34 @@ impl super::Nexus { | |
) -> ListResultVec<db::model::IpPoolResource> { | ||
let (.., authz_pool) = | ||
pool_lookup.lookup_for(authz::Action::ListChildren).await?; | ||
|
||
// check ability to list silos in general | ||
opctx.authorize(authz::Action::ListChildren, &authz::FLEET).await?; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed this check was missing here |
||
self.db_datastore.ip_pool_silo_list(opctx, &authz_pool, pagparams).await | ||
} | ||
|
||
// List pools for a given silo | ||
pub(crate) async fn silo_ip_pool_list( | ||
&self, | ||
opctx: &OpContext, | ||
silo_lookup: &lookup::Silo<'_>, | ||
pagparams: &PaginatedBy<'_>, | ||
) -> ListResultVec<(db::model::IpPool, db::model::IpPoolResource)> { | ||
let (.., authz_silo) = | ||
silo_lookup.lookup_for(authz::Action::Read).await?; | ||
// check ability to list pools in general | ||
opctx | ||
.authorize(authz::Action::ListChildren, &authz::IP_POOL_LIST) | ||
.await?; | ||
self.db_datastore.silo_ip_pool_list(opctx, &authz_silo, pagparams).await | ||
} | ||
|
||
pub(crate) async fn ip_pool_link_silo( | ||
&self, | ||
opctx: &OpContext, | ||
pool_lookup: &lookup::IpPool<'_>, | ||
silo_link: ¶ms::IpPoolSiloLink, | ||
silo_link: ¶ms::IpPoolLinkSilo, | ||
) -> CreateResult<db::model::IpPoolResource> { | ||
let (authz_pool,) = | ||
pool_lookup.lookup_for(authz::Action::Modify).await?; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized this query is exactly the same as the one above — the only difference is whether you're passing in a silo or pulling the current silo from auth context. I will extract a shared function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came up in some of my work too. I just dropped the
current
version altogether and only left on that takes a given argument. The app layer can pass in the current silo when needed.