-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gateway): Add API to trigger Gateway update
- Loading branch information
1 parent
5256b9f
commit 4a8ecee
Showing
10 changed files
with
92 additions
and
1 deletion.
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 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
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use axum::extract::Query; | ||
use axum::Json; | ||
use hyper::StatusCode; | ||
|
||
use devolutions_agent_shared::{get_updater_file_path, ProductUpdateInfo, UpdateJson, VersionSpecification}; | ||
|
||
use crate::extract::UpdateScope; | ||
use crate::http::{HttpError, HttpErrorBuilder}; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct UpdateQueryParam { | ||
version: VersionSpecification, | ||
} | ||
|
||
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] | ||
#[derive(Serialize)] | ||
pub(crate) struct UpdateResponse {} | ||
|
||
/// Starts Devolutions Gateway update process | ||
#[cfg_attr(feature = "openapi", utoipa::path( | ||
get, | ||
operation_id = "Update", | ||
tag = "Update", | ||
path = "/jet/update", | ||
responses( | ||
(status = 200, description = "Update request has been processed successfully", body = UpdateResponse), | ||
(status = 400, description = "Bad request"), | ||
(status = 401, description = "Invalid or missing authorization token"), | ||
(status = 403, description = "Insufficient permissions"), | ||
(status = 500, description = "Agent updater service is malfunctioning"), | ||
(status = 503, description = "Agent updater service is unavailable"), | ||
), | ||
security(("scope_token" = ["gateway.update"])), | ||
))] | ||
pub(super) async fn start_update( | ||
Query(query): Query<UpdateQueryParam>, | ||
_scope: UpdateScope, | ||
) -> Result<Json<UpdateResponse>, HttpError> { | ||
let target_version = query.version; | ||
|
||
let updater_file_path = get_updater_file_path(); | ||
|
||
if !updater_file_path.exists() { | ||
error!("Failed to start Gateway update, `update.json` does not exist (should be created by Devolutions Agent)"); | ||
|
||
return Err(HttpErrorBuilder::new(StatusCode::SERVICE_UNAVAILABLE).msg("Agent updater service is unavailable")); | ||
} | ||
|
||
let update_json = UpdateJson { | ||
gateway: Some(ProductUpdateInfo { target_version }), | ||
}; | ||
|
||
serde_json::to_string(&update_json) | ||
.ok() | ||
.and_then(|serialized| std::fs::write(updater_file_path, serialized).ok()) | ||
.ok_or_else(|| { | ||
error!("Failed to write new Gateway version to `update.json`"); | ||
HttpErrorBuilder::new(StatusCode::INTERNAL_SERVER_ERROR).msg("Agent updater service is unavailable") | ||
})?; | ||
|
||
Ok(Json(UpdateResponse {})) | ||
} |
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