-
Notifications
You must be signed in to change notification settings - Fork 27
move to Dropshot API manager #951
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
Changes from all commits
d16a335
663ec05
4285745
c5da44a
0e01240
ceac570
6dfc46a
cac9b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [package] | ||
| name = "propolis-dropshot-apis" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| license = "MPL-2.0" | ||
|
|
||
| [dependencies] | ||
| anyhow.workspace = true | ||
| camino.workspace = true | ||
| clap.workspace = true | ||
| dropshot-api-manager-types.workspace = true | ||
| dropshot-api-manager.workspace = true | ||
| propolis-server-api.workspace = true | ||
| semver.workspace = true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // 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 dropshot_api_manager::{Environment, ManagedApiConfig, ManagedApis}; | ||
| use dropshot_api_manager_types::{ManagedApiMetadata, Versions}; | ||
| use propolis_server_api::*; | ||
|
|
||
| pub fn environment() -> anyhow::Result<Environment> { | ||
| // The workspace root is two levels up from this crate's directory. | ||
| let workspace_root = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| .parent() | ||
| .unwrap() | ||
| .parent() | ||
| .unwrap() | ||
| .to_path_buf(); | ||
| let env = Environment::new( | ||
| // This is the command used to run the OpenAPI manager. | ||
| "cargo xtask openapi", | ||
| workspace_root, | ||
| // This is the location within the workspace root where the OpenAPI | ||
| // documents are stored. | ||
| "openapi", | ||
| )? | ||
| .with_default_git_branch("origin/master".to_owned()); | ||
pfmooney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Ok(env) | ||
| } | ||
|
|
||
| /// The list of APIs managed by the OpenAPI manager. | ||
| pub fn all_apis() -> anyhow::Result<ManagedApis> { | ||
| let apis = vec![ManagedApiConfig { | ||
| ident: "propolis-server", | ||
| versions: Versions::Lockstep { version: semver::Version::new(0, 0, 1) }, | ||
|
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. and presumably in the future we'll move this to 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. Yes, making these APIs versioned (as part of self-service update) is the overall motivation for the series of changes I've been making to all of these repos. See oxidecomputer/omicron#8922 for overall status tracking. |
||
| title: "Oxide Propolis Server API", | ||
| metadata: ManagedApiMetadata { | ||
| description: Some( | ||
| "API for interacting with the Propolis hypervisor frontend.", | ||
| ), | ||
| contact_url: Some("https://oxide.computer"), | ||
| contact_email: Some("api@oxide.computer"), | ||
| ..Default::default() | ||
| }, | ||
| api_description: propolis_server_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()) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.