@abtnode/core 1.7.2 → 1.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,9 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
29
29
  newConfigs.forEach((x) => {
30
30
  if (x.secure) {
31
31
  x.value = security.encrypt(x.value, did, dek);
32
+ if (x.default) {
33
+ x.default = security.encrypt(x.default, did, dek);
34
+ }
32
35
  }
33
36
  });
34
37
  }
@@ -15,6 +15,8 @@ const { isValid: isValidDid } = require('@arcblock/did');
15
15
  const { verifyPresentation } = require('@arcblock/vc');
16
16
  const { toBase58, isHex } = require('@ocap/util');
17
17
  const { fromSecretKey } = require('@ocap/wallet');
18
+ const { toPng: createDidLogo } =
19
+ process.env.NODE_ENV !== 'test' ? require('@arcblock/did-motif') : require('@arcblock/did-motif/dist/did-motif.cjs');
18
20
 
19
21
  const logger = require('@abtnode/logger')('@abtnode/core:blocklet:manager');
20
22
  const downloadFile = require('@abtnode/util/lib/download-file');
@@ -2214,6 +2216,8 @@ class BlockletManager extends BaseBlockletManager {
2214
2216
  blocklet = await this.ensureBlocklet(did);
2215
2217
  logger.info('blocklet installed', { source, did: meta.did });
2216
2218
 
2219
+ await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.png'), createDidLogo(blocklet.meta.did));
2220
+
2217
2221
  this.emit(BlockletEvents.installed, { blocklet, context });
2218
2222
 
2219
2223
  states.notification.create({
@@ -2339,6 +2343,9 @@ class BlockletManager extends BaseBlockletManager {
2339
2343
  }
2340
2344
 
2341
2345
  blocklet = await this.ensureBlocklet(did, context);
2346
+
2347
+ await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.png'), createDidLogo(blocklet.meta.did));
2348
+
2342
2349
  this.refreshListCache();
2343
2350
 
2344
2351
  try {
package/lib/index.js CHANGED
@@ -247,7 +247,7 @@ function ABTNode(options) {
247
247
  updateNodeRouting,
248
248
  isInitialized,
249
249
  resetNode: (params, context) =>
250
- resetNode({ params, context, blockletManager, routerManager, takeRoutingSnapshot, teamManager }),
250
+ resetNode({ params, context, blockletManager, routerManager, takeRoutingSnapshot, teamManager, certManager }),
251
251
 
252
252
  // Team && Access control
253
253
 
@@ -3,7 +3,7 @@
3
3
  /* eslint-disable no-underscore-dangle */
4
4
 
5
5
  module.exports = async ({ states, printInfo }) => {
6
- printInfo('Try to update blocklet to 1.7.1...');
6
+ printInfo('Try to update blocklet server to 1.7.1...');
7
7
 
8
8
  const blockletExtras = await states.blockletExtras.find({});
9
9
  for (const extra of blockletExtras) {
@@ -13,6 +13,6 @@ module.exports = async ({ states, printInfo }) => {
13
13
 
14
14
  await states.blockletExtras.setSettings(extra.did, { initialized: true });
15
15
 
16
- printInfo(`Set initialized: ${extra}`);
16
+ printInfo(`Set initialized: ${extra.did}`);
17
17
  }
18
18
  };
@@ -7,6 +7,7 @@ const get = require('lodash/get');
7
7
  const cloneDeep = require('lodash/cloneDeep');
8
8
  const isEqual = require('lodash/isEqual');
9
9
  const joinUrl = require('url-join');
10
+ const { replaceSlotToIp } = require('@blocklet/meta/lib/util');
10
11
  const { getProvider } = require('@abtnode/router-provider');
11
12
  const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
12
13
  const getTmpDir = require('@abtnode/util/lib/get-tmp-directory');
@@ -79,7 +80,7 @@ const attachRuntimeDomainAliases = async ({ sites = [], context = {}, node }) =>
79
80
  return domain;
80
81
  }
81
82
  if (domain.value.includes(SLOT_FOR_IP_DNS_SITE) && ip) {
82
- domain.value = domain.value.replace(SLOT_FOR_IP_DNS_SITE, ip.replace(/\./g, '-'));
83
+ domain.value = replaceSlotToIp(domain.value, ip);
83
84
  }
84
85
  return domain;
85
86
  });
@@ -365,58 +365,6 @@ class RouterManager extends EventEmitter {
365
365
  return newSite;
366
366
  }
367
367
 
368
- // eslint-disable-next-line no-unused-vars
369
- async addCertificate(entity, context = {}) {
370
- entity.type = 'nginx';
371
- this.fixCertificate(entity);
372
-
373
- this.validateCertificate(entity);
374
-
375
- const info = Certificate.fromPEM(entity.certificate);
376
- const domain = get(info, 'subject.commonName', '');
377
-
378
- const cert = await states.certificate.find({ domain });
379
- const hasOne = cert && cert.length;
380
-
381
- if (hasOne) {
382
- throw new Error('certificate has exists!');
383
- }
384
-
385
- const newCert = await states.certificate.upsert({
386
- ...entity,
387
- domain,
388
- });
389
- logger.info('add certificate result', { domain: newCert.domain });
390
- this.emit('cert.added', { type: 'nginx', data: newCert });
391
- }
392
-
393
- // eslint-disable-next-line no-unused-vars
394
- async deleteCertificate({ id }, context = {}) {
395
- const tmpCert = await states.certificate.find({ _id: id });
396
- if (!tmpCert) {
397
- throw new Error('certificate does not exist');
398
- }
399
-
400
- const removeResult = await states.certificate.remove({ _id: id });
401
-
402
- logger.info('delete certificate', { removeResult, domain: tmpCert.domain });
403
- this.emit('cert.removed', { type: 'nginx', data: { domain: tmpCert.domain } });
404
- return {};
405
- }
406
-
407
- // eslint-disable-next-line no-unused-vars
408
- async updateNginxHttpsCert(entity, context = {}) {
409
- entity.type = 'nginx';
410
- this.fixCertificate(entity);
411
- this.validateCertificate(entity, entity.domain);
412
- const dbEntity = await states.certificate.upsert(entity);
413
- this.emit('cert.issued', { type: 'nginx', data: dbEntity });
414
- }
415
-
416
- findCertificateByDomain(domain) {
417
- return states.certificate.findOne({ domain });
418
- }
419
-
420
368
  // ============================================================================================
421
369
  // Internal API that are used by public APIs and called from CLI
422
370
  // ============================================================================================
@@ -546,10 +494,7 @@ class RouterManager extends EventEmitter {
546
494
  const info = await states.node.read();
547
495
  const httpsEnabled = get(info, 'routing.https', true);
548
496
 
549
- const selection = { domain: 1, privateKey: 1, certificate: 1 };
550
- const certificates = httpsEnabled
551
- ? await states.certificate.find({ type: get(info, 'routing.provider', null) }, selection)
552
- : [];
497
+ const certificates = httpsEnabled ? await this.certManager.getAllNormal() : [];
553
498
 
554
499
  let sites = await states.site.getSites();
555
500
  // mutate data by input
@@ -4,7 +4,6 @@ const ChallengeState = require('./challenge');
4
4
  const BlockletState = require('./blocklet');
5
5
  const NotificationState = require('./notification');
6
6
  const SiteState = require('./site');
7
- const HttpsCertState = require('./https-cert');
8
7
  const AccessKeyState = require('./access-key');
9
8
  const WebhookState = require('./webhook');
10
9
  const MigrationState = require('./migration');
@@ -18,7 +17,6 @@ const init = (dataDirs, options) => {
18
17
  const blockletState = new BlockletState(dataDirs.core, options);
19
18
  const challengeState = new ChallengeState(dataDirs.core, options);
20
19
  const siteState = new SiteState(dataDirs.core, options);
21
- const httpsCertState = new HttpsCertState(dataDirs.core, options);
22
20
  const accessKeyState = new AccessKeyState(dataDirs.core, options);
23
21
  const webhookState = new WebhookState(dataDirs.core, options);
24
22
  const migrationState = new MigrationState(dataDirs.core, options);
@@ -30,7 +28,6 @@ const init = (dataDirs, options) => {
30
28
  node: nodeState,
31
29
  blocklet: blockletState,
32
30
  notification: notificationState,
33
- certificate: httpsCertState,
34
31
  site: siteState,
35
32
  accessKey: accessKeyState,
36
33
  webhook: webhookState,
package/lib/util/index.js CHANGED
@@ -17,6 +17,7 @@ const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
17
17
  const parseBlockletMeta = require('@blocklet/meta/lib/parse');
18
18
  const { validateMeta, fixAndValidateService } = require('@blocklet/meta/lib/validate');
19
19
  const { BlockletStatus, BLOCKLET_INTERFACE_WELLKNOWN } = require('@blocklet/meta/lib/constants');
20
+ const { replaceSlotToIp } = require('@blocklet/meta/lib/util');
20
21
  const {
21
22
  StatusCode,
22
23
  DOMAIN_FOR_DEFAULT_SITE,
@@ -83,10 +84,10 @@ const getBlockletHost = ({ domain, context, nodeIp }) => {
83
84
  const ipRegex = /\d+[-.]\d+[-.]\d+[-.]\d+/;
84
85
  const match = ipRegex.exec(context.hostname);
85
86
  if (match) {
86
- const ip = match[0].replace(/\./g, '-');
87
- tmpDomain = tmpDomain.replace(SLOT_FOR_IP_DNS_SITE, ip);
87
+ const ip = match[0];
88
+ tmpDomain = replaceSlotToIp(tmpDomain, ip);
88
89
  } else if (nodeIp) {
89
- tmpDomain = tmpDomain.replace(SLOT_FOR_IP_DNS_SITE, nodeIp.replace(/\./g, '-'));
90
+ tmpDomain = replaceSlotToIp(tmpDomain, nodeIp);
90
91
  }
91
92
  }
92
93
 
@@ -52,14 +52,14 @@ const resetSites = async ({ context, routerManager, takeRoutingSnapshot }) => {
52
52
  };
53
53
 
54
54
  /* istanbul ignore next */
55
- const resetCertificates = async ({ context, routerManager }) => {
56
- const certs = await states.certificate.find();
55
+ const resetCertificates = async ({ certManager }) => {
56
+ const certs = await certManager.getAll();
57
57
  for (let i = 0; i < certs.length; i++) {
58
58
  const cert = certs[i];
59
- if (!cert.sans.includes('*.ip.abtnet.io')) {
59
+ if (!cert.domain === '*.ip.abtnet.io') {
60
60
  try {
61
61
  // eslint-disable-next-line no-await-in-loop
62
- await routerManager.deleteCertificate({ id: cert.id }, context);
62
+ await certManager.remove(cert.id);
63
63
  } catch (err) {
64
64
  // Do nothing
65
65
  }
@@ -109,7 +109,15 @@ const resetFns = {
109
109
  invitations: resetInvitations,
110
110
  };
111
111
 
112
- module.exports = async ({ params, context, blockletManager, routerManager, takeRoutingSnapshot, teamManager }) => {
112
+ module.exports = async ({
113
+ params,
114
+ context,
115
+ blockletManager,
116
+ routerManager,
117
+ takeRoutingSnapshot,
118
+ teamManager,
119
+ certManager,
120
+ }) => {
113
121
  if (process.env.NODE_ENV !== 'e2e') {
114
122
  throw new Error('Reset node only exists for test purpose');
115
123
  }
@@ -140,7 +148,14 @@ module.exports = async ({ params, context, blockletManager, routerManager, takeR
140
148
  }
141
149
 
142
150
  // eslint-disable-next-line no-await-in-loop
143
- results[key] = await resetFns[key]({ context, blockletManager, routerManager, takeRoutingSnapshot, teamManager });
151
+ results[key] = await resetFns[key]({
152
+ context,
153
+ blockletManager,
154
+ routerManager,
155
+ takeRoutingSnapshot,
156
+ teamManager,
157
+ certManager,
158
+ });
144
159
  }
145
160
  }
146
161
 
@@ -1,6 +1,7 @@
1
1
  const logger = require('@abtnode/logger')('@abtnode/core:webhook:index');
2
2
 
3
- const sortPriorityUrl = require('@abtnode/util/lib/sort-priority-url');
3
+ const { evaluateURLs } = require('@abtnode/util/lib/url-evaluation');
4
+ const checkURLAccessible = require('@abtnode/util/lib/url-evaluation/check-accessible-node');
4
5
  const { EVENTS } = require('@abtnode/constant');
5
6
  const WebHookSender = require('./sender');
6
7
  const createQueue = require('../queue');
@@ -29,7 +30,10 @@ const getSlackUrlInfo = async (actionPath = '/notifications', urls) => {
29
30
  });
30
31
  }
31
32
 
32
- const prioritys = await sortPriorityUrl(urls);
33
+ const prioritys = await evaluateURLs(
34
+ urls.map((item) => item.url),
35
+ { checkAccessble: checkURLAccessible }
36
+ );
33
37
  const priorityUrl = prioritys[0].url;
34
38
 
35
39
  const { protocol } = new URL(priorityUrl);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.7.2",
6
+ "version": "1.7.5",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,28 +19,29 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/certificate-manager": "1.7.2",
23
- "@abtnode/constant": "1.7.2",
24
- "@abtnode/cron": "1.7.2",
25
- "@abtnode/db": "1.7.2",
26
- "@abtnode/logger": "1.7.2",
27
- "@abtnode/queue": "1.7.2",
28
- "@abtnode/rbac": "1.7.2",
29
- "@abtnode/router-provider": "1.7.2",
30
- "@abtnode/static-server": "1.7.2",
31
- "@abtnode/timemachine": "1.7.2",
32
- "@abtnode/util": "1.7.2",
33
- "@arcblock/did": "^1.15.3",
34
- "@arcblock/event-hub": "1.15.3",
22
+ "@abtnode/certificate-manager": "1.7.5",
23
+ "@abtnode/constant": "1.7.5",
24
+ "@abtnode/cron": "1.7.5",
25
+ "@abtnode/db": "1.7.5",
26
+ "@abtnode/logger": "1.7.5",
27
+ "@abtnode/queue": "1.7.5",
28
+ "@abtnode/rbac": "1.7.5",
29
+ "@abtnode/router-provider": "1.7.5",
30
+ "@abtnode/static-server": "1.7.5",
31
+ "@abtnode/timemachine": "1.7.5",
32
+ "@abtnode/util": "1.7.5",
33
+ "@arcblock/did": "^1.15.7",
34
+ "@arcblock/did-motif": "^1.1.3",
35
+ "@arcblock/event-hub": "1.15.7",
35
36
  "@arcblock/pm2-events": "^0.0.5",
36
- "@arcblock/vc": "^1.15.3",
37
- "@blocklet/meta": "1.7.2",
37
+ "@arcblock/vc": "^1.15.7",
38
+ "@blocklet/meta": "1.7.5",
38
39
  "@fidm/x509": "^1.2.1",
39
40
  "@nedb/core": "^1.2.2",
40
41
  "@nedb/multi": "^1.2.2",
41
- "@ocap/mcrypto": "^1.15.3",
42
- "@ocap/util": "^1.15.3",
43
- "@ocap/wallet": "^1.15.3",
42
+ "@ocap/mcrypto": "^1.15.7",
43
+ "@ocap/util": "^1.15.7",
44
+ "@ocap/wallet": "^1.15.7",
44
45
  "@slack/webhook": "^5.0.3",
45
46
  "ajv": "^7.0.3",
46
47
  "axios": "^0.25.0",
@@ -49,7 +50,7 @@
49
50
  "deep-diff": "^1.0.2",
50
51
  "detect-port": "^1.3.0",
51
52
  "flat": "^5.0.2",
52
- "fs-extra": "^10.0.0",
53
+ "fs-extra": "^10.0.1",
53
54
  "get-port": "^5.1.1",
54
55
  "is-base64": "^1.1.0",
55
56
  "is-ip": "^3.1.0",
@@ -77,5 +78,5 @@
77
78
  "express": "^4.17.1",
78
79
  "jest": "^27.4.5"
79
80
  },
80
- "gitHead": "b84e7406d84fb9c3be5bf7ce968cb7b6b661d550"
81
+ "gitHead": "b17d83773e5a4c06bae390fc70398d49d6dd86b3"
81
82
  }
@@ -1,30 +0,0 @@
1
- module.exports = async ({ states, node, printInfo }) => {
2
- printInfo('Migrate certificates...');
3
- const certs = await states.certificate.find(
4
- {},
5
- {
6
- domain: 1,
7
- privateKey: 1,
8
- certificate: 1,
9
- createdAt: 1,
10
- updatedAt: 1,
11
- }
12
- );
13
-
14
- const tasks = certs.map((cert) => {
15
- const data = {
16
- _id: cert.id,
17
- domain: cert.domain,
18
- privateKey: cert.privateKey,
19
- certificate: cert.certificate,
20
- createdAt: cert.createdAt,
21
- updatedAt: cert.updatedAt,
22
- source: 'lets_encrypt',
23
- status: 'generated',
24
- };
25
-
26
- return node.certManager.addWithoutValidations(data);
27
- });
28
-
29
- await Promise.all(tasks);
30
- };
@@ -1,67 +0,0 @@
1
- /* eslint-disable no-underscore-dangle */
2
-
3
- const logger = require('@abtnode/logger')('@abtnode/core:https-cert');
4
- const BaseState = require('./base');
5
- const { getHttpsCertInfo } = require('../util');
6
-
7
- const attachHttpsCertInfo = (certificates = []) => {
8
- if (!certificates) {
9
- return null;
10
- }
11
-
12
- if (Array.isArray(certificates)) {
13
- return certificates.map((cert) => {
14
- const info = cert.certificate ? getHttpsCertInfo(cert.certificate) : {};
15
- return { ...cert, ...info };
16
- });
17
- }
18
-
19
- const info = certificates.certificate ? getHttpsCertInfo(certificates.certificate) : {};
20
- return { ...certificates, ...info };
21
- };
22
-
23
- class HttpsCert extends BaseState {
24
- constructor(baseDir, options = {}) {
25
- super(baseDir, { filename: 'https_cert.db', ...options });
26
-
27
- this.db.ensureIndex({ fieldName: 'domain', unique: true }, (error) => {
28
- if (error) {
29
- logger.error('ensure unique index failed', { error });
30
- }
31
- });
32
- }
33
-
34
- async upsert(entity) {
35
- const updateResult = await this.asyncDB.update(
36
- { domain: entity.domain },
37
- { $set: entity },
38
- {
39
- upsert: true,
40
- }
41
- );
42
-
43
- logger.debug('upsert result', { updateResult });
44
-
45
- const newEntity = await this.findOne({ domain: entity.domain });
46
-
47
- return HttpsCert.renameIdFiledName(newEntity);
48
- }
49
-
50
- async find(condition, projection) {
51
- const dbEntity = await this.asyncDB.find(condition, { privateKey: 0, ...(projection || {}) });
52
-
53
- return attachHttpsCertInfo(HttpsCert.renameIdFiledName(dbEntity));
54
- }
55
-
56
- async findOne(condition, projection) {
57
- const dbEntity = await this.asyncDB.findOne(condition, { privateKey: 0, ...(projection || {}) });
58
-
59
- return attachHttpsCertInfo(HttpsCert.renameIdFiledName(dbEntity));
60
- }
61
-
62
- async remove(...args) {
63
- return this.asyncDB.remove(...args);
64
- }
65
- }
66
-
67
- module.exports = HttpsCert;