From 460b014e91d7a48caa86c44b2b4b1c1840271f75 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 12 Jun 2023 15:41:45 +0100 Subject: [PATCH] swagger-ui allows adding X-REMOTE_USER header when behind proxy --- lib/App/Netdisco/Web.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/App/Netdisco/Web.pm b/lib/App/Netdisco/Web.pm index edbc0444..da423707 100644 --- a/lib/App/Netdisco/Web.pm +++ b/lib/App/Netdisco/Web.pm @@ -425,6 +425,20 @@ if ($api_requires_key) { $swagger_doc->{security} = [ { APIKeyHeader => [] } ]; } +if (setting('trust_x_remote_user')) { + foreach my $path (keys %{ $swagger_doc->{paths} }) { + foreach my $method (keys %{ $swagger_doc->{paths}->{$path} }) { + unshift @{ $swagger_doc->{paths}->{$path}->{$method}->{parameters} }, { + name => 'X-REMOTE_USER', + description => 'API client user name', + in => 'header', + required => true, + type => 'string', + }; + } + } +} + # manually install Swagger UI routes because plugin doesn't handle non-root # hosting, so we cannot use show_ui(1) my $swagger_base = config->{plugins}->{Swagger}->{ui_url};