macaroons: add macaroons package and update glide

This commit is contained in:
Alex authored and Olaoluwa Osuntokun committed 2017-08-17 19:20:41 -07:00
1 parent 5ef077e5c8
commit 662731e719
5 files changed
+282 -2

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
package macaroons
import (
"path"
"gopkg.in/macaroon-bakery.v1/bakery"
"github.com/boltdb/bolt"
)
var (
// dbFileName is the filename within the data directory which contains
// the macaroon stores.
dbFilename = "macaroons.db"
)
// NewService returns a service backed by the macaroon Bolt DB stored in the
// passed directory.
func NewService(dir string) (*bakery.Service, error) {
// Open the database.
macaroonDB, err := bolt.Open(path.Join(dir, dbFilename), 0600,
bolt.DefaultOptions)
if err != nil {
return nil, err
}
rootKeyStore, err := NewRootKeyStorage(macaroonDB)
if err != nil {
return nil, err
}
macaroonStore, err := NewStorage(macaroonDB)
if err != nil {
return nil, err
}
macaroonParams := bakery.NewServiceParams{
Location: "lnd",
Store: macaroonStore,
RootKeyStore: rootKeyStore,
// No third-party caveat support for now.
// TODO(aakselrod): Add third-party caveat support.
Locator: nil,
Key: nil,
}
return bakery.NewService(macaroonParams)
}