Skip to content

Commit

Permalink
[FABN-1219] Convert FabricCAClient.js to ES6 syntax.
Browse files Browse the repository at this point in the history
Delete "'use strict';" in ES5 syntax, because ES6 modules
are always in strict mode.
Using template literals in ES6 instead of
concatenated strings, because of the readability
and expression friendliness.

Refactor object-curly-spacing.

Change-Id: I46026b85c07e67c3711b061fdf20d69a2c23be75
Signed-off-by: “5sWind” <[email protected]>
  • Loading branch information
“5sWind” committed May 1, 2019
1 parent 71e371b commit a9f082c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions fabric-ca-client/lib/FabricCAClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

'use strict';

const {Utils: utils} = require('fabric-common');
const config = utils.getConfig();
const logger = utils.getLogger('FabricCAClient.js');
Expand Down Expand Up @@ -40,7 +38,7 @@ const FabricCAClient = class {
try {
this._validateConnectionOpts(connect_opts);
} catch (err) {
throw new Error('Invalid connection options. ' + err.message);
throw new Error(`Invalid connection options. ${err.message}`);
}

this._caName = connect_opts.caname,
Expand Down Expand Up @@ -283,7 +281,7 @@ const FabricCAClient = class {
const requestOptions = {
hostname: self._hostname,
port: self._port,
path: path,
path,
method: http_method,
headers: {
Authorization: self.generateAuthToken(requestObj, signingIdentity, path, http_method)
Expand Down Expand Up @@ -363,21 +361,21 @@ const FabricCAClient = class {
let signString;
if (reqBody) {
const body = Buffer.from(JSON.stringify(reqBody)).toString('base64');
signString = body + '.' + cert;
signString = `${body}.${cert}`;
} else {
signString = '.' + cert;
signString = `.${cert}`;
}

if (path && method) {
const s = Buffer.from(path).toString('base64');
signString = method + '.' + s + '.' + signString;
signString = `${method}.${s}.${signString}`;
}

const sig = signingIdentity.sign(signString, {hashFunction: this._cryptoPrimitives.hash.bind(this._cryptoPrimitives)});
logger.debug(util.format('signString: %s', signString));

const b64Sign = Buffer.from(sig, 'hex').toString('base64');
return cert + '.' + b64Sign;
return `${cert}.${b64Sign}`;
}

/**
Expand Down Expand Up @@ -416,9 +414,9 @@ const FabricCAClient = class {
const requestOptions = {
hostname: self._hostname,
port: self._port,
path: self._baseAPI + 'enroll',
path: `${self._baseAPI}enroll`,
method: 'POST',
auth: enrollmentID + ':' + enrollmentSecret,
auth: `${enrollmentID}:${enrollmentSecret}`,
ca: self._tlsOptions.trustedRoots,
rejectUnauthorized: self._tlsOptions.verify
};
Expand Down

0 comments on commit a9f082c

Please sign in to comment.