|
| 1 | +package rules |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/lightninglabs/lightning-terminal/firewalldb" |
| 5 | + "github.com/lightninglabs/lndclient" |
| 6 | + "gopkg.in/macaroon-bakery.v2/bakery" |
| 7 | +) |
| 8 | + |
| 9 | +// Config encompasses all the possible configuration items that could be |
| 10 | +// required by the various rules. |
| 11 | +type Config interface { |
| 12 | + // GetStores can be used to get access to methods that can be used to |
| 13 | + // perform atomic transactions on permanent and temporary local and |
| 14 | + // global kv stores. |
| 15 | + GetStores() firewalldb.KVStores |
| 16 | + |
| 17 | + // GetActionsDB can be used by rules to list any past actions that were |
| 18 | + // made for the specific session or feature. |
| 19 | + GetActionsDB() firewalldb.ActionsDB |
| 20 | + |
| 21 | + // GetMethodPerms returns a map that contains URIs and the permissions |
| 22 | + // required to use them. |
| 23 | + GetMethodPerms() func(string) ([]bakery.Op, bool) |
| 24 | + |
| 25 | + // GetNodePubKey returns the node ID of the lnd node. |
| 26 | + GetNodePubKey() [33]byte |
| 27 | + |
| 28 | + // GetRouterClient returns an lnd router client. |
| 29 | + GetRouterClient() lndclient.RouterClient |
| 30 | + |
| 31 | + // GetReqID is the request ID of the call being evaluated. This can be |
| 32 | + // used to link a request with a response. |
| 33 | + GetReqID() int64 |
| 34 | + |
| 35 | + // GetLndClient returns an lnd client. |
| 36 | + GetLndClient() lndclient.LightningClient |
| 37 | +} |
| 38 | + |
| 39 | +// ConfigImpl is an implementation of the Config interface. |
| 40 | +type ConfigImpl struct { |
| 41 | + // GetStores provides access to methods that can be used to perform |
| 42 | + // atomic transactions on permanent and temporary local and global |
| 43 | + // kv stores. |
| 44 | + Stores firewalldb.KVStores |
| 45 | + |
| 46 | + // ActionsDB can be used by rules to list any past actions that were |
| 47 | + // made for the specific session or feature. |
| 48 | + ActionsDB firewalldb.ActionsDB |
| 49 | + |
| 50 | + // MethodPerms is a function that can be used to fetch the permissions |
| 51 | + // required for a URI. |
| 52 | + MethodPerms func(string) ([]bakery.Op, bool) |
| 53 | + |
| 54 | + // NodeID is the pub key of the lnd node. |
| 55 | + NodeID [33]byte |
| 56 | + |
| 57 | + // RouterClient is an lnd router client. |
| 58 | + RouterClient lndclient.RouterClient |
| 59 | + |
| 60 | + // ReqID is the request ID of the call being evaluated. This can be used |
| 61 | + // to link a request with a response. |
| 62 | + ReqID int64 |
| 63 | + |
| 64 | + // LndClient is a connection to the Lit node's LND node. |
| 65 | + LndClient lndclient.LightningClient |
| 66 | +} |
| 67 | + |
| 68 | +func (c *ConfigImpl) GetStores() firewalldb.KVStores { |
| 69 | + return c.Stores |
| 70 | +} |
| 71 | + |
| 72 | +// GetActionsDB returns the list of past actions. |
| 73 | +func (c *ConfigImpl) GetActionsDB() firewalldb.ActionsDB { |
| 74 | + return c.ActionsDB |
| 75 | +} |
| 76 | + |
| 77 | +// GetMethodPerms returns a function that can be used to fetch the permissions |
| 78 | +// of a URI. |
| 79 | +func (c *ConfigImpl) GetMethodPerms() func(string) ([]bakery.Op, bool) { |
| 80 | + return c.MethodPerms |
| 81 | +} |
| 82 | + |
| 83 | +// GetNodePubKey returns the node ID for the lnd node. |
| 84 | +func (c *ConfigImpl) GetNodePubKey() [33]byte { |
| 85 | + return c.NodeID |
| 86 | +} |
| 87 | + |
| 88 | +// GetRouterClient returns an lnd router client. |
| 89 | +func (c *ConfigImpl) GetRouterClient() lndclient.RouterClient { |
| 90 | + return c.RouterClient |
| 91 | +} |
| 92 | + |
| 93 | +// GetReqID returns the request ID of the request or response being evaluated. |
| 94 | +func (c *ConfigImpl) GetReqID() int64 { |
| 95 | + return c.ReqID |
| 96 | +} |
| 97 | + |
| 98 | +// GetLndClient returns an lnd client. |
| 99 | +func (c *ConfigImpl) GetLndClient() lndclient.LightningClient { |
| 100 | + return c.LndClient |
| 101 | +} |
| 102 | + |
| 103 | +// A compile-time check to ensure that ConfigImpl implements the Config |
| 104 | +// interface. |
| 105 | +var _ Config = (*ConfigImpl)(nil) |
0 commit comments