summaryrefslogtreecommitdiff
path: root/internal/config/env.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-24 13:34:06 +0300
committerPaul Buetow <paul@buetow.org>2021-10-24 13:34:19 +0300
commit14959ffba46282dd7b8ada53db0dfc0e1b26ab2e (patch)
tree0b207cb61af3aa2bd93a0c5c864ec91246dd4595 /internal/config/env.go
parentac2d6fa5d054ca725a7268eb1a8e050525372c34 (diff)
Fix DCat color test.
Diffstat (limited to 'internal/config/env.go')
-rw-r--r--internal/config/env.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/config/env.go b/internal/config/env.go
index 88b831d..804a10a 100644
--- a/internal/config/env.go
+++ b/internal/config/env.go
@@ -2,6 +2,26 @@ package config
import "os"
+// Env returns true when a given environment variable is set to "yes".
func Env(env string) bool {
return "yes" == os.Getenv(env)
}
+
+// Hostname returns the current hostname. It can be overriden with
+// DTAIL_HOSTNAME_OVERRIDE environment variable (useful for integration tests).
+func Hostname() (string, error) {
+ hostname := os.Getenv("DTAIL_HOSTNAME_OVERRIDE")
+ if len(hostname) > 0 {
+ return hostname, nil
+ }
+ return os.Hostname()
+}
+
+// SSHKnownHostsFile returns the known hosts file path (useful for integration tests)
+func SSHKnownHostsFile() string {
+ if len(os.Getenv("DTAIL_SSH_KNOWN_HOSTS_FILE")) > 0 {
+ return os.Getenv("DTAIL_SSH_KNOWN_HOSTS_FILE")
+ } else {
+ return os.Getenv("HOME") + "/.ssh/known_hosts"
+ }
+}