Skip to content

Commit

Permalink
feat(config): Visualise config file in Butler hosted web page
Browse files Browse the repository at this point in the history
Implements #1199
  • Loading branch information
Göran Sander committed Aug 27, 2024
1 parent aaf414e commit 29356ce
Show file tree
Hide file tree
Showing 10 changed files with 1,778 additions and 877 deletions.
1 change: 0 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ async function build(opts = {}) {
const dirContents = fs.readdirSync(globals.appBasePath);
globals.logger.verbose(`CONFIG VIS: Directory contents of "${globals.appBasePath}": ${dirContents}`);


const htmlDir = path.resolve(globals.appBasePath, 'static/configvis');
globals.logger.info(`CONFIG VIS: Serving static files from ${htmlDir}`);

Expand Down
14 changes: 7 additions & 7 deletions src/config/config-gen-api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Butler:
# More info on whata data is collected: https://butler.ptarmiganlabs.com/docs/about/telemetry/
# Please consider leaving this at true - it really helps future development of Butler!

# Should Butler start a web server that serves an obfuscated view of the Butler config file?
configVisualisation:
enable: false
host: localhost # Hostname or IP address where the web server will listen. Should be localhost in most cases.
port: 3100 # Port where the web server will listen. Change if port 3100 is already in use.
obfuscate: true # Should the config file shown in the web UI be obfuscated?

# Heartbeats can be used to send "I'm alive" messages to any other tool, e.g. an infrastructure monitoring tool
heartbeat:
enable: false
Expand Down Expand Up @@ -805,13 +812,6 @@ Butler:
webhook:
enable: false

# Should Butler start a web server that serves an obfuscated view of the Butler config file?
configVisualisation:
enable: false
host: localhost # Hostname or IP address where the web server will listen. Should be localhost in most cases.
port: 3100 # Port where the web server will listen. Change if port 3100 is already in use.
obfuscate: true # Should the config file shown in the web UI be obfuscated?

# Certificates to use when connecting to Sense. Get these from the Certificate Export in QMC.
cert:
clientCert: ...
Expand Down
14 changes: 7 additions & 7 deletions src/config/production_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Butler:
# More info on whata data is collected: https://butler.ptarmiganlabs.com/docs/about/telemetry/
# Please consider leaving this at true - it really helps future development of Butler!

# Should Butler start a web server that serves an obfuscated view of the Butler config file?
configVisualisation:
enable: true
host: localhost # Hostname or IP address where the web server will listen. Should be localhost in most cases.
port: 3100 # Port where the web server will listen. Change if port 3100 is already in use.
obfuscate: true # Should the config file shown in the web UI be obfuscated?

# Heartbeats can be used to send "I'm alive" messages to any other tool, e.g. an infrastructure monitoring tool
heartbeat:
enable: false
Expand Down Expand Up @@ -914,13 +921,6 @@ Butler:
webhook: # Send service alerts as outbound webhooks/http calls
enable: true

# Should Butler start a web server that serves an obfuscated view of the Butler config file?
configVisualisation:
enable: true
host: localhost # Hostname or IP address where the web server will listen. Should be localhost in most cases.
port: 3100 # Port where the web server will listen. Change if port 3100 is already in use.
obfuscate: true # Should the config file shown in the web UI be obfuscated?

# Certificates to use when connecting to Sense. Get these from the Certificate Export in QMC.
cert:
clientCert: <path/to/cert/client.pem>
Expand Down
42 changes: 21 additions & 21 deletions src/lib/assert/assert_config_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,27 @@ export const configFileStructureAssert = async (config, logger) => {
configFileCorrect = false;
}

// Config visualisation setttings
if (!config.has('Butler.configVisualisation.enable')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.enable"');
configFileCorrect = false;
}

if (!config.has('Butler.configVisualisation.host')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.host"');
configFileCorrect = false;
}

if (!config.has('Butler.configVisualisation.port')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.port"');
configFileCorrect = false;
}

if (!config.has('Butler.configVisualisation.obfuscate')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.obfuscate"');
configFileCorrect = false;
}

if (!config.has('Butler.heartbeat.enable')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.heartbeat.enable"');
configFileCorrect = false;
Expand Down Expand Up @@ -4951,27 +4972,6 @@ export const configFileStructureAssert = async (config, logger) => {
configFileCorrect = false;
}

// Config visualisation setttings
if (!config.has('Butler.configVisualisation.enable')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.enable"');
configFileCorrect = false;
}

if (!config.has('Butler.configVisualisation.host')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.host"');
configFileCorrect = false;
}

if (!config.has('Butler.configVisualisation.port')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.port"');
configFileCorrect = false;
}

if (!config.has('Butler.configVisualisation.obfuscate')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.configVisualisation.obfuscate"');
configFileCorrect = false;
}

if (!config.has('Butler.cert.clientCert')) {
logger.error('ASSERT CONFIG: Missing config file entry "Butler.cert.clientCert"');
configFileCorrect = false;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/config_obfuscate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ function configObfuscate(config) {
try {
const obfuscatedConfig = { ...config };

// Obfuscate Butler.configVisualisation.host, keep first 3 chars, mask the rest with *
obfuscatedConfig.Butler.configVisualisation.host =
obfuscatedConfig.Butler.configVisualisation.host.substring(0, 3) + '*'.repeat(10);

// Keep first 10 chars of remote URL, mask the rest with *
obfuscatedConfig.Butler.heartbeat.remoteURL = obfuscatedConfig.Butler.heartbeat.remoteURL.substring(0, 10) + '*'.repeat(10);

Expand Down
5 changes: 2 additions & 3 deletions static/configvis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<html lang="en">
<head>
<title>Ctrl-Q</title>
<title>Butler</title>

<link rel="stylesheet" href="jsontree.js.css" />
<script src="jsontree.js"></script>
Expand Down Expand Up @@ -182,9 +182,8 @@ <h3>JSON tree view</h3>
sortPropertyNames: false,
sortPropertyNamesInAlphabeticalOrder: false,
data: {{butlerConfigJsonEncoded}} }"
style="width: 100%"
style="width: 100%; max-width: 100%"
>
Your HTML.
</div>
</div>

Expand Down
Loading

0 comments on commit 29356ce

Please sign in to comment.