mirror of
https://github.com/kopia/kopia.git
synced 2026-05-19 12:14:45 -04:00
* cli: added --tls-print-server-cert flag This prints complete server certificate that is base64 and PEM-encoded. It is needed for Electron to securely connect to the server outside of the browser, since there's no way to trust certificate by fingerprint. * server: added repo/exists API * server: added ClientOptions to create and connect API * server: exposed current-user API * server: API to change description of a repository * htmlui: refactored connect/create flow This cleaned up the code a lot and made UX more obvious. * kopia-ui: simplified repository management UX Removed repository configuration window which was confusing due to the notion of 'server'. Now KopiaUI will automatically launch 'kopia server --ui' for each config found in the kopia config directory and shut it down every time repository is disconnected. See https://youtu.be/P4Ll_LR4UVM for a quick demo. Fixes #583
44 lines
832 B
Go
44 lines
832 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).Warningf("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).Warningf("Unable to determine hostname: %s\n", err)
|
|
return "nohost"
|
|
}
|
|
|
|
// Normalize hostname.
|
|
hostname = strings.ToLower(strings.Split(hostname, ".")[0])
|
|
|
|
return hostname
|
|
}
|