Files
kopia/repo/userhost.go
Jarek Kowalski f4347886b8 logging: simplified log levels (#954)
Removed Warning, Notify and Fatal:

* `Warning` => `Error` or `Info`
* `Notify` => `Info`
* `Fatal` was never used.

Note that --log-level=warning is still supported for backwards
compatibility, but it is the same as --log-level=error.

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-04-09 07:27:35 -07:00

44 lines
828 B
Go

package repo
import (
"context"
"os"
"os/user"
"runtime"
"strings"
)
// GetDefaultUserName returns default username.
func GetDefaultUserName(ctx context.Context) string {
currentUser, err := user.Current()
if err != nil {
log(ctx).Errorf("Cannot determine current user: %s", err)
return "nobody"
}
u := currentUser.Username
if runtime.GOOS == "windows" {
if p := strings.Index(u, "\\"); p >= 0 {
// On Windows ignore domain name.
u = u[p+1:]
}
}
return u
}
// GetDefaultHostName returns default hostname.
func GetDefaultHostName(ctx context.Context) string {
hostname, err := os.Hostname()
if err != nil {
log(ctx).Errorf("Unable to determine hostname: %s\n", err)
return "nohost"
}
// Normalize hostname.
hostname = strings.ToLower(strings.Split(hostname, ".")[0])
return hostname
}