Skip to content

Commit

Permalink
Merge pull request #176 from Devolutions/WAYK-2567
Browse files Browse the repository at this point in the history
WAYK-2567: Add endpoint to get logs (GET /diagnostics/logs)
  • Loading branch information
fdubois1 authored Aug 5, 2021
2 parents cf6e96b + e46601e commit ebb5fc8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
33 changes: 33 additions & 0 deletions devolutions-gateway/src/http/controllers/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::config::Config;
use crate::http::guards::access::{AccessGuard, JetTokenType};
use crate::http::HttpErrorStatus;
use jet_proto::token::JetAccessScope;
use saphir::prelude::*;
use std::sync::Arc;

pub struct DiagnosticsController {
config: Arc<Config>,
}

impl DiagnosticsController {
pub fn new(config: Arc<Config>) -> Self {
DiagnosticsController { config }
}
}

#[controller(name = "diagnostics")]
impl DiagnosticsController {
#[get("/logs")]
#[guard(
AccessGuard,
init_expr = r#"JetTokenType::Scope(JetAccessScope::GatewayDiagnosticsRead)"#
)]
async fn get_logs(&self) -> Result<File, HttpErrorStatus> {
let log_file_path = self
.config
.log_file
.as_ref()
.ok_or_else(|| HttpErrorStatus::not_found("Log file is not configured"))?;
File::open(log_file_path).await.map_err(HttpErrorStatus::internal)
}
}
1 change: 1 addition & 0 deletions devolutions-gateway/src/http/controllers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod diagnostics;
pub mod health;
pub mod http_bridge;
pub mod jet;
Expand Down
8 changes: 5 additions & 3 deletions devolutions-gateway/src/http/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::config::Config;
use crate::http::controllers::diagnostics::DiagnosticsController;
use crate::http::controllers::health::HealthController;
use crate::http::controllers::http_bridge::HttpBridgeController;
use crate::http::controllers::jet::JetController;
Expand Down Expand Up @@ -36,7 +37,9 @@ pub fn configure_http_server(config: Arc<Config>, jet_associations: JetAssociati
})
.configure_router(|router| {
info!("Loading HTTP controllers");
let diagnostics = DiagnosticsController::new(config.clone());
let health = HealthController::new(config.clone());
let http_bridge = HttpBridgeController::new();
let jet = JetController::new(config.clone(), jet_associations.clone());
let session = SessionsController;

Expand All @@ -55,17 +58,16 @@ pub fn configure_http_server(config: Arc<Config>, jet_associations: JetAssociati
let sogar = SogarController::new(registry_name.as_str(), registry_namespace.as_str());
let token_controller = TokenController::new(config.clone());

let http_bridge = HttpBridgeController::new();

info!("Configuring HTTP router");

router
.controller(diagnostics)
.controller(health)
.controller(http_bridge)
.controller(jet)
.controller(session)
.controller(sogar)
.controller(token_controller)
.controller(http_bridge)
})
.configure_listener(|listener| listener.server_name("Devolutions Gateway"))
.build_stack_only()
Expand Down
5 changes: 5 additions & 0 deletions devolutions-gateway/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ impl HttpErrorStatus {
fn bad_gateway<T: Display + Send + 'static>(source: T) -> Self {
Self::new(StatusCode::BAD_GATEWAY, source)
}

#[track_caller]
fn not_found<T: Display + Send + 'static>(source: T) -> Self {
Self::new(StatusCode::NOT_FOUND, source)
}
}

impl Responder for HttpErrorStatus {
Expand Down
2 changes: 2 additions & 0 deletions jet-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub enum JetAccessScope {
GatewaySessionsRead,
#[serde(rename = "gateway.associations.read")]
GatewayAssociationsRead,
#[serde(rename = "gateway.diagnostics.read")]
GatewayDiagnosticsRead,
}

#[derive(Clone, Deserialize)]
Expand Down

0 comments on commit ebb5fc8

Please sign in to comment.