-
Notifications
You must be signed in to change notification settings - Fork 1
migrate to Dropshot API manager #141
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
Merged
sunshowers
merged 6 commits into
main
from
sunshowers/spr/migrate-to-dropshot-api-manager
Oct 7, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2315bb6
[spr] initial version
sunshowers a8b11d5
fix up bad merge
sunshowers fcae9f6
add xtask
sunshowers cf1c2fe
update dropshot-api-manager, rebase on main
sunshowers e91d1bb
rebase on main
sunshowers cf4232d
update dropshot-api-manager
sunshowers 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "dendrite-dropshot-apis" | ||
version = "0.1.0" | ||
edition = "2024" | ||
license = "MPL-2.0" | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
camino.workspace = true | ||
clap.workspace = true | ||
dpd-api.workspace = true | ||
dropshot-api-manager-types.workspace = true | ||
dropshot-api-manager.workspace = true | ||
semver.workspace = true |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
use std::process::ExitCode; | ||
|
||
use anyhow::Context; | ||
use camino::Utf8PathBuf; | ||
use clap::Parser; | ||
use dpd_api::*; | ||
use dropshot_api_manager::{Environment, ManagedApiConfig, ManagedApis}; | ||
use dropshot_api_manager_types::{ManagedApiMetadata, Versions}; | ||
|
||
pub fn environment() -> anyhow::Result<Environment> { | ||
// The workspace root is one level up from this crate's directory. | ||
let workspace_root = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
.parent() | ||
.unwrap() | ||
.to_path_buf(); | ||
let env = Environment::new( | ||
// This is the command used to run the OpenAPI manager. | ||
"cargo xtask openapi".to_owned(), | ||
workspace_root, | ||
// This is the location within the workspace root where the OpenAPI | ||
// documents are stored. | ||
"openapi", | ||
)?; | ||
Ok(env) | ||
} | ||
|
||
/// The list of APIs managed by the OpenAPI manager. | ||
pub fn all_apis() -> anyhow::Result<ManagedApis> { | ||
let apis = vec![ManagedApiConfig { | ||
ident: "dpd", | ||
versions: Versions::Lockstep { | ||
version: semver::Version::new(0, 1, 0), | ||
}, | ||
title: "Oxide Switch Dataplane Controller", | ||
metadata: ManagedApiMetadata { | ||
description: Some("API for managing the Oxide rack switch"), | ||
contact_url: Some("https://oxide.computer"), | ||
contact_email: Some("api@oxide.computer"), | ||
..Default::default() | ||
}, | ||
api_description: dpd_api_mod::stub_api_description, | ||
extra_validation: None, | ||
}]; | ||
|
||
let apis = ManagedApis::new(apis).context("error creating ManagedApis")?; | ||
Ok(apis) | ||
} | ||
|
||
fn main() -> anyhow::Result<ExitCode> { | ||
let app = dropshot_api_manager::App::parse(); | ||
let env = environment()?; | ||
let apis = all_apis()?; | ||
|
||
Ok(app.exec(&env, &apis)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use dropshot_api_manager::test_util::check_apis_up_to_date; | ||
|
||
use super::*; | ||
|
||
// Also recommended: a test which ensures documents are up-to-date. The | ||
// OpenAPI manager comes with a helper function for this, called | ||
// `check_apis_up_to_date`. | ||
#[test] | ||
fn test_apis_up_to_date() -> anyhow::Result<ExitCode> { | ||
let env = environment()?; | ||
let apis = all_apis()?; | ||
|
||
let result = check_apis_up_to_date(&env, &apis)?; | ||
Ok(result.to_exit_code()) | ||
} | ||
} |
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.
Now that we only have the
run
command, we can just drop the subcommand structure entirely.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.
In general, we've retained the subcommand structure in other servers even if it's the only command.
If you still think we should get rid of the run command, can this be a followup? Would have to update all the places that run the binary as well, which adds risk for something that's pretty time-constrained.
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.
If our standard practice is to keep the vestigial
run
subcommand, I'm fine with that.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.
Thanks -- see https://github.com/oxidecomputer/omicron/blob/5f7ab65c8c8b215c6cf71b0d6e018574aa2e7f92/sled-agent/src/bin/sled-agent.rs#L25-L31 for an example. I guess one advantage is that if we do need to add a second command in the future, the places that run the binary don't have to be updated again.