From 50bee9723680a51b18bf93e213801262a7607e97 Mon Sep 17 00:00:00 2001 From: Sam Cohen Date: Mon, 15 Nov 2021 10:49:09 -0500 Subject: [PATCH] Allow setting URL in config file * Update config YAML parser to read a key called `url`, which points to the APIEndpoint we'd like to use * Unhide the `--url` CLI parameter * These changes benefit users running self-hosted versions of the software --- cmd/deviceplane/configure/configure.go | 9 +++++++++ cmd/deviceplane/main.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/deviceplane/configure/configure.go b/cmd/deviceplane/configure/configure.go index a5f5fe6..92cc43b 100644 --- a/cmd/deviceplane/configure/configure.go +++ b/cmd/deviceplane/configure/configure.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "io/ioutil" + "net/url" "os" "os/user" "path/filepath" @@ -18,6 +19,7 @@ import ( type ConfigValues struct { AccessKey *string `yaml:"access-key,omitempty"` Project *string `yaml:"project,omitempty"` + Url *string `yaml:"url,omitempty"` } func populateEmptyValuesFromConfig(c *kingpin.ParseContext) (err error) { @@ -96,6 +98,13 @@ func populateEmptyValuesFromConfig(c *kingpin.ParseContext) (err error) { *gConfig.Flags.Project = *configValues.Project } } + if gConfig.Flags.APIEndpoint != nil { + u, err := url.Parse(*configValues.Url) + if err != nil { + return errors.Wrap(err, "invalid url") + } + *gConfig.Flags.APIEndpoint = u + } return nil } diff --git a/cmd/deviceplane/main.go b/cmd/deviceplane/main.go index 3f9bcc2..25355a8 100644 --- a/cmd/deviceplane/main.go +++ b/cmd/deviceplane/main.go @@ -23,7 +23,7 @@ var ( ParsedCorrectly: app.Flag("internal-parsing-validator", "").Hidden().Default("true").Bool(), Flags: global.ConfigFlags{ - APIEndpoint: app.Flag("url", "API Endpoint.").Hidden().Default("https://cloud.deviceplane.com:443/api").URL(), + APIEndpoint: app.Flag("url", "API Endpoint.").Default("https://cloud.deviceplane.com:443/api").URL(), AccessKey: app.Flag("access-key", "Access key used for authentication. (env: DEVICEPLANE_ACCESS_KEY)").Envar("DEVICEPLANE_ACCESS_KEY").String(), Project: app.Flag("project", "Project name. (env: DEVICEPLANE_PROJECT)").Envar("DEVICEPLANE_PROJECT").String(), ConfigFile: app.Flag("config", "Config file to use.").Default("~/.deviceplane/config").String(),