-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/ilyakaznacheev/cleanenv" | ||
|
||
"github.com/grafana/grafana-kiosk/pkg/kiosk" | ||
) | ||
|
||
var ( | ||
// Version this is set during build time using git tags | ||
Version string | ||
) | ||
|
||
// Args command-line parameters. | ||
type Args struct { | ||
ConfigPath string | ||
} | ||
|
||
// ProcessArgs processes and handles CLI arguments. | ||
func ProcessArgs(cfg interface{}) Args { | ||
var processedArgs Args | ||
|
||
flagSettings := flag.NewFlagSet("migrate-config", flag.ContinueOnError) | ||
flagSettings.StringVar(&processedArgs.ConfigPath, "c", "", "Path to configuration file (config.yaml)") | ||
|
||
fu := flagSettings.Usage | ||
flagSettings.Usage = func() { | ||
fu() | ||
|
||
envHelp, _ := cleanenv.GetDescription(cfg, nil) | ||
|
||
fmt.Fprintln(flagSettings.Output()) | ||
fmt.Fprintln(flagSettings.Output(), envHelp) | ||
} | ||
|
||
err := flagSettings.Parse(os.Args[1:]) | ||
if err != nil { | ||
os.Exit(-1) | ||
} | ||
|
||
return processedArgs | ||
} | ||
|
||
func summary(cfg *kiosk.Config) { | ||
// general | ||
log.Println("AutoFit:", cfg.GrafanaOptions.AutoFit) | ||
log.Println("LXDEEnabled:", cfg.General.LXDEEnabled) | ||
log.Println("LXDEHome:", cfg.General.LXDEHome) | ||
log.Println("GrafanaOptions - Kiosk Mode:", cfg.GrafanaOptions.KioskMode) | ||
log.Println("WindowPosition:", cfg.ChromeDPFlags.WindowPosition) | ||
log.Println("WindowSize:", cfg.ChromeDPFlags.WindowSize) | ||
log.Println("ScaleFactor:", cfg.ChromeDPFlags.ScaleFactor) | ||
// target | ||
log.Println("URL:", cfg.Target.URL) | ||
log.Println("LoginMethod:", cfg.Target.LoginMethod) | ||
log.Println("Username:", cfg.Target.Username) | ||
log.Println("Password:", "*redacted*") | ||
log.Println("IgnoreCertificateErrors:", cfg.Target.IgnoreCertificateErrors) | ||
log.Println("IsPlayList:", cfg.Target.IsPlayList) | ||
log.Println("UseMFA:", cfg.Target.UseMFA) | ||
// goauth | ||
log.Println("Fieldname AutoLogin:", cfg.GoAuth.AutoLogin) | ||
log.Println("Fieldname Username:", cfg.GoAuth.UsernameField) | ||
log.Println("Fieldname Password:", cfg.GoAuth.PasswordField) | ||
} | ||
|
||
func main() { | ||
var cfg kiosk.Config | ||
fmt.Println("Migrate Config Version:", Version) | ||
// set the version | ||
cfg.BuildInfo.Version = Version | ||
|
||
// override | ||
args := ProcessArgs(&cfg) | ||
|
||
// check if config specified | ||
if args.ConfigPath != "" { | ||
// read configuration from the file and then override with environment variables | ||
if err := cleanenv.ReadConfig(args.ConfigPath, &cfg); err != nil { | ||
log.Println("Error reading config file", err) | ||
os.Exit(-1) | ||
} else { | ||
log.Println("Using config from", args.ConfigPath) | ||
} | ||
} | ||
summary(&cfg) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/grafana/grafana-kiosk/pkg/kiosk" | ||
"github.com/ilyakaznacheev/cleanenv" | ||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
// TestMigration checks kiosk command. | ||
func TestMigration(t *testing.T) { | ||
Convey("Given Previous YAML Configuration", t, func() { | ||
Convey("Migrate YAML Configuration", func() { | ||
Convey("General", func() { | ||
cfg := kiosk.ConfigLegacy{} | ||
pathToYAML := "../../../testdata/legacy-config-local.yaml" | ||
if err := cleanenv.ReadConfig(pathToYAML, &cfg); err != nil { | ||
log.Println("Error reading config file", err) | ||
os.Exit(-1) | ||
} else { | ||
log.Println("Using config from", pathToYAML) | ||
} | ||
So(cfg.General.AutoFit, ShouldBeTrue) | ||
So(cfg.General.Mode, ShouldEqual, "full") | ||
So(cfg.General.LXDEEnabled, ShouldBeTrue) | ||
So(cfg.General.LXDEEnabled, ShouldBeTrue) | ||
So(cfg.General.WindowSize, ShouldEqual, "1920,1080") | ||
// | ||
So(cfg.Target.LoginMethod, ShouldEqual, "local") | ||
So(cfg.Target.Username, ShouldEqual, "user1") | ||
So(cfg.Target.Password, ShouldEqual, "changeme") | ||
So(cfg.Target.IsPlayList, ShouldBeFalse) | ||
So(cfg.Target.URL, ShouldEqual, "https://notplay.grafana.com") | ||
So(cfg.Target.IgnoreCertificateErrors, ShouldBeFalse) | ||
|
||
// now migrate to new config | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kiosk | ||
|
||
// ConfigLegacy configuration for backend. | ||
type ConfigLegacy struct { | ||
BuildInfo BuildInfo `yaml:"buildinfo"` | ||
General LegacyGeneral `yaml:"general"` | ||
Target LegacyTarget `yaml:"target"` | ||
GoAuth LegacyGoAuth `yaml:"goauth"` | ||
IDToken LegacyIDToken `yaml:"idtoken"` | ||
APIKey LegacyAPIKey `yaml:"apikey"` | ||
} | ||
|
||
// LegacyGeneral non-site specific configuations | ||
type LegacyGeneral struct { | ||
AutoFit bool `yaml:"autofit" env:"KIOSK_AUTOFIT" env-default:"true" env-description:"fit panels to screen"` | ||
DebugEnabled bool `yaml:"debug" env:"KIOSK_DEBUG" env-default:"false" env-description:"enables debug output"` | ||
GPUEnabled bool `yaml:"gpu-enabled" env:"KIOSK_GPU_ENABLED" env-default:"false" env-description:"disable GPU support"` | ||
LXDEEnabled bool `yaml:"lxde" env:"KIOSK_LXDE_ENABLED" env-default:"false" env-description:"initialize LXDE for kiosk mode"` | ||
LXDEHome string `yaml:"lxde-home" env:"KIOSK_LXDE_HOME" env-default:"/home/pi" env-description:"path to home directory of LXDE user running X Server"` | ||
Mode string `yaml:"kiosk-mode" env:"KIOSK_MODE" env-default:"full" env-description:"[full|tv|disabled]"` | ||
OzonePlatform string `yaml:"ozone-platform" env:"KIOSK_OZONE_PLATFORM" env-default:"" env-description:"Set ozone-platform option (wayland|cast|drm|wayland|x11)"` | ||
PageLoadDelayMS int64 `yaml:"page-load-delay-ms" env:"KIOSK_PAGE_LOAD_DELAY_MS" env-default:"2000" env-description:"milliseconds to wait before expecting page load"` | ||
ScaleFactor string `yaml:"scale-factor" env:"KIOSK_SCALE_FACTOR" env-default:"1.0" env-description:"Scale factor, like zoom"` | ||
WindowPosition string `yaml:"window-position" env:"KIOSK_WINDOW_POSITION" env-default:"0,0" env-description:"Top Left Position of Kiosk"` | ||
WindowSize string `yaml:"window-size" env:"KIOSK_WINDOW_SIZE" env-default:"" env-description:"Size of Kiosk in pixels (width,height)"` | ||
} | ||
|
||
// LegacyTarget the dashboard/playlist details | ||
type LegacyTarget struct { | ||
IgnoreCertificateErrors bool `yaml:"ignore-certificate-errors" env:"KIOSK_IGNORE_CERTIFICATE_ERRORS" env-description:"ignore SSL/TLS certificate errors" env-default:"false"` | ||
IsPlayList bool `yaml:"playlist" env:"KIOSK_IS_PLAYLIST" env-default:"false" env-description:"URL is a playlist"` | ||
LoginMethod string `yaml:"login-method" env:"KIOSK_LOGIN_METHOD" env-default:"anon" env-description:"[anon|local|gcom|goauth|idtoken|apikey]"` | ||
Password string `yaml:"password" env:"KIOSK_LOGIN_PASSWORD" env-default:"guest" env-description:"password"` | ||
URL string `yaml:"URL" env:"KIOSK_URL" env-default:"https://play.grafana.org" env-description:"URL to Grafana server"` | ||
Username string `yaml:"username" env:"KIOSK_LOGIN_USER" env-default:"guest" env-description:"username"` | ||
UseMFA bool `yaml:"use-mfa" env:"KIOSK_USE_MFA" env-default:"false" env-description:"MFA is enabled for given account"` | ||
} | ||
|
||
// LegacyGoAuth OAuth | ||
type LegacyGoAuth struct { | ||
AutoLogin bool `yaml:"auto-login" env:"KIOSK_GOAUTH_AUTO_LOGIN" env-description:"[false|true]"` | ||
UsernameField string `yaml:"fieldname-username" env:"KIOSK_GOAUTH_FIELD_USER" env-description:"Username html input name value"` | ||
PasswordField string `yaml:"fieldname-password" env:"KIOSK_GOAUTH_FIELD_PASSWORD" env-description:"Password html input name value"` | ||
} | ||
|
||
// LegacyIDToken token based login | ||
type LegacyIDToken struct { | ||
KeyFile string `yaml:"idtoken-keyfile" env:"KIOSK_IDTOKEN_KEYFILE" env-default:"key.json" env-description:"JSON Credentials for idtoken"` | ||
Audience string `yaml:"idtoken-audience" env:"KIOSK_IDTOKEN_AUDIENCE" env-description:"Audience for idtoken, tpyically your oauth client id"` | ||
} | ||
|
||
// LegacyAPIKey APIKey for login | ||
type LegacyAPIKey struct { | ||
APIKey string `yaml:"apikey" env:"KIOSK_APIKEY_APIKEY" env-description:"APIKEY"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
general: | ||
kiosk-mode: full | ||
autofit: true | ||
lxde: true | ||
lxde-home: /home/pi | ||
window-size: 1920,1080 | ||
|
||
target: | ||
login-method: local | ||
username: user1 | ||
password: changeme | ||
playlist: false | ||
URL: https://notplay.grafana.com | ||
ignore-certificate-errors: false |