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