-
Notifications
You must be signed in to change notification settings - Fork 28
/
config.js
242 lines (177 loc) · 10.3 KB
/
config.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
const fs = require('fs-extra');
const _ = require('lodash');
const log4jsConfigured = require('./util/log/log4js-configured');
const logger = log4jsConfigured.getLogger('config.js');
let cryptoConfigPath = fs.realpathSync(process.env.CRYPTO_CONFIG_DIR || '../fabric-starter/crypto-config');
logger.info(`Crypto-config path: ${cryptoConfigPath}`);
const TEMPLATES_DIR = process.env.TEMPLATES_DIR || '/etc/hyperledger/templates';
const YAMLS_DIR = process.env.YAMLS_DIR || `${TEMPLATES_DIR}/..`;
const ENROLL_ID = process.env.ENROLL_ID || 'admin';
const TMP_DIR = process.env.TMP_DIR || cryptoConfigPath;
const ordererNamePrefix = process.env.ORDERER_NAME_PREFIX || 'raft';
const ordererBatchTimeout = process.env.ORDERER_BATCH_TIMEOUT || '2';
const systemChannelId = process.env.SYSTEM_CHANNEL_ID || "orderer-system-channel";
const PEER_CONFIG_FILE = process.env.PEER_CONFIG_FILE || `${TMP_DIR}/node-config${process.env.DEBUG_INSTANCE ? '-' + process.env.DEBUG_INSTANCE : ''}.json`
logger.info(`PEER_CONFIG_FILE: ${PEER_CONFIG_FILE}`);
const persistedConfig = fs.readJsonSync(PEER_CONFIG_FILE, {throws: false}) || {}
const PEER_ADDRESS_PREFIX_TEMPLATE = process.env.PEER_ADDRESS_PREFIX_TEMPLATE || "${PEER_NAME}."
//@deprecated
const PEER_ADDRESS_TEMPLATE = process.env.PEER_ADDRESS_TEMPLATE; // || "${PEER_NAME}.${ORG}.${DOMAIN}" //TODO: deprecated, use PEER_ADDRESS_PREFIX_TEMPLATE
module.exports = {
log4js: log4jsConfigured, //TODO: remove from config, use directly
systemChannelId: systemChannelId,
ENROLL_ID: ENROLL_ID,
CRYPTO_CONFIG_DIR: cryptoConfigPath,
TMP_DIR: TMP_DIR,
TEMPLATES_DIR: TEMPLATES_DIR,
YAMLS_DIR: YAMLS_DIR,
FABRIC_STARTER_HOME: process.env.FABRIC_STARTER_HOME || process.env.FABRIC_STARTER_PWD || './',
FABRIC_VERSION: process.env.FABRIC_VERSION,
FABRIC_STARTER_VERSION: process.env.FABRIC_STARTER_VERSION,
DEFAULT_CONSORTIUM: process.env.DEFAULT_CONSORTIUM || 'SampleConsortium',
BOOTSTRAP_SERVICE_URL: process.env.BOOTSTRAP_SERVICE_URL || 'https',
BOOTSTRAP_EXTERNAL_PORT: process.env.BOOTSTRAP_EXTERNAL_PORT || '443',
API_PORT: process.env.API_PORT || '4000',
USE_SERVICE_DISCOVERY: typeof process.env.USE_SERVICE_DISCOVERY === "undefined" || process.env.USE_SERVICE_DISCOVERY === "true",
WEBADMIN_DIR: process.env.WEBADMIN_DIR || "./admin",
WEBAPPS_DIR: process.env.WEBAPPS_DIR || "webapps",
MIDDLWARE_DIR: process.env.MIDDLWARE_DIR || "./routes",
APPSTORE_DIR: process.env.APPSTORE_DIR || "./appstore",
UI_LISTEN_BLOCK_OPTS: process.env.UI_LISTEN_BLOCK_OPTS === "true" || process.env.UI_LISTEN_BLOCK_OPTS,
DNS_CHANNEL: process.env.DNS_CHANNEL || "common",
DNS_CHAINCODE: process.env.DNS_CHAINCODE || "dns",
DNS_UPDATE_TIMEOUT: process.env.DNS_UPDATE_TIMEOUT || 4000,
CHANNEL_LISTENER_UPDATE_TIMEOUT: process.env.CHANNEL_LISTENER_UPDATE_TIMEOUT || 10000,
CHAINCODE_PROCESSING_TIMEOUT: process.env.CHAINCODE_PROCESSING_TIMEOUT || 120000,
INVOKE_RETRY_COUNT: process.env.INVOKE_RETRY_COUNT || 1,
JOIN_RETRY_COUNT: process.env.JOIN_RETRY_COUNT || 10,
LISTENER_RETRY_COUNT: process.env.LISTENER_RETRY_COUNT || 20,
ORDERER_NAME_PREFIX: ordererNamePrefix,
ORDERER_BATCH_TIMEOUT: ordererBatchTimeout,
DEFAULT_PEER0PORT: '7051',
HARDCODED_ORDERER_NAME: process.env.HARDCODED_ORDERER_NAME || 'orderer',
get SDK_API_URL() { return process.env.SDK_API_URL || `http://sdk.${this.org}.${this.domain}:8080`},
get org() {return persistedConfig.ORG || process.env.ORG || ''},
setOrg(val) {
persistedConfig.ORG = val
persistConfig()
},
get domain() {return persistedConfig.DOMAIN || process.env.DOMAIN || 'example.com'},
setDomain(val) {
persistedConfig.DOMAIN = val
persistConfig()
},
get internalDomain() {return persistedConfig.INTERNAL_DOMAIN || process.env.INTERNAL_DOMAIN },
get peerName() {return persistedConfig.PEER_NAME || process.env.PEER_NAME || 'peer0'},
setPeerName(val) {
persistedConfig.PEER_NAME = val
persistConfig()
},
get myIp() {return persistedConfig.MY_IP || process.env.MY_IP},
setMyIp(val) {
persistedConfig.MY_IP = val
persistConfig()
},
get masterIp() {return persistedConfig.MASTER_IP || process.env.MASTER_IP || this.myIp},
setMasterIp(val) {
persistedConfig.MASTER_IP = val
persistConfig()
},
get bootstrapIp() {return persistedConfig.BOOTSTRAP_IP || process.env.BOOTSTRAP_IP},
setBootstrapIp(val) {
persistedConfig.BOOTSTRAP_IP = val
persistConfig()
},
get peer0Port() {return persistedConfig.PEER0_PORT || process.env.PEER0_PORT || this.DEFAULT_PEER0PORT},
setPeer0Port(val) {
persistedConfig.PEER0_PORT = val
persistConfig()
},
get ordererName() {return persistedConfig.ORDERER_NAME || process.env.ORDERER_NAME || 'orderer';},
setOrdererName(val) {
persistedConfig.ORDERER_NAME = val
persistConfig()
},
get ordererDomain() {return persistedConfig.ORDERER_DOMAIN || process.env.ORDERER_DOMAIN || this.domain;},
setOrdererDomain(val) {
persistedConfig.ORDERER_DOMAIN = val
persistConfig()
},
get ordererMspId() {return persistedConfig.ORDERER_MSPID || `${this.ordererName}.${this.ordererDomain}`},
setOrdererMspId(val) {
persistedConfig.ORDERER_MSPID = val
persistConfig()
},
get ordererPort() {return persistedConfig.ORDERER_PORT || process.env.ORDERER_GENERAL_LISTENPORT || '7050'},
setOrdererPort(val) {
persistedConfig.ORDERER_PORT = val
persistConfig()
},
get ORDERER_ADDR() {return persistedConfig.ORDERER_ADDR || `${this.ordererName}.${this.internalDomain || this.ordererDomain}:${this.ordererPort}`},
setOrdererAddr(val) {
persistedConfig.ORDERER_ADDR = val
persistConfig()
},
get ordererWwwPort() {return persistedConfig.ORDERER_WWW_PORT || process.env.ORDERER_WWW_PORT || 79},
setOrdererWwwPort(val) {
persistedConfig.ORDERER_WWW_PORT = val
persistConfig()
},
get enrollSecret() {return persistedConfig.ENROLL_SECRET || process.env.ENROLL_SECRET || 'adminpw';},
setEnrollSecret(val) {
persistedConfig.ENROLL_SECRET = val
persistConfig()
},
get masterCAPort() {return persistedConfig.MASTER_CA_PORT || process.env.MASTER_CA_PORT || '7054'},
setMasterCAPort(val) {
persistedConfig.MASTER_CA_PORT = val
persistConfig()
},
get masterTLSCAPort() {return persistedConfig.MASTER_TLSCA_PORT || process.env.MASTER_TLSCA_PORT || '7055'},
setMasterTLSCAPort(val) {
persistedConfig.MASTER_TLSCA_PORT = val
persistConfig()
},
get ordererCryptoDir() {return `${cryptoConfigPath}/ordererOrganizations/${this.ordererDomain}` },
get ORDERER_TLS_CERT() {return `${this.ordererCryptoDir}/msp/tlscacerts/tlsca.${this.ordererDomain}-cert.pem` },
get PEER_ADDRESS_PREFIX_TEMPLATE() {return PEER_ADDRESS_PREFIX_TEMPLATE},
peerAddressPrefix(peer) {
return _.replace(this.PEER_ADDRESS_PREFIX_TEMPLATE, '${PEER_NAME}', peer)
},
addressFromTemplate: (peer, org, domain) =>{
const template = PEER_ADDRESS_TEMPLATE ? PEER_ADDRESS_TEMPLATE : `${PEER_ADDRESS_PREFIX_TEMPLATE}\${ORG}.\${DOMAIN}`
let result = _.replace(template, '${PEER_NAME}', peer);
result = _.replace(result , '${ORG}', org);
result = _.replace(result , '${DOMAIN}', domain);
return result
},
// default to peer0.org1.example.com:7051 inside docker-compose or export ORGS='{"org1":"peer0.org1.example.com:7051","org2":"peer0.org2.example.com:7051"}'
// get orgs() {return process.env.ORGS || `"${this.org}":"${this.peerName}.${this.org}.${this.domain}:${this.peer0Port}"`},
get cas() {return process.env.CAS || `"${this.org}":"ca.${this.org}.${this.domain}:${this.masterCAPort}"`},
get tlsCas() {return process.env.TLS_CAS || `"${this.org}":"tlsca.${this.org}.${this.domain}:${this.masterTLSCAPort}"`},
get orgs() {return process.env.ORGS || `"${this.org}":"${this.addressFromTemplate(this.peerName, this.org, this.internalDomain || this.domain)}:${this.peer0Port}"`},
// get cas() {return process.env.CAS || `"${this.org}":"${this.corePeerAddress('ca', this.org, this.domain)}:${this.masterCAPort}"`},
// get tlsCas() {return process.env.TLS_CAS || `"${this.org}":"${this.corePeerAddress('tlsca', this.org, this.domain)}:${this.masterTLSCAPort}"`},
get PEEER_ORG_NAME() {return persistedConfig.PEEER_ORG_NAME || process.env.PEEER_ORG_NAME || `${this.peerName}.${this.org}`},
get ORG_CRYPTO_DIR() {return `${cryptoConfigPath}/peerOrganizations/${this.org}.${this.domain}`},
get CORE_PEER_LOCALMSPID() {return this.org},
get CORE_PEER_MSPCONFIGPATH() {return `${cryptoConfigPath}/peerOrganizations/${this.org}.${this.domain}/users/Admin@${this.org}.${this.domain}/msp`},
get certificationDomain() { return `${this.org}.${this.domain}`},
get RAFT0_CONSENTER_PORT(){return process.env.RAFT0_CONSENTER_PORT || this.ordererPort},
RAFT1_CONSENTER_PORT: process.env.RAFT1_CONSENTER_PORT || '7150',
RAFT2_CONSENTER_PORT: process.env.RAFT2_CONSENTER_PORT || '7250',
ACCEPT_ALL_ORGS: process.env.ACCEPT_ALL_ORGS !== 'false',
CUSTOM_APP_PORTS: process.env.CUSTOM_APP_PORTS || '8081-8089',
AUTH_MODE: process.env.AUTH_MODE || (process.env.CRYPTO_ALGORITHM === 'GOST' ? 'ADMIN' : 'CA'),
SIGNATURE_HASH_FAMILY: process.env.SIGNATURE_HASH_FAMILY || (process.env.CRYPTO_ALGORITHM === 'GOST' ? 'SM3' : 'SHA2'),
CRYPTO_SUIT_CONFIG: process.env.CRYPTO_ALGORITHM === 'GOST' ? require('./gost-deps/crypto-suit-config') : {},
AUTH_JWT_EXPIRES_IN: (/^\d+$/.test(process.env.AUTH_JWT_EXPIRES_IN) ? parseInt(process.env.AUTH_JWT_EXPIRES_IN) : process.env.AUTH_JWT_EXPIRES_IN) || '8h',
DOCKER_COMPOSE_EXTRA_ARGS: process.env.DOCKER_COMPOSE_EXTRA_ARGS || '',
PRIVATE_KEYS_FILTER : '.*\/keystore.*|.*\/sk.pem|.*/\*.key|.*\/priv_sk',
SKIP_CHECK_PORTS_TIMEOUT_SECONDS: process.env.SKIP_CHECK_PORTS_TIMEOUT_SECONDS ? process.env.SKIP_CHECK_PORTS_TIMEOUT_SECONDS * 1000 : '',
DISABLE_TX_ID_LISTENER: process.env.DISABLE_TX_ID_LISTENER === "true" || process.env.DISABLE_TX_ID_LISTENER,
REQUEST_LIMIT: process.env.REQUEST_LIMIT || -1
};
function persistConfig() {
fs.outputJsonSync(PEER_CONFIG_FILE, persistedConfig)
}