Skip to content

Commit

Permalink
🔒 Enables sensetive data to be passed by env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Apr 14, 2024
1 parent 75f65de commit 25e774c
Show file tree
Hide file tree
Showing 26 changed files with 54 additions and 51 deletions.
6 changes: 4 additions & 2 deletions src/components/Widgets/AdGuardDnsInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
/* URL/ IP or hostname to the AdGuardHome instance, without trailing slash */
hostname() {
if (!this.options.hostname) this.error('You must specify the path to your AdGuard server');
return this.options.hostname;
return this.parseAsEnvVar(this.options.hostname);
},
showFullInfo() {
return this.options.showFullInfo;
Expand All @@ -39,7 +39,9 @@ export default {
},
authHeaders() {
if (this.options.username && this.options.password) {
const encoded = window.btoa(`${this.options.username}:${this.options.password}`);
const password = this.parseAsEnvVar(this.options.password);
const username = this.parseAsEnvVar(this.options.username);
const encoded = window.btoa(`${username}:${password}`);
return { Authorization: `Basic ${encoded}` };
}
return {};
Expand Down
6 changes: 4 additions & 2 deletions src/components/Widgets/AdGuardFilterStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
/* URL/ IP or hostname to the AdGuardHome instance, without trailing slash */
hostname() {
if (!this.options.hostname) this.error('You must specify the path to your AdGuard server');
return this.options.hostname;
return this.parseAsEnvVar(this.options.hostname);
},
showOnOffStatusOnly() {
return this.options.showOnOffStatusOnly;
Expand All @@ -48,7 +48,9 @@ export default {
},
authHeaders() {
if (this.options.username && this.options.password) {
const encoded = window.btoa(`${this.options.username}:${this.options.password}`);
const username = this.parseAsEnvVar(this.options.username);
const password = this.parseAsEnvVar(this.options.password);
const encoded = window.btoa(`${username}:${password}`);
return { Authorization: `Basic ${encoded}` };
}
return {};
Expand Down
6 changes: 4 additions & 2 deletions src/components/Widgets/AdGuardStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ export default {
/* URL/ IP or hostname to the AdGuardHome instance, without trailing slash */
hostname() {
if (!this.options.hostname) this.error('You must specify the path to your AdGuard server');
return this.options.hostname;
return this.parseAsEnvVar(this.options.hostname);
},
endpoint() {
return `${this.hostname}/control/stats`;
},
authHeaders() {
if (this.options.username && this.options.password) {
const encoded = window.btoa(`${this.options.username}:${this.options.password}`);
const username = this.parseAsEnvVar(this.options.username);
const password = this.parseAsEnvVar(this.options.password);
const encoded = window.btoa(`${username}:${password}`);
return { Authorization: `Basic ${encoded}` };
}
return {};
Expand Down
6 changes: 4 additions & 2 deletions src/components/Widgets/AdGuardTopDomains.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export default {
/* URL/ IP or hostname to the AdGuardHome instance, without trailing slash */
hostname() {
if (!this.options.hostname) this.error('You must specify the path to your AdGuard server');
return this.options.hostname;
return this.parseAsEnvVar(this.options.hostname);
},
authHeaders() {
if (this.options.username && this.options.password) {
const encoded = window.btoa(`${this.options.username}:${this.options.password}`);
const username = this.parseAsEnvVar(this.options.username);
const password = this.parseAsEnvVar(this.options.password);
const encoded = window.btoa(`${username}:${password}`);
return { Authorization: `Basic ${encoded}` };
}
return {};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Widgets/AnonAddy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default {
},
computed: {
hostname() {
return this.options.hostname || widgetApiEndpoints.anonAddy;
return this.parseAsEnvVar(this.options.hostname) || widgetApiEndpoints.anonAddy;
},
apiVersion() {
return this.options.apiVersion || 'v1';
Expand All @@ -132,7 +132,7 @@ export default {
},
apiKey() {
if (!this.options.apiKey) this.error('An apiKey is required');
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
hideMeta() {
return this.options.hideMeta;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/BlacklistCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
},
apiKey() {
if (!this.options.apiKey) this.error('Missing API Key');
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
endpoint() {
return `${widgetApiEndpoints.blacklistCheck}/${this.ipAddress}`;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Widgets/CodeStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export default {
/* The username to fetch data from - REQUIRED */
username() {
if (!this.options.username) this.error('You must specify a username');
return this.options.username;
return this.parseAsEnvVar(this.options.username);
},
/* Optionally override hostname, if using a self-hosted instance */
hostname() {
if (this.options.hostname) return this.options.hostname;
return widgetApiEndpoints.codeStats;
return this.parseAsEnvVar(widgetApiEndpoints.codeStats);
},
hideMeta() {
return this.options.hideMeta || false;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Widgets/DomainMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export default {
computed: {
apiKey() {
if (!this.options.apiKey) this.error('Missing API Key');
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
domain() {
if (!this.options.domain) this.error('Missing Domain Name Key');
return this.options.domain;
return this.parseAsEnvVar(this.options.domain);
},
endpoint() {
return `${widgetApiEndpoints.domainMonitor}/?domain=${this.domain}&r=whois&apikey=${this.apiKey}`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/DroneCi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default {
if (!this.options.apiKey) {
this.error('An API key is required, please see the docs for more info');
}
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/ExchangeRates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
computed: {
/* The users API key for exchangerate-api.com */
apiKey() {
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
/* The currency to convert results into */
inputCurrency() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/Flights.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default {
this.error('An API key must be supplied');
return '';
}
return usersChoice;
return this.parseAsEnvVar(usersChoice);
},
/* The direction of flights: Arrival, Departure or Both */
direction() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/GluetunStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
},
hostname() {
if (!this.options.hostname) this.error('`hostname` is required');
return this.options.hostname;
return this.parseAsEnvVar(this.options.hostname);
},
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/HealthChecks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
this.error('An API key is required, please see the docs for more info');
}
if (typeof this.options.apiKey === 'string') {
return [this.options.apiKey];
return [this.parseAsEnvVar(this.options.apiKey)];
}
return this.options.apiKey;
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Widgets/Linkding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export default {
computed: {
endpoint() {
if (!this.options.host) this.error('linkgding Host is required');
return `${this.options.host}/api/bookmarks`;
return `${this.parseAsEnvVar(this.options.host)}/api/bookmarks`;
},
apiKey() {
if (!this.options.apiKey) this.error('linkgding apiKey is required');
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
filtertags() {
return this.options.tags;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/NewsHeadlines.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
computed: {
apiKey() {
if (!this.options.apiKey) this.error('An API key is required, see docs for more info');
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
country() {
return this.options.country ? `&country=${this.options.country}` : '';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/NextcloudNotifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</span>
<span v-if="canDeleteNotification('delete')">
<a @click="deleteNotification(notification.notification_id)"
class="action secondary">{{ tt('delete-notification') }}</a>
class="action secondary">{{ tt('delete-notification') }}</a>
</span>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/NextcloudStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<em v-html="formatNumber(shares.num_shares)"></em>
<strong>{{ tt('local') }}</strong> <small> {{ tt('and') }}</small>
<em v-html="formatNumber(shares.num_fed_shares_sent
+ shares.num_fed_shares_received)"></em>
+ shares.num_fed_shares_received)"></em>
<strong>
{{ tt('federated-shares') }}
</strong>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Widgets/Proxmox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ export default {
computed: {
clusterUrl() {
if (!this.options.cluster_url) this.error('The cluster URL is required.');
return this.options.cluster_url || '';
return this.parseAsEnvVar(this.options.cluster_url) || '';
},
userName() {
if (!this.options.user_name) this.error('The user name is required.');
return this.options.user_name || '';
return this.parseAsEnvVar(this.options.user_name) || '';
},
tokenName() {
if (!this.options.token_name) this.error('The token name is required.');
return this.options.token_name || '';
return this.parseAsEnvVar(this.options.token_name) || '';
},
tokenUuid() {
if (!this.options.token_uuid) this.error('The token uuid is required.');
return this.options.token_uuid || '';
return this.parseAsEnvVar(this.options.token_uuid) || '';
},
node() {
return this.options.node || '';
return this.parseAsEnvVar(this.options.node) || '';
},
nodeData() {
return this.options.node_data || false;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/PublicIp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
},
provider() {
// Can be either `ip-api`, `ipapi.co` or `ipgeolocation`
return this.options.provider || 'ipapi.co';
return this.parseAsEnvVar(this.options.provider) || 'ipapi.co';
},
},
data() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/RssFeed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default {
return this.options.rssUrl || '';
},
apiKey() {
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
parseLocally() {
return this.options.parseLocally;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/SportsScores.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default {
return this.options.leagueId;
},
apiKey() {
return this.options.apiKey || '50130162';
return this.parseAsEnvVar(this.options.apiKey) || '50130162';
},
limit() {
return this.options.limit || 20;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/StockPriceChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
},
/* The users API key for AlphaVantage */
apiKey() {
return this.options.apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
/* The formatted GET request API endpoint to fetch stock data from */
endpoint() {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Widgets/SynologyDownload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ export default {
computed: {
hostname() {
if (!this.options.hostname) this.error('A hostname is required');
return this.options.hostname;
return this.parseAsEnvVar(this.options.hostname);
},
username() {
if (!this.options.username) this.error('A username is required');
return this.options.username;
return this.parseAsEnvVar(this.options.username);
},
password() {
if (!this.options.password) this.error('A password is required');
return this.options.password;
return this.parseAsEnvVar(this.options.password);
},
endpointLogin() {
return `${this.hostname}/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&account=${this.username}&passwd=${this.password}&session=DownloadStation&format=sid`;
Expand Down
8 changes: 2 additions & 6 deletions src/components/Widgets/UptimeKuma.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ export default {
computed: {
/* Get API key for access to instance */
apiKey() {
const { apiKey } = this.options;
return apiKey;
return this.parseAsEnvVar(this.options.apiKey);
},
/* Get instance URL */
url() {
const { url } = this.options;
return url;
return this.parseAsEnvVar(this.options.url);
},
/* Create authorisation header for the instance from the apiKey */
authHeaders() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/WalletBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
},
address() {
if (!this.options.address) this.error('You must specify a public address');
return this.options.address;
return this.parseAsEnvVar(this.options.address);
},
network() {
return this.options.network || 'main';
Expand Down
13 changes: 6 additions & 7 deletions src/components/Widgets/Weather.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ export default {
return this.options.units || 'metric';
},
endpoint() {
const {
apiKey, city, lat, lon,
} = this.options;
if (lat && lon) {
return `${widgetApiEndpoints.weather}?lat=${lat}&lon=${lon}&appid=${apiKey}&units=${this.units}`;
}
return `${widgetApiEndpoints.weather}?q=${city}&appid=${apiKey}&units=${this.units}`;
const apiKey = this.parseAsEnvVar(this.options.apiKey);
const { city, lat, lon } = this.options;
const params = (lat && lon)
? `lat=${lat}&lon=${lon}&appid=${apiKey}&units=${this.units}`
: `q=${city}&appid=${apiKey}&units=${this.units}`;
return `${widgetApiEndpoints.weather}?${params}`;
},
tempDisplayUnits() {
switch (this.units) {
Expand Down

0 comments on commit 25e774c

Please sign in to comment.