Skip to content

Commit 26d028f

Browse files
committed
firewall+firewalldb: extract Account ID and pass to AddActionReq
In this commit we add an optional AccountID to the RequestInfo type. Then, we populate it if the caveat of the macaroon being used contains an accounts caveat. We also add an unused AccountID type to the AddActionReq and pass in the value from the RequestLogger.
1 parent 8527969 commit 26d028f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

firewall/request_info.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/lightninglabs/lightning-terminal/accounts"
78
"github.com/lightninglabs/lightning-terminal/session"
89
"github.com/lightningnetwork/lnd/fn"
910
"github.com/lightningnetwork/lnd/lnrpc"
@@ -29,6 +30,7 @@ const (
2930
// request.
3031
type RequestInfo struct {
3132
SessionID fn.Option[session.ID]
33+
AccountID fn.Option[accounts.AccountID]
3234
MsgID uint64
3335
RequestID uint64
3436
MWRequestType string
@@ -140,6 +142,12 @@ func NewInfoFromRequest(req *lnrpc.RPCMiddlewareRequest) (*RequestInfo, error) {
140142
}
141143
}
142144

145+
ri.AccountID, err = accounts.IDFromCaveats(ri.Macaroon.Caveats())
146+
if err != nil {
147+
return nil, fmt.Errorf("error extracting account ID "+
148+
"from macaroon: %v", err)
149+
}
150+
143151
return ri, nil
144152
}
145153

firewall/request_logger.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func (r *RequestLogger) addNewAction(ctx context.Context, ri *RequestInfo,
195195

196196
actionReq := &firewalldb.AddActionReq{
197197
SessionID: ri.SessionID,
198+
AccountID: ri.AccountID,
198199
MacaroonIdentifier: macaroonID,
199200
RPCMethod: ri.URI,
200201
}

firewalldb/actions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"time"
66

7+
"github.com/lightninglabs/lightning-terminal/accounts"
78
"github.com/lightninglabs/lightning-terminal/session"
89
"github.com/lightningnetwork/lnd/fn"
910
)
@@ -45,6 +46,13 @@ type AddActionReq struct {
4546
// guaranteed to be linked to an existing session.
4647
SessionID fn.Option[session.ID]
4748

49+
// AccountID holds the optional account ID of the account that this
50+
// action was performed on.
51+
//
52+
// NOTE: for our BoltDB impl, this is not persisted in any way, and we
53+
// do not populate it on reading from disk.
54+
AccountID fn.Option[accounts.AccountID]
55+
4856
// ActorName is the name of the entity who performed the Action.
4957
ActorName string
5058

0 commit comments

Comments
 (0)