Go client for KeePassHTTP to interact with KeePass's credentials.
$ go get -u github.com/cyrbil/go_keepasshttp/keepasshttp
package main
import (
"fmt"
"github.com/cyrbil/go_keepasshttp/keepasshttp"
)
func main() {
kph := keepasshttp.New()
...
credential, err := kph.Get(&keepasshttp.Filter{Url: "my_credential_name_or_url"})
if err != nil { panic(err) }
fmt.Printf("Login: %#v - Password: %#v", credential.Login, credential.Password)
credentials, err := kph.List()
if err != nil { panic(err) }
for _, credential = range credentials {
fmt.Printf("Login: %#v", credential.Login)
}
credentials, err = kph.Search(&keepasshttp.Filter{
SubmitUrl: "github.com", // Filter has other useful fields
})
if err != nil { panic(err) }
for _, credential := range credentials {
fmt.Printf("Login: %#v - Password: %#v", credential.Login, credential.Password)
}
err = kph.Create(&keepasshttp.Credential{
Login: "hello",
Password: "world",
Url: "github.com",
})
if err != nil { panic(err) }
credential.Password = "new password"
err = credential.Commit()
if err != nil { panic(err) }
// or
err = kph.Update(&keepasshttp.Credential{
Uuid: credential.Uuid,
Login: "hello",
Password: "world",
Url: "github.com",
})
if err != nil { panic(err) }
By default, this module will write AES association key to ~/.go_keepass_http
and use http://localhost:19455/
to connect to the KeePassHTTP server.
To change theses parameters, instantiate keepasshttp.KeePassHTTP
with different values.
kph := keepasshttp.New()
kph.Storage = "file.bin"
kph.Url = "http://remote/keepasshttp/server"
You can simply run the tests using:
$ cd keepasshttp
$ go test
KeePassHTTP
calls are mocked, to run the tests against a real server, you need to:
- open
tests/test_database.kdbx
inKeePass
password istest
- set
TEST_WITH_KEEPASS
environment variable - run test normally
KeePassHTTP
will ask to store new key (enterunittest
as name and pressyes
to overwrite) and yield various messages, this is all normal
To run tests with coverage:
$ go get golang.org/x/tools/cmd/cover
$ go test -cover