Environment variable overrides (#74)

* Environment variable overrides

* Remove ORCHARD_CONTEXT
This commit is contained in:
Nikolay Edigaryev 2023-04-07 21:49:13 +04:00 committed by GitHub
parent 316f785a0c
commit fd1be695d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -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 |

7
internal/config/env.go Normal file
View File

@ -0,0 +1,7 @@
package config
const (
OrchardURL = "ORCHARD_URL"
OrchardServiceAccountName = "ORCHARD_SERVICE_ACCOUNT_NAME"
OrchardServiceAccountToken = "ORCHARD_SERVICE_ACCOUNT_TOKEN"
)

View File

@ -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
}