🔀 Merge pull request #1438 from zigotica/FEATURE/environment-variables

 Feature: add user defined environment variables
This commit is contained in:
Alicia Sykes 2024-04-14 18:22:49 +01:00 committed by GitHub
commit 27a8c8fa56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 81 additions and 58 deletions

114
.env
View File

@ -1,55 +1,59 @@
# Store environmental variables here. All variables are optional. # Store environmental variables here. All variables are optional.
# Lines beginning in '#' are ignored. # Lines beginning in '#' are ignored.
# Can be either development, production or test # Can be either development, production or test
# NODE_ENV=production # NODE_ENV=production
# The port to expose the running application on # The port to expose the running application on
# PORT=4000 # PORT=4000
# If you've proved SSL certs, then can set HTTPS port # If you've proved SSL certs, then can set HTTPS port
# SSL_PORT=4001 # SSL_PORT=4001
# The host that Dashy is running on, domain or IP # The host that Dashy is running on, domain or IP
# HOST=localhost # HOST=localhost
# The default base path for serving up static assets # The default base path for serving up static assets
# BASE_URL=./ # BASE_URL=./
# Optionally, specify the path of SSL private + public keys # Optionally, specify the path of SSL private + public keys
# SSL_PRIV_KEY_PATH=/etc/ssl/certs/dashy-priv.key # SSL_PRIV_KEY_PATH=/etc/ssl/certs/dashy-priv.key
# SSL_PUB_KEY_PATH=/etc/ssl/certs/dashy-pub.pem # SSL_PUB_KEY_PATH=/etc/ssl/certs/dashy-pub.pem
# If SSL enabled, choose whether or not to redirect http to https # If SSL enabled, choose whether or not to redirect http to https
# Defaults to true # Defaults to true
# REDIRECT_HTTPS=true # REDIRECT_HTTPS=true
# The path to the user data directory # The path to the user data directory
# USER_DATA_DIR=user-data # USER_DATA_DIR=user-data
# Override where the path to the configuration file is, can be a remote URL # Override where the path to the configuration file is, can be a remote URL
# VUE_APP_CONFIG_PATH=/conf.yml # VUE_APP_CONFIG_PATH=/conf.yml
# Usually the same as BASE_URL, but accessible in frontend # Usually the same as BASE_URL, but accessible in frontend
# VUE_APP_DOMAIN=https://dashy.to # VUE_APP_DOMAIN=https://dashy.to
# Override the page title for the frontend app # Override the page title for the frontend app
# VUE_APP_TITLE='' # VUE_APP_TITLE=''
# Set the default view to load on startup (can be `minimal`, `workspace` or `home`) # Set the default view to load on startup (can be `minimal`, `workspace` or `home`)
# VUE_APP_STARTING_VIEW=home # VUE_APP_STARTING_VIEW=home
# Set the Vue app routing mode (can be 'hash', 'history' or 'abstract') # Set the Vue app routing mode (can be 'hash', 'history' or 'abstract')
# VUE_APP_ROUTING_MODE=history # VUE_APP_ROUTING_MODE=history
# Should enable SRI for build script and link resources # Should enable SRI for build script and link resources
# INTEGRITY=true # INTEGRITY=true
# Computed automatically on build. Indicates if running in container # Computed automatically on build. Indicates if running in container
# IS_DOCKER=true # IS_DOCKER=true
# Again, set automatically using package.json during build time # Again, set automatically using package.json during build time
# VUE_APP_VERSION=2.0.0 # VUE_APP_VERSION=2.0.0
# Directory for conf.yml backups # Directory for conf.yml backups
# BACKUP_DIR=./user-data/ # BACKUP_DIR=./user-data/
# Setup any other user defined vars by prepending VUE_APP_ to the var name
# VUE_APP_pihole_ip=http://your.pihole.ip
# VUE_APP_pihole_key=your_pihole_secret_key

View File

@ -1554,6 +1554,19 @@ Displays the number of queries blocked by [Pi-Hole](https://pi-hole.net/).
apiKey: xxxxxxxxxxxxxxxxxxxxxxx apiKey: xxxxxxxxxxxxxxxxxxxxxxx
``` ```
> [!TIP]
> In order to avoid leaking secret data, both `hostname` and `apiKey` can leverage environment variables. Simply pass the name of the variable, which MUST start with `VUE_APP_`.
```yaml
- type: pi-hole-stats
options:
hostname: VUE_APP_pihole_ip
apiKey: VUE_APP_pihole_key
```
> [!IMPORTANT]
> You will need to restart the server (or the docker image) if adding/editing an env var for this to be refreshed.
#### Info #### Info
- **CORS**: 🟢 Enabled - **CORS**: 🟢 Enabled

View File

@ -36,13 +36,14 @@ export default {
computed: { computed: {
/* Let user select which comic to display: random, latest or a specific number */ /* Let user select which comic to display: random, latest or a specific number */
hostname() { hostname() {
const usersChoice = this.options.hostname; const usersChoice = this.parseAsEnvVar(this.options.hostname);
if (!usersChoice) this.error('You must specify the hostname for your Pi-Hole server'); if (!usersChoice) this.error('You must specify the hostname for your Pi-Hole server');
return usersChoice || 'http://pi.hole'; return usersChoice || 'http://pi.hole';
}, },
apiKey() { apiKey() {
if (!this.options.apiKey) this.error('API Key is required, please see the docs'); const usersChoice = this.parseAsEnvVar(this.options.apiKey);
return this.options.apiKey; if (!usersChoice) this.error('API Key is required, please see the docs');
return usersChoice;
}, },
endpoint() { endpoint() {
return `${this.hostname}/admin/api.php?summary&auth=${this.apiKey}`; return `${this.hostname}/admin/api.php?summary&auth=${this.apiKey}`;

View File

@ -131,6 +131,11 @@ const WidgetMixin = {
}); });
}); });
}, },
/* Check if a value is an environment variable, return its value if so. */
parseAsEnvVar(str) {
if (str.includes('VUE_APP_')) return process.env[str];
return str;
},
}, },
}; };