Innitial Commit
+added Base Project Version 0.0.1
This commit is contained in:
45
internal/secret/keyring.go
Normal file
45
internal/secret/keyring.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/99designs/keyring"
|
||||
)
|
||||
|
||||
const serviceName = "pdev-ssh"
|
||||
|
||||
func OpenKeyring() (keyring.Keyring, error) {
|
||||
return keyring.Open(keyring.Config{
|
||||
ServiceName: serviceName,
|
||||
})
|
||||
}
|
||||
|
||||
func GetPassword(id string) (string, error) {
|
||||
kr, err := OpenKeyring()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
item, err := kr.Get(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(item.Data), nil
|
||||
}
|
||||
|
||||
func SavePassword(id string, password string) error {
|
||||
if id == "" {
|
||||
return fmt.Errorf("password_id fehlt")
|
||||
}
|
||||
|
||||
kr, err := OpenKeyring()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return kr.Set(keyring.Item{
|
||||
Key: id,
|
||||
Data: []byte(password),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user