mirror of
https://github.com/fosrl/newt.git
synced 2025-05-12 21:20:39 +01:00
Allow use of env vars
This commit is contained in:
parent
41f0973308
commit
2897b92f72
3 changed files with 32 additions and 24 deletions
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
services:
|
||||
newt:
|
||||
image: newttest
|
||||
container_name: newt
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- PANGOLIN_ENDPOINT=https://proxy.schwartznetwork.net
|
||||
- NEWT_ID=2ix2t8xk22ubpfy
|
||||
- NEWT_SECRET=nnisrfsdfc7prqsp9ewo1dvtvci50j5uiqotez00dgap0ii2
|
||||
- LOG_LEVEL=DEBUG
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Sample from https://github.com/traefik/traefik-library-image/blob/5070edb25b03cca6802d75d5037576c840f73fdd/v3.1/alpine/entrypoint.sh
|
||||
|
||||
set -e
|
||||
|
||||
# first arg is `-f` or `--some-option`
|
||||
|
@ -9,13 +7,4 @@ if [ "${1#-}" != "$1" ]; then
|
|||
set -- newt "$@"
|
||||
fi
|
||||
|
||||
# if our command is a valid newt subcommand, let's invoke it through newt instead
|
||||
# (this allows for "docker run newt version", etc)
|
||||
if newt "$1" --help >/dev/null 2>&1
|
||||
then
|
||||
set -- newt "$@"
|
||||
else
|
||||
echo "= '$1' is not a newt command: assuming shell execution." 1>&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
35
main.go
35
main.go
|
@ -222,13 +222,6 @@ func resolveDomain(domain string) (string, error) {
|
|||
return ipAddr, nil
|
||||
}
|
||||
|
||||
func getEnvWithDefault(key, defaultValue string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
return value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
endpoint string
|
||||
|
@ -240,12 +233,28 @@ func main() {
|
|||
logLevel string
|
||||
)
|
||||
|
||||
// Define CLI flags with default values from environment variables
|
||||
flag.StringVar(&endpoint, "endpoint", os.Getenv("PANGOLIN_ENDPOINT"), "Endpoint of your pangolin server")
|
||||
flag.StringVar(&id, "id", os.Getenv("NEWT_ID"), "Newt ID")
|
||||
flag.StringVar(&secret, "secret", os.Getenv("NEWT_SECRET"), "Newt secret")
|
||||
flag.StringVar(&dns, "dns", getEnvWithDefault("DEFAULT_DNS", "8.8.8.8"), "DNS server to use")
|
||||
flag.StringVar(&logLevel, "log-level", getEnvWithDefault("LOG_LEVEL", "INFO"), "Log level (DEBUG, INFO, WARN, ERROR, FATAL)")
|
||||
// if PANGOLIN_ENDPOINT, NEWT_ID, and NEWT_SECRET are set as environment variables, they will be used as default values
|
||||
endpoint = os.Getenv("PANGOLIN_ENDPOINT")
|
||||
id = os.Getenv("NEWT_ID")
|
||||
secret = os.Getenv("NEWT_SECRET")
|
||||
dns = os.Getenv("DNS")
|
||||
logLevel = os.Getenv("LOG_LEVEL")
|
||||
|
||||
if endpoint == "" {
|
||||
flag.StringVar(&endpoint, "endpoint", "", "Endpoint of your pangolin server")
|
||||
}
|
||||
if id == "" {
|
||||
flag.StringVar(&id, "id", "", "Newt ID")
|
||||
}
|
||||
if secret == "" {
|
||||
flag.StringVar(&secret, "secret", "", "Newt secret")
|
||||
}
|
||||
if dns == "" {
|
||||
flag.StringVar(&dns, "dns", "8.8.8.8", "DNS server to use")
|
||||
}
|
||||
if logLevel == "" {
|
||||
flag.StringVar(&logLevel, "log-level", "INFO", "Log level (DEBUG, INFO, WARN, ERROR, FATAL)")
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
logger.Init()
|
||||
|
|
Loading…
Reference in a new issue