Skip to content

Commit

Permalink
[FAB-8953] Fix eslint error
Browse files Browse the repository at this point in the history
This fixes #FAB-8953

This CR fix /fabric-client and /fabric-ca-client
Have not fixed test/*

for not implemented functions, abstract methods,
 use ``if(unused0||unused1);`` to skip eslint checking

remove unused internal utility method functions in lib/Channel.js
 - _combineMSPs
 - _arrayToMap

Change-Id: I3345ee052a1f8d300fa3393205e6f5649b4789f1
Signed-off-by: davidliu <[email protected]>
  • Loading branch information
davidkhala committed Mar 19, 2018
1 parent 907e33e commit c12930b
Show file tree
Hide file tree
Showing 25 changed files with 372 additions and 456 deletions.
135 changes: 67 additions & 68 deletions fabric-ca-client/lib/FabricCAClientImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

'use strict';

var api = require('./api.js');
var utils = require('./utils.js');
var BaseClient = require('./BaseClient.js');
var util = require('util');
Expand Down Expand Up @@ -89,7 +88,7 @@ var FabricCAServices = class extends BaseClient {

var endpoint = FabricCAServices._parseURL(url);

if (!!cryptoSuite) {
if (cryptoSuite) {
this.setCryptoSuite(cryptoSuite);
} else {
this.setCryptoSuite(utils.newCryptoSuite());
Expand Down Expand Up @@ -210,31 +209,31 @@ var FabricCAServices = class extends BaseClient {
}
self.getCryptoSuite().generateKey(opts)
.then(
function (privateKey) {
function (privateKey) {
//generate CSR using enrollmentID for the subject
try {
var csr = privateKey.generateCSR('CN=' + req.enrollmentID);
self._fabricCAClient.enroll(req.enrollmentID, req.enrollmentSecret, csr, req.profile, req.attr_reqs)
.then(
function (enrollResponse) {
return resolve({
key: privateKey,
certificate: enrollResponse.enrollmentCert,
rootCertificate: enrollResponse.caCertChain
});
},
function (err) {
return reject(err);
}
);

} catch (err) {
return reject(new Error(util.format('Failed to generate CSR for enrollmemnt due to error [%s]', err)));
try {
var csr = privateKey.generateCSR('CN=' + req.enrollmentID);
self._fabricCAClient.enroll(req.enrollmentID, req.enrollmentSecret, csr, req.profile, req.attr_reqs)
.then(
function (enrollResponse) {
return resolve({
key: privateKey,
certificate: enrollResponse.enrollmentCert,
rootCertificate: enrollResponse.caCertChain
});
},
function (err) {
return reject(err);
}
);

} catch (err) {
return reject(new Error(util.format('Failed to generate CSR for enrollmemnt due to error [%s]', err)));
}
},
function (err) {
return reject(new Error(util.format('Failed to generate key for enrollment due to error [%s]', err)));
}
},
function (err) {
return reject(new Error(util.format('Failed to generate key for enrollment due to error [%s]', err)));
}
);

});
Expand Down Expand Up @@ -295,31 +294,31 @@ var FabricCAServices = class extends BaseClient {
//generate enrollment certificate pair for signing
self.getCryptoSuite().generateKey()
.then(
function (privateKey) {
function (privateKey) {
//generate CSR using the subject of the current user's certificate
try {
var csr = privateKey.generateCSR('CN=' + subject);
self._fabricCAClient.reenroll(csr, currentUser.getSigningIdentity(), attr_reqs)
.then(
function (response) {
return resolve({
key: privateKey,
certificate: Buffer.from(response.result.Cert, 'base64').toString(),
rootCertificate: Buffer.from(response.result.ServerInfo.CAChain, 'base64').toString()
});
},
function (err) {
return reject(err);
}
);

} catch (err) {
return reject(new Error(util.format('Failed to generate CSR for enrollmemnt due to error [%s]', err)));
try {
var csr = privateKey.generateCSR('CN=' + subject);
self._fabricCAClient.reenroll(csr, currentUser.getSigningIdentity(), attr_reqs)
.then(
function (response) {
return resolve({
key: privateKey,
certificate: Buffer.from(response.result.Cert, 'base64').toString(),
rootCertificate: Buffer.from(response.result.ServerInfo.CAChain, 'base64').toString()
});
},
function (err) {
return reject(err);
}
);

} catch (err) {
return reject(new Error(util.format('Failed to generate CSR for enrollmemnt due to error [%s]', err)));
}
},
function (err) {
return reject(new Error(util.format('Failed to generate key for enrollment due to error [%s]', err)));
}
},
function (err) {
return reject(new Error(util.format('Failed to generate key for enrollment due to error [%s]', err)));
}
);

});
Expand Down Expand Up @@ -575,11 +574,11 @@ var FabricCAClient = class {
}

return self.post('register', regRequest, signingIdentity)
.then(function (response) {
return resolve(response.result.secret);
}).catch(function (err) {
return reject(err);
});
.then(function (response) {
return resolve(response.result.secret);
}).catch(function (err) {
return reject(err);
});
});
}

Expand Down Expand Up @@ -618,11 +617,11 @@ var FabricCAClient = class {
};

return self.post('revoke', regRequest, signingIdentity)
.then(function (response) {
return resolve(response);
}).catch(function (err) {
return reject(err);
});
.then(function (response) {
return resolve(response);
}).catch(function (err) {
return reject(err);
});
});
}

Expand Down Expand Up @@ -654,11 +653,11 @@ var FabricCAClient = class {
}

return self.post('reenroll', request, signingIdentity)
.then(function (response) {
return resolve(response);
}).catch(function (err) {
return reject(err);
});
.then(function (response) {
return resolve(response);
}).catch(function (err) {
return reject(err);
});
});
}

Expand Down Expand Up @@ -947,7 +946,7 @@ var FabricCAClient = class {
if (!(contents[0].match(/-----\s*BEGIN ?([^-]+)?-----/) &&
contents[contents.length - 1].match(/-----\s*END ?([^-]+)?-----/))) {
throw new Error('Input parameter does not appear to be PEM-encoded.');
};
}
contents.shift(); //remove BEGIN
contents.pop(); //remove END
//base64 decode and encode as hex string
Expand All @@ -964,17 +963,17 @@ var FabricCAClient = class {
//check for protocol
if (!connect_opts.protocol) {
throw new Error('Protocol must be set to \'http\' or \'https\'');
};
}

if (connect_opts.protocol != 'http') {
if (connect_opts.protocol != 'https') {
throw new Error('Protocol must be set to \'http\' or \'https\'');
}
};
}

if (!connect_opts.hostname) {
throw new Error('Hostname must be set');
};
}

if (connect_opts.port) {
if (!Number.isInteger(connect_opts.port)) {
Expand All @@ -993,7 +992,7 @@ function getSubjectCommonName(pem) {
var hex = x509.pemToHex(pem);
var d = ASN1HEX.getDecendantHexTLVByNthList(hex, 0, [0, 5]);
var subject = x509.hex2dn(d); // format: '/C=US/ST=California/L=San Francisco/[email protected]/[email protected]'
var m = subject.match(/CN=.+[^\/]/);
var m = subject.match(/CN=.+[^/]/);
if (!m)
throw new Error('Certificate PEM does not seem to contain a valid subject with common name "CN"');
else
Expand Down
3 changes: 1 addition & 2 deletions fabric-ca-client/lib/IdentityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

'use strict';

const logger = require('./utils').getLogger('IdentityService');
const checkRegistrar = require('./helper').checkRegistrar;

/**
Expand Down Expand Up @@ -115,7 +114,7 @@ class IdentityService {
* @return {Promise} Return the secret of this new identity
*/
create(req, registrar) {
if (typeof req === 'undefined' || req === null) {
if (!req) {
throw new Error('Missing required argument "req"');
}

Expand Down
3 changes: 1 addition & 2 deletions fabric-client/lib/BlockDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'use strict';

var grpc = require('grpc');
var util = require('util');
var path = require('path');
var utils = require('./utils.js');
var logger = utils.getLogger('BlockDecoder.js');
Expand Down Expand Up @@ -858,7 +857,7 @@ function decodeConfigPolicy(proto_config_policy) {
config_policy.policy.value = decodeSignaturePolicyEnvelope(proto_config_policy.value.policy.value);
break;
case _policiesProto.Policy.PolicyType.MSP:
var proto_msp = _policiesProto.Policy.decode(proto_config_policy.value.policy.value);
// var proto_msp = _policiesProto.Policy.decode(proto_config_policy.value.policy.value);
logger.warn('decodeConfigPolicy - found a PolicyType of MSP. This policy type has not been implemented yet.');
break;
case _policiesProto.Policy.PolicyType.IMPLICIT_META:
Expand Down
3 changes: 0 additions & 3 deletions fabric-client/lib/CertificateAuthority.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

'use strict';

var api = require('./api.js');
var utils = require('./utils.js');
var util = require('util');

var logger = utils.getLogger('CertificateAuthority.js');

/**
Expand Down
26 changes: 1 addition & 25 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2076,30 +2076,6 @@ function _getProposalResponseResults(proposal_response) {
return extension.results.toBuffer();
}

//internal utility method to combine MSPs
function _combineMSPs(current, configuration) {
var results = new Map();
_arrayToMap(results, current);
// do these second to replace any of the same name
_arrayToMap(results, configuration);

return results;
}

//internal utility method to add msps to a map
function _arrayToMap(map, msps) {
if (msps) {
var keys = Object.keys(msps);
for (let key in keys) {
let id = keys[key];
let msp = msps[id];
let mspid = msp.getId();
logger.debug('_arrayToMap - add msp ::%s', mspid);
map.set(mspid, msp);
}
}
}

/*
* utility method to load in a config group
* @param {Object} - config_items - holder of values found in the configuration
Expand Down Expand Up @@ -2319,7 +2295,7 @@ function loadPolicy(config_items, versions, key, policy, group_name) {
try {
if(policy.type === _policiesProto.Policy.PolicyType.SIGNATURE){
let signature_policy = _policiesProto.SignaturePolicyEnvelope.decode(policy.policy);
logger.debug('loadPolicy - %s - policy SIGNATURE :: %s %s', group_name, signature_policy.encodeJSON(), this.decodeSignaturePolicy(signature_policy.getIdentities()));
logger.debug('loadPolicy - %s - policy SIGNATURE :: %s %s', group_name, signature_policy.encodeJSON(), decodeSignaturePolicy(signature_policy.getIdentities()));
}else if(policy.type === _policiesProto.Policy.PolicyType.IMPLICIT_META){
let implicit_policy = _policiesProto.ImplicitMetaPolicy.decode(policy.value);
let rule = ImplicitMetaPolicy_Rule[implicit_policy.getRule()];
Expand Down
Loading

0 comments on commit c12930b

Please sign in to comment.