Skip to content

Commit

Permalink
WAYK-2568: Add an endpoint to get configuration information (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdubois1 authored Aug 6, 2021
1 parent ebb5fc8 commit cad3d42
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion devolutions-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum Protocol {
Unknown,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct ListenerConfig {
pub internal_url: Url,
pub external_url: Url,
Expand Down
26 changes: 25 additions & 1 deletion devolutions-gateway/src/http/controllers/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::Config;
use crate::config::{Config, ListenerConfig};
use crate::http::guards::access::{AccessGuard, JetTokenType};
use crate::http::HttpErrorStatus;
use jet_proto::token::JetAccessScope;
Expand All @@ -9,6 +9,21 @@ pub struct DiagnosticsController {
config: Arc<Config>,
}

#[derive(Serialize)]
struct GatewayConfigurationResponse {
hostname: String,
listeners: Vec<ListenerConfig>,
}

impl From<Arc<Config>> for GatewayConfigurationResponse {
fn from(config: Arc<Config>) -> Self {
GatewayConfigurationResponse {
listeners: config.listeners.clone(),
hostname: config.hostname.clone(),
}
}
}

impl DiagnosticsController {
pub fn new(config: Arc<Config>) -> Self {
DiagnosticsController { config }
Expand All @@ -30,4 +45,13 @@ impl DiagnosticsController {
.ok_or_else(|| HttpErrorStatus::not_found("Log file is not configured"))?;
File::open(log_file_path).await.map_err(HttpErrorStatus::internal)
}

#[get("/configuration")]
#[guard(
AccessGuard,
init_expr = r#"JetTokenType::Scope(JetAccessScope::GatewayDiagnosticsRead)"#
)]
async fn get_configuration(&self) -> Json<GatewayConfigurationResponse> {
Json(self.config.clone().into())
}
}

0 comments on commit cad3d42

Please sign in to comment.