export config paths
This commit is contained in:
parent
bd93a5dee4
commit
8bb4703577
@ -6,7 +6,7 @@ package localconfig
|
||||
import "os"
|
||||
|
||||
// Configfile is the OS dependent config file location
|
||||
func getConfig(filename string) string {
|
||||
func GetConfigPath(filename string) string {
|
||||
home, _ := os.UserHomeDir()
|
||||
return home + "/." + filename
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
package localconfig
|
||||
|
||||
// Configfile is the OS dependent config file location
|
||||
func getConfig(filename string) string {
|
||||
func GetConfigPath(filename string) string {
|
||||
return ".\\" + filename
|
||||
}
|
||||
|
12
creds.go
12
creds.go
@ -31,7 +31,7 @@ func randomString(n int) string {
|
||||
}
|
||||
|
||||
func loadRootKey() []byte {
|
||||
rkpath := getConfig("rk")
|
||||
rkpath := GetConfigPath("rk")
|
||||
rk, err := os.ReadFile(rkpath)
|
||||
if err != nil {
|
||||
rk = []byte(randomString(64))
|
||||
@ -41,7 +41,7 @@ func loadRootKey() []byte {
|
||||
}
|
||||
|
||||
func (creds *Creds) Exists(filename string) bool {
|
||||
if _, err := os.Stat(getConfig(filename)); err == nil {
|
||||
if _, err := os.Stat(GetConfigPath(filename)); err == nil {
|
||||
return true
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
return false
|
||||
@ -64,9 +64,9 @@ func (creds *Creds) Init(filename string) {
|
||||
if silentPassword != "" {
|
||||
creds.Password = silentPassword
|
||||
b, _ := json.Marshal(creds)
|
||||
fmt.Println("Writing credentials to : " + getConfig(filename))
|
||||
fmt.Println("Writing credentials to : " + GetConfigPath(filename))
|
||||
armor, _ := helper.EncryptMessageWithPassword(loadRootKey(), string(b))
|
||||
os.WriteFile(getConfig(filename), []byte(armor), 0600)
|
||||
os.WriteFile(GetConfigPath(filename), []byte(armor), 0600)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,13 +80,13 @@ func (creds *Creds) NewPw(filename string) {
|
||||
creds.Password = silentPassword
|
||||
b, _ := json.Marshal(creds)
|
||||
armor, _ := helper.EncryptMessageWithPassword(loadRootKey(), string(b))
|
||||
os.WriteFile(getConfig(filename), []byte(armor), 0600)
|
||||
os.WriteFile(GetConfigPath(filename), []byte(armor), 0600)
|
||||
}
|
||||
}
|
||||
|
||||
// Load credentials if available or creates them
|
||||
func (creds *Creds) Load(filename string) error {
|
||||
indata, err := os.ReadFile(getConfig(filename))
|
||||
indata, err := os.ReadFile(GetConfigPath(filename))
|
||||
if err != nil {
|
||||
creds.Init(filename)
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user