Skip to content

Commit 4d22dfb

Browse files
committed
multi: refactor to not use session.MacaroonRecipe outside the package
In this commit, we refactor various uses of the session.MacaroonRecipe type outside of the session package. This is to decouple the baking of a super macaroon from the sessions package and will help avoid import cycles in future.
1 parent 832fbad commit 4d22dfb

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

accounts/rpcserver.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,10 @@ func (s *RPCServer) CreateAccount(ctx context.Context,
8787
fmt.Sprintf("%s %x", CondAccount, account.ID[:]),
8888
)
8989

90-
macHex, err := s.superMacBaker(ctx, macRootKey, &session.MacaroonRecipe{
91-
Permissions: MacaroonPermissions,
92-
Caveats: []macaroon.Caveat{{
93-
Id: []byte(accountCaveat),
94-
}},
95-
})
90+
macHex, err := s.superMacBaker(
91+
ctx, macRootKey, MacaroonPermissions,
92+
[]macaroon.Caveat{{Id: []byte(accountCaveat)}},
93+
)
9694
if err != nil {
9795
return nil, fmt.Errorf("error baking account macaroon: %w", err)
9896
}

session/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type Session struct {
7474

7575
// MacaroonBaker is a function type for baking a super macaroon.
7676
type MacaroonBaker func(ctx context.Context, rootKeyID uint64,
77-
recipe *MacaroonRecipe) (string, error)
77+
perms []bakery.Op, caveats []macaroon.Caveat) (string, error)
7878

7979
// NewSession creates a new session with the given user-defined parameters.
8080
func NewSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,

session_rpcserver.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
424424
})
425425

426426
mac, err := s.cfg.superMacBaker(
427-
ctx, sess.MacaroonRootKey,
428-
&session.MacaroonRecipe{
429-
Permissions: permissions,
430-
Caveats: caveats,
431-
},
427+
ctx, sess.MacaroonRootKey, permissions, caveats,
432428
)
433429
if err != nil {
434430
log.Debugf("Not resuming session %x. Could not bake "+

terminal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import (
6969
"google.golang.org/grpc/test/bufconn"
7070
"google.golang.org/protobuf/encoding/protojson"
7171
"gopkg.in/macaroon-bakery.v2/bakery"
72+
"gopkg.in/macaroon.v2"
7273
)
7374

7475
const (
@@ -430,11 +431,10 @@ func (g *LightningTerminal) start(ctx context.Context) error {
430431
}
431432

432433
superMacBaker := func(ctx context.Context, rootKeyID uint64,
433-
recipe *session.MacaroonRecipe) (string, error) {
434+
perms []bakery.Op, caveats []macaroon.Caveat) (string, error) {
434435

435436
return litmac.BakeSuperMacaroon(
436-
ctx, g.basicClient, rootKeyID,
437-
recipe.Permissions, recipe.Caveats,
437+
ctx, g.basicClient, rootKeyID, perms, caveats,
438438
)
439439
}
440440

0 commit comments

Comments
 (0)