Skip to content

Commit

Permalink
use path params more
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Dec 13, 2024
1 parent 5866f48 commit 55e9c24
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 93 deletions.
3 changes: 3 additions & 0 deletions nexus/external-api/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ probe_view GET /experimental/v1/probes/{probe
support_bundle_create POST /experimental/v1/system/support-bundles
support_bundle_delete DELETE /experimental/v1/system/support-bundles/{support_bundle}
support_bundle_download GET /experimental/v1/system/support-bundles/{support_bundle}/download
support_bundle_download_file GET /experimental/v1/system/support-bundles/{support_bundle}/download/{file}
support_bundle_head HEAD /experimental/v1/system/support-bundles/{support_bundle}/download
support_bundle_head_file HEAD /experimental/v1/system/support-bundles/{support_bundle}/download/{file}
support_bundle_index GET /experimental/v1/system/support-bundles/{support_bundle}/index
support_bundle_list GET /experimental/v1/system/support-bundles
support_bundle_view GET /experimental/v1/system/support-bundles/{support_bundle}
timeseries_query POST /v1/timeseries/query
Expand Down
41 changes: 36 additions & 5 deletions nexus/external-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2793,7 +2793,7 @@ pub trait NexusExternalApi {
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<shared::SupportBundleInfo>>, HttpError>;

/// View a single support bundle
/// View a support bundle
#[endpoint {
method = GET,
path = "/experimental/v1/system/support-bundles/{support_bundle}",
Expand All @@ -2804,7 +2804,18 @@ pub trait NexusExternalApi {
path_params: Path<params::SupportBundlePath>,
) -> Result<HttpResponseOk<shared::SupportBundleInfo>, HttpError>;

/// Download the contents of a single support bundle
/// Download the index of a support bundle
#[endpoint {
method = GET,
path = "/experimental/v1/system/support-bundles/{support_bundle}/index",
tags = ["hidden"], // system/support-bundles: only one tag is allowed
}]
async fn support_bundle_index(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SupportBundlePath>,
) -> Result<Response<Body>, HttpError>;

/// Download the contents of a support bundle
#[endpoint {
method = GET,
path = "/experimental/v1/system/support-bundles/{support_bundle}/download",
Expand All @@ -2813,10 +2824,20 @@ pub trait NexusExternalApi {
async fn support_bundle_download(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SupportBundlePath>,
body: TypedBody<SupportBundleGetQueryParams>,
) -> Result<Response<Body>, HttpError>;

/// Download the metadata of a single support bundle
/// Download a file within a support bundle
#[endpoint {
method = GET,
path = "/experimental/v1/system/support-bundles/{support_bundle}/download/{file}",
tags = ["hidden"], // system/support-bundles: only one tag is allowed
}]
async fn support_bundle_download_file(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SupportBundleFilePath>,
) -> Result<Response<Body>, HttpError>;

/// Download the metadata of a support bundle
#[endpoint {
method = HEAD,
path = "/experimental/v1/system/support-bundles/{support_bundle}/download",
Expand All @@ -2825,7 +2846,17 @@ pub trait NexusExternalApi {
async fn support_bundle_head(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SupportBundlePath>,
body: TypedBody<SupportBundleGetQueryParams>,
) -> Result<Response<Body>, HttpError>;

/// Download the metadata of a file within the support bundle
#[endpoint {
method = HEAD,
path = "/experimental/v1/system/support-bundles/{support_bundle}/download/{file}",
tags = ["hidden"], // system/support-bundles: only one tag is allowed
}]
async fn support_bundle_head_file(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SupportBundleFilePath>,
) -> Result<Response<Body>, HttpError>;

/// Create a new support bundle
Expand Down
72 changes: 69 additions & 3 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ use omicron_common::api::external::NameOrId;
use omicron_common::api::external::Probe;
use omicron_common::api::external::RouterRoute;
use omicron_common::api::external::RouterRouteKind;
use omicron_common::api::external::SupportBundleGetQueryParams;
use omicron_common::api::external::SwitchPort;
use omicron_common::api::external::SwitchPortSettings;
use omicron_common::api::external::SwitchPortSettingsView;
Expand Down Expand Up @@ -6074,10 +6073,55 @@ impl NexusExternalApi for NexusExternalApiImpl {
.await
}

async fn support_bundle_index(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::SupportBundlePath>,
) -> Result<Response<Body>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;

let opctx =
crate::context::op_context_for_external_api(&rqctx).await?;

Err(nexus
.unimplemented_todo(&opctx, crate::app::Unimpl::Public)
.await
.into())
};
apictx
.context
.external_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}

async fn support_bundle_download(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::SupportBundlePath>,
_body: TypedBody<SupportBundleGetQueryParams>,
) -> Result<Response<Body>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;

let opctx =
crate::context::op_context_for_external_api(&rqctx).await?;

Err(nexus
.unimplemented_todo(&opctx, crate::app::Unimpl::Public)
.await
.into())
};
apictx
.context
.external_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}

async fn support_bundle_download_file(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::SupportBundleFilePath>,
) -> Result<Response<Body>, HttpError> {
let apictx = rqctx.context();
let handler = async {
Expand All @@ -6101,7 +6145,29 @@ impl NexusExternalApi for NexusExternalApiImpl {
async fn support_bundle_head(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::SupportBundlePath>,
_body: TypedBody<SupportBundleGetQueryParams>,
) -> Result<Response<Body>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;

let opctx =
crate::context::op_context_for_external_api(&rqctx).await?;

Err(nexus
.unimplemented_todo(&opctx, crate::app::Unimpl::Public)
.await
.into())
};
apictx
.context
.external_latencies
.instrument_dropshot_handler(&rqctx, handler)
.await
}

async fn support_bundle_head_file(
rqctx: RequestContext<Self::Context>,
_path_params: Path<params::SupportBundleFilePath>,
) -> Result<Response<Body>, HttpError> {
let apictx = rqctx.context();
let handler = async {
Expand Down
9 changes: 9 additions & 0 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ impl From<Name> for SiloSelector {
}
}

#[derive(Serialize, Deserialize, JsonSchema)]
pub struct SupportBundleFilePath {
#[serde(flatten)]
pub bundle: SupportBundlePath,

/// The file within the bundle to download
pub file: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct OptionalSiloSelector {
/// Name or ID of the silo
Expand Down
Loading

0 comments on commit 55e9c24

Please sign in to comment.