|
@@ -1,5 +1,10 @@
|
|
package client
|
|
package client
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Functions for reading and writing the auth token from the user's
|
|
|
|
+ home directory.
|
|
|
|
+*/
|
|
|
|
+
|
|
import (
|
|
import (
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"ngrok/log"
|
|
"ngrok/log"
|
|
@@ -9,21 +14,17 @@ import (
|
|
"sync"
|
|
"sync"
|
|
)
|
|
)
|
|
|
|
|
|
-/*
|
|
|
|
- Functions for reading and writing the auth token from the user's
|
|
|
|
- home directory.
|
|
|
|
-*/
|
|
|
|
var (
|
|
var (
|
|
once sync.Once
|
|
once sync.Once
|
|
currentAuthToken string
|
|
currentAuthToken string
|
|
authTokenFile string
|
|
authTokenFile string
|
|
)
|
|
)
|
|
|
|
|
|
-func Init() {
|
|
|
|
|
|
+func initAuth() {
|
|
user, err := user.Current()
|
|
user, err := user.Current()
|
|
|
|
|
|
- // os.Getenv("HOME") hack is here to support osx -> linux cross-compilation
|
|
|
|
- // because user.Current() only cross compiles correctly from osx -> windows
|
|
|
|
|
|
+ // user.Current() does not work on linux when cross compilling because
|
|
|
|
+ // it requires CGO; use os.Getenv("HOME") hack until we compile natively
|
|
homeDir := os.Getenv("HOME")
|
|
homeDir := os.Getenv("HOME")
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Warn("Failed to get user's home directory: %s", err.Error())
|
|
log.Warn("Failed to get user's home directory: %s", err.Error())
|
|
@@ -43,11 +44,13 @@ func Init() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Load the auth token from file
|
|
func LoadAuthToken() string {
|
|
func LoadAuthToken() string {
|
|
- once.Do(func() { Init() })
|
|
|
|
|
|
+ once.Do(initAuth)
|
|
return currentAuthToken
|
|
return currentAuthToken
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Save the auth token to file
|
|
func SaveAuthToken(token string) {
|
|
func SaveAuthToken(token string) {
|
|
if token == "" || token == LoadAuthToken() || authTokenFile == "" {
|
|
if token == "" || token == LoadAuthToken() || authTokenFile == "" {
|
|
return
|
|
return
|