1
0
Fork 0
mirror of https://github.com/Luzifer/vault-user-token.git synced 2024-12-30 01:31:21 +00:00

Support shortening hostnames to first part

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2017-07-06 14:00:11 +02:00
parent 53fc4b4ae3
commit 193e4d3884
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"time" "time"
"github.com/Luzifer/rconfig" "github.com/Luzifer/rconfig"
@ -16,6 +17,8 @@ var (
cfg = struct { cfg = struct {
LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warning, error)"` LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warning, error)"`
UseFullHostname bool `flag:"full-hostname" default:"true" description:"Use the full reported hostname (true) or only the first part (false)"`
VaultAddress string `flag:"vault-addr" env:"VAULT_ADDR" default:"https://127.0.0.1:8200" description:"Vault API address"` VaultAddress string `flag:"vault-addr" env:"VAULT_ADDR" default:"https://127.0.0.1:8200" description:"Vault API address"`
VaultRoleID string `flag:"vault-role-id" env:"VAULT_ROLE_ID" default:"" description:"ID of the role to use"` VaultRoleID string `flag:"vault-role-id" env:"VAULT_ROLE_ID" default:"" description:"ID of the role to use"`
@ -52,6 +55,10 @@ func init() {
if hostname, err = os.Hostname(); err != nil { if hostname, err = os.Hostname(); err != nil {
log.Fatalf("Could not resolve hostname: %s", err) log.Fatalf("Could not resolve hostname: %s", err)
} }
if parts := strings.Split(hostname, "."); !cfg.UseFullHostname && len(parts) > 1 {
hostname = parts[0]
}
} }
func main() { func main() {