From fd1be695d4590d24d2039efc8855b5a866bed852 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Fri, 7 Apr 2023 21:49:13 +0400 Subject: [PATCH] Environment variable overrides (#74) * Environment variable overrides * Remove ORCHARD_CONTEXT --- README.md | 10 ++++++++++ internal/config/env.go | 7 +++++++ internal/config/handle.go | 11 +++++++++++ 3 files changed, 28 insertions(+) create mode 100644 internal/config/env.go diff --git a/README.md b/README.md index 4636176..1a61593 100644 --- a/README.md +++ b/README.md @@ -66,3 +66,13 @@ From architecture perspective, Orchard has a lower level API for port forwarding All port forwarding connections are done via the Orchard Controller instance which "proxies" a secure connection to the Orchard Workers. Therefore, your workers can be located under a stricter firewall that only allows connections to the Orchard Controller instance. Orchard Controller instance is secured by default and all API calls are authenticated and authorized. + +### Environment variables + +In addition to controlling the Orchard via the CLI arguments, there are environment variables that may be beneficial both when automating Orchard and in daily use: + +| Variable name | Description | +|---------------------------------|------------------------------------------------------------------------------------| +| `ORCHARD_URL` | Override controller URL on per-command basis | +| `ORCHARD_SERVICE_ACCOUNT_NAME` | Override service account name (used for controller API auth) on per-command basis | +| `ORCHARD_SERVICE_ACCOUNT_TOKEN` | Override service account token (used for controller API auth) on per-command basis | diff --git a/internal/config/env.go b/internal/config/env.go new file mode 100644 index 0000000..1d298d8 --- /dev/null +++ b/internal/config/env.go @@ -0,0 +1,7 @@ +package config + +const ( + OrchardURL = "ORCHARD_URL" + OrchardServiceAccountName = "ORCHARD_SERVICE_ACCOUNT_NAME" + OrchardServiceAccountToken = "ORCHARD_SERVICE_ACCOUNT_TOKEN" +) diff --git a/internal/config/handle.go b/internal/config/handle.go index c2db192..2a4e0e4 100644 --- a/internal/config/handle.go +++ b/internal/config/handle.go @@ -116,6 +116,17 @@ func (handle *Handle) DefaultContext() (Context, error) { } } + // Environment variable overrides + if url, ok := os.LookupEnv(OrchardURL); ok { + defaultContext.URL = url + } + if serviceAccountName, ok := os.LookupEnv(OrchardServiceAccountName); ok { + defaultContext.ServiceAccountName = serviceAccountName + } + if serviceAccountToken, ok := os.LookupEnv(OrchardServiceAccountToken); ok { + defaultContext.ServiceAccountToken = serviceAccountToken + } + return defaultContext, nil }