11package config
22
33import (
4- "reflect"
5- "time"
6-
74 "github.com/ethersphere/beekeeper/pkg/orchestration"
85)
96
107type Inheritable interface {
118 GetParentName () string
129}
1310
14- // BeeConfig represents Bee configuration
11+ // BeeConfig represents Bee configuration as read from Beekeeper's YAML config.
12+ //
13+ // It embeds orchestration.Config (the Bee flag set), so the flag fields are
14+ // defined in exactly one place and the same yaml tags — the Bee flag names —
15+ // are used both for reading the config here and for rendering the node's
16+ // .bee.yaml. The only thing BeeConfig adds is the config-file-only concern of
17+ // inheritance (_inherit). Export returns just the embedded Config, so neither
18+ // _inherit nor any other config-loading detail can leak into the rendered file.
1519type BeeConfig struct {
16- // parent to inherit settings from
17- * Inherit `yaml:",inline"`
18- // Bee configuration
19- AllowPrivateCIDRs * bool `yaml:"allow-private-cidrs"`
20- APIAddr * string `yaml:"api-addr"`
21- AutoTLSCAEndpoint * string `yaml:"autotls-ca-endpoint"`
22- AutoTLSDomain * string `yaml:"autotls-domain"`
23- AutoTLSRegistrationEndpoint * string `yaml:"autotls-registration-endpoint"`
24- BlockchainRPCEndpoint * string `yaml:"blockchain-rpc-endpoint"`
25- BlockTime * uint64 `yaml:"block-time"`
26- BootnodeMode * bool `yaml:"bootnode-mode"`
27- Bootnodes * string `yaml:"bootnodes"`
28- CacheCapacity * uint64 `yaml:"cache-capacity"`
29- ChequebookEnable * bool `yaml:"chequebook-enable"`
30- CORSAllowedOrigins * string `yaml:"cors-allowed-origins"`
31- DataDir * string `yaml:"data-dir"`
32- DbBlockCacheCapacity * int `yaml:"db-block-cache-capacity"`
33- DbDisableSeeksCompaction * bool `yaml:"db-disable-seeks-compaction"`
34- DbOpenFilesLimit * int `yaml:"db-open-files-limit"`
35- DbWriteBufferSize * int `yaml:"db-write-buffer-size"`
36- FullNode * bool `yaml:"full-node"`
37- Mainnet * bool `yaml:"mainnet"`
38- NATAddr * string `yaml:"nat-addr"`
39- NATWSSAddr * string `yaml:"nat-wss-addr"`
40- NetworkID * uint64 `yaml:"network-id"`
41- P2PAddr * string `yaml:"p2p-addr"`
42- P2PWSEnable * bool `yaml:"p2p-ws-enable"`
43- P2PWSSAddr * string `yaml:"p2p-wss-addr"`
44- P2PWSSEnable * bool `yaml:"p2p-wss-enable"`
45- Password * string `yaml:"password"`
46- PaymentEarly * uint64 `yaml:"payment-early-percent"`
47- PaymentThreshold * uint64 `yaml:"payment-threshold"`
48- PaymentTolerance * uint64 `yaml:"payment-tolerance-percent"`
49- PostageContractStartBlock * uint64 `yaml:"postage-stamp-start-block"`
50- PostageStampAddress * string `yaml:"postage-stamp-address"`
51- PriceOracleAddress * string `yaml:"price-oracle-address"`
52- RedistributionAddress * string `yaml:"redistribution-address"`
53- ResolverOptions * string `yaml:"resolver-options"`
54- StakingAddress * string `yaml:"staking-address"`
55- StorageIncentivesEnable * string `yaml:"storage-incentives-enable"`
56- SwapEnable * bool `yaml:"swap-enable"`
57- SwapEndpoint * string `yaml:"swap-endpoint"` // deprecated: use blockchain-rpc-endpoint
58- SwapFactoryAddress * string `yaml:"swap-factory-address"`
59- SwapInitialDeposit * uint64 `yaml:"swap-initial-deposit"`
60- TracingEnabled * bool `yaml:"tracing-enabled"`
61- TracingEndpoint * string `yaml:"tracing-endpoint"`
62- TracingServiceName * string `yaml:"tracing-service-name"`
63- Verbosity * uint64 `yaml:"verbosity"`
64- WarmupTime * time.Duration `yaml:"warmup-time"`
65- WelcomeMessage * string `yaml:"welcome-message"`
66- WithdrawAddress * string `yaml:"withdrawal-addresses-whitelist"`
20+ * Inherit `yaml:",inline"`
21+ orchestration.Config `yaml:",inline"`
6722}
6823
6924func (b BeeConfig ) GetParentName () string {
@@ -73,30 +28,9 @@ func (b BeeConfig) GetParentName() string {
7328 return ""
7429}
7530
76- // Export exports BeeConfig to orchestration.Config
77- func (b * BeeConfig ) Export () (config orchestration.Config ) {
78- localVal := reflect .ValueOf (b ).Elem ()
79- localType := reflect .TypeFor [BeeConfig ]()
80- remoteVal := reflect .ValueOf (& config ).Elem ()
81-
82- for i := range localVal .NumField () {
83- localField := localVal .Field (i )
84- if localField .IsValid () && ! localField .IsNil () {
85- localFieldVal := localVal .Field (i ).Elem ()
86- localFieldName := localType .Field (i ).Name
87-
88- remoteFieldVal := remoteVal .FieldByName (localFieldName )
89- if remoteFieldVal .IsValid () && remoteFieldVal .Type () == localFieldVal .Type () {
90- remoteFieldVal .Set (localFieldVal )
91- }
92- }
93- }
94-
95- config = remoteVal .Interface ().(orchestration.Config )
96-
97- if config .BlockchainRPCEndpoint == "" && b .SwapEndpoint != nil {
98- config .BlockchainRPCEndpoint = * b .SwapEndpoint
99- }
100-
101- return config
31+ // Export returns the Bee flag configuration to be rendered into the node's
32+ // .bee.yaml. Inheritance has already been resolved during config loading and is
33+ // not part of the embedded Config.
34+ func (b * BeeConfig ) Export () orchestration.Config {
35+ return b .Config
10236}
0 commit comments