Skip to content

Commit

Permalink
feat: Parse '--enable-auto-expiry [duration]' and pass to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mman committed Oct 18, 2024
1 parent 94a22ed commit 822cc1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/bin/venus-influx-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { program } from "commander"
import buildInfo from "../buildInfo.cjs"

import { Server } from "../server/server"
import ms from "ms"

const autoExpiryDefault = "30d"

program
.version(buildInfo.buildVersion)
Expand All @@ -23,6 +26,7 @@ program
)
.option("--disable-grafana-api", "disable Grafana JSON datasource /grafana-api/ endpoint")
.option("--enable-discovery-api", "enable venus-upnp-browser /discovery-api/ endpoint")
.option("--enable-auto-expiry [duration]", "enable automatic expiry of data collection", autoExpiryDefault)
.option("--hide-settings-influxdb")
.option("--hide-settings-security")
.option("--hide-settings-venus-discovery")
Expand All @@ -43,13 +47,25 @@ const grafanaApi = options.disableGrafanaApi ? undefined : "/grafana-api/"
const port = options.port
const grafanaUrl = options.grafanaUrl

// extract autoExpiryDuration, but only when the option was used
// to workaround commander limitation where default option value
// is always present even if the option was not used at all
let autoExpiryDuration: number
if (process.argv.includes("--enable-auto-expiry")) {
autoExpiryDuration =
options.enableAutoExpiry === true ? ms(autoExpiryDefault) : ms(options.enableAutoExpiry as string)
} else {
autoExpiryDuration = 0 // disabled
}

log("Use --help to learn how to use this program")
log(`Config Path: ${options.configPath}`)
log(`Discovery API: ${discoveryApi || "disabled"}`)
log(`Admin API: ${adminApi || "disabled"}`)
log(`Grafana JSON Datasource API: ${grafanaApi || "disabled"}`)
log(`API Port: ${adminApi || grafanaApi ? port : "disabled"}`)
log(`Grafana URL: ${grafanaUrl}`)
log(`Automatic Data Collection Expiry: ${autoExpiryDuration > 0 ? ms(autoExpiryDuration, { long: true }) : "disabled"}`)

// exit on Ctrl-C
process.on("SIGINT", function () {
Expand All @@ -71,6 +87,7 @@ const server = new Server({
showEditManualSettings: !options.hideSettingsVenusManual,
showEditSecuritySettings: !options.hideSettingsSecurity && adminApiAuthEnabled,
showEditInfluxDBSettings: !options.hideSettingsInfluxdb,
showAutomaticExpirySettings: autoExpiryDuration,
},
})

Expand Down
1 change: 1 addition & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface AppUISettings {
showEditManualSettings: boolean
showEditSecuritySettings: boolean
showEditInfluxDBSettings: boolean
showAutomaticExpirySettings?: number
}

export type AppUISettingsKey = keyof AppUISettings
Expand Down

0 comments on commit 822cc1f

Please sign in to comment.