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.
This commit is contained in:
Elle Mouton 2025-02-09 10:45:10 +02:00
parent 832fbad1c5
commit 4d22dfb7e9
No known key found for this signature in database
GPG key ID: D7D916376026F177
4 changed files with 9 additions and 15 deletions

View file

@ -87,12 +87,10 @@ func (s *RPCServer) CreateAccount(ctx context.Context,
fmt.Sprintf("%s %x", CondAccount, account.ID[:]),
)
macHex, err := s.superMacBaker(ctx, macRootKey, &session.MacaroonRecipe{
Permissions: MacaroonPermissions,
Caveats: []macaroon.Caveat{{
Id: []byte(accountCaveat),
}},
})
macHex, err := s.superMacBaker(
ctx, macRootKey, MacaroonPermissions,
[]macaroon.Caveat{{Id: []byte(accountCaveat)}},
)
if err != nil {
return nil, fmt.Errorf("error baking account macaroon: %w", err)
}

View file

@ -74,7 +74,7 @@ type Session struct {
// MacaroonBaker is a function type for baking a super macaroon.
type MacaroonBaker func(ctx context.Context, rootKeyID uint64,
recipe *MacaroonRecipe) (string, error)
perms []bakery.Op, caveats []macaroon.Caveat) (string, error)
// NewSession creates a new session with the given user-defined parameters.
func NewSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,

View file

@ -424,11 +424,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
})
mac, err := s.cfg.superMacBaker(
ctx, sess.MacaroonRootKey,
&session.MacaroonRecipe{
Permissions: permissions,
Caveats: caveats,
},
ctx, sess.MacaroonRootKey, permissions, caveats,
)
if err != nil {
log.Debugf("Not resuming session %x. Could not bake "+

View file

@ -69,6 +69,7 @@ import (
"google.golang.org/grpc/test/bufconn"
"google.golang.org/protobuf/encoding/protojson"
"gopkg.in/macaroon-bakery.v2/bakery"
"gopkg.in/macaroon.v2"
)
const (
@ -430,11 +431,10 @@ func (g *LightningTerminal) start(ctx context.Context) error {
}
superMacBaker := func(ctx context.Context, rootKeyID uint64,
recipe *session.MacaroonRecipe) (string, error) {
perms []bakery.Op, caveats []macaroon.Caveat) (string, error) {
return litmac.BakeSuperMacaroon(
ctx, g.basicClient, rootKeyID,
recipe.Permissions, recipe.Caveats,
ctx, g.basicClient, rootKeyID, perms, caveats,
)
}