mirror of
https://github.com/neondatabase/neon.git
synced 2026-06-03 05:20:38 +00:00
This is a refactor to create better abstractions related to our management server. It cleans up the code, and prepares everything for authorized communication to and from the control plane. Signed-off-by: Tristan Partin <tristan@neon.tech>
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use std::sync::Arc;
|
|
|
|
use axum::{extract::State, response::Response};
|
|
use compute_api::{
|
|
requests::ExtensionInstallRequest,
|
|
responses::{ComputeStatus, ExtensionInstallResponse},
|
|
};
|
|
use http::StatusCode;
|
|
|
|
use crate::{
|
|
compute::ComputeNode,
|
|
http::{extract::Json, JsonResponse},
|
|
};
|
|
|
|
/// Install a extension.
|
|
pub(in crate::http) async fn install_extension(
|
|
State(compute): State<Arc<ComputeNode>>,
|
|
request: Json<ExtensionInstallRequest>,
|
|
) -> Response {
|
|
let status = compute.get_status();
|
|
if status != ComputeStatus::Running {
|
|
return JsonResponse::invalid_status(status);
|
|
}
|
|
|
|
match compute
|
|
.install_extension(
|
|
&request.extension,
|
|
&request.database,
|
|
request.version.to_string(),
|
|
)
|
|
.await
|
|
{
|
|
Ok(version) => JsonResponse::success(
|
|
StatusCode::CREATED,
|
|
Some(ExtensionInstallResponse {
|
|
extension: request.extension.clone(),
|
|
version,
|
|
}),
|
|
),
|
|
Err(e) => JsonResponse::error(
|
|
StatusCode::INTERNAL_SERVER_ERROR,
|
|
format!("failed to install extension: {e}"),
|
|
),
|
|
}
|
|
}
|