How to use the fabric-client.getConfigSetting function in fabric-client

To help you get started, we’ve selected a few fabric-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / test / integration / grpc.js View on Github external
test('\n\n*** GRPC message size tests ***\n\n', async (t) => {
	testUtil.resetDefaults();
	testUtil.setupChaincodeDeploy();

	try {
		// setup client , including user and tls mutual certs
		const client = new Client();
		const channel_name = testUtil.END2END.channel;
		const channel = client.newChannel(channel_name);
		const ORGS = Client.getConfigSetting('test-network');
		const userOrg = 'org1';
		const orgName = ORGS[userOrg].name;
		const url = ORGS[userOrg].peer1.requests;
		const data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[userOrg].peer1.tls_cacerts));
		const cryptoSuite = Client.newCryptoSuite();
		cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
		client.setCryptoSuite(cryptoSuite);
		const tlsInfo = await e2eUtils.tlsEnroll(userOrg);
		client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
		const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(orgName)});
		client.setStateStore(store);
		await testUtil.getSubmitter(client, t, userOrg, true);

		// make sure chaincode is installed that has the echo function
		const go_cc = testUtil.END2END.chaincodeId;
		const node_cc = testUtil.NODE_END2END.chaincodeId;
github hyperledger / fabric-sdk-node / test / integration / cloudant-fabricca-tests.js View on Github external
test('Use FabricCAServices wih a Cloudant CouchDB KeyValueStore', (t) => {
	testUtil.resetDefaults();
	Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
	ORGS = Client.getConfigSetting('test-network');
	const fabricCAEndpoint = ORGS[userOrg].ca.url;

	Client.addConfigFile('test/fixtures/credentials/cloudant.json');
	const keyValueStore = Client.getConfigSetting('key-value-store');
	logger.debug('cloudant Key Value Store = ' + keyValueStore);

	// override t.end function so it'll always clear the config settings
	t.end = ((context, f) => {
		return function() {
			if (global && global.hfc) {
				global.hfc.config = undefined;
			}
			require('nconf').reset();

			f.apply(context, arguments);
		};
github hyperledger / fabric-test / tools / PTE / pte-execRequest.js View on Github external
orderersCPFList = testUtil.getNodetypeFromConnProfilesSubmitter(cpList, 'orderers');

// set org connection profile
var cpf=testUtil.findOrgConnProfileSubmitter(cpList, org);
if ( 0 === testUtil.getConnProfilePropCntSubmitter(cpf, 'orderers') ) {
    logger.error('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] no orderer found in the connection profile', Nid, channel.getName(), org, pid);
    process.exit(1);
}
if ( 0 === testUtil.getConnProfilePropCntSubmitter(cpf, 'peers') ) {
    logger.error('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] no peer found in the connection profile', Nid, channel.getName(), org, pid);
    process.exit(1);
}
var cpOrgs = cpf['organizations'];
var cpPeers = cpf['peers'];

var users =  hfc.getConfigSetting('users');

//user parameters
var transMode = txCfgPtr.transMode.toUpperCase();
var transType = txCfgPtr.transType.toUpperCase();
var invokeType = txCfgPtr.invokeType.toUpperCase();
var nRequest = parseInt(txCfgPtr.nRequest);

if ( transType == 'DISCOVERY' && TLS != testUtil.TLSCLIENTAUTH ) {
    logger.error('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] invalid configuration: transType (%s) requires mutual TLS (clientauth)', Nid, channelName, org, pid, transType);
    process.exit(1);
}

logger.info('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] transMode: %s, transType: %s, invokeType: %s, nRequest: %d', Nid, channel.getName(), org, pid,  transMode, transType, invokeType, nRequest);


// orderer parameters
github hyperledger / fabric-sdk-node / test / unit / headless-tests.js View on Github external
test('\n\n ** Config **\n\n', function (t) {
	// setup the environment
	process.argv.push('--test-4=argv');
	process.argv.push('--test-5=argv');
	process.env.TEST_3 = 'env';
	process.env.test_6 = 'mapped';
	// internal call. clearing the cached config.
	global.hfc.config = undefined;
	t.equals(hfc.getConfigSetting('request-timeout', 'notfound'), 3000, 'checking that able to get "request-timeout" value from an additional configuration file');
	//try adding another config file
	hfc.addConfigFile('test/fixtures/local.json');
	t.equals(hfc.getConfigSetting('test-2', 'notfound'), 'local', 'checking that able to test-2 value from an additional configuration file');
	t.equals(hfc.getConfigSetting('test-3', 'notfound'), 'env', 'checking that test-3 environment values are used');
	t.equals(hfc.getConfigSetting('test-4', 'notfound'), 'argv', 'checking that test-4 argument values are used');
	hfc.setConfigSetting('test-5', 'program');
	t.equals(hfc.getConfigSetting('test-5', 'notfound'), 'program', 'checking that test-5 program values are used');
	t.equals(hfc.getConfigSetting('test-6', 'notfound'), 'mapped', 'checking that test-6 is enviroment mapped value');
	t.end();
});
github asararatnakar / FabricNodeApp1.0 / app / instantiate-chaincode.js View on Github external
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
'use strict';
var path = require('path');
var fs = require('fs');
var util = require('util');
var hfc = require('fabric-client');
var Peer = require('fabric-client/lib/Peer.js');
var EventHub = require('fabric-client/lib/EventHub.js');
var config = require('../config.json');
var helper = require('./helper.js');
var logger = helper.getLogger('instantiate-chaincode');
hfc.addConfigFile(path.join(__dirname, 'network-config.json'));
var ORGS = hfc.getConfigSetting('network-config');
var tx_id = null;
var eh = null;

var instantiateChaincode = function(channelName, chaincodeName, chaincodeVersion, functionName, args, username, org, isUpgrade) {
	logger.debug('\n============ Instantiate chaincode on organization ' + org +
		' ============\n');

	var channel = helper.getChannelForOrg(org, channelName);
	var client = helper.getClientForOrg(org);

	return helper.getOrgAdmin(org).then((user) => {
		// read the config block from the orderer for the channel
		// and initialize the verify MSPs based on the participating
		// organizations
		return channel.initialize();
	}, (err) => {
github AliyunContainerService / solution-blockchain-demo / balance-transfer-app / app / helper.js View on Github external
async function getClientForOrg (userorg, username) {
	logger.debug('getClientForOrg - ****** START %s %s', userorg, username)
	// get a fabric client loaded with a connection profile for this org
	let config = '-connection-profile-path';

	// build a client context and load it with a connection profile
	// lets only load the network settings and save the client for later
	let client = hfc.loadFromConfig(hfc.getConfigSetting('network'+config));

	// This will load a connection profile over the top of the current one one
	// since the first one did not have a client section and the following one does
	// nothing will actually be replaced.
	// This will also set an admin identity because the organization defined in the
	// client section has one defined
	client.loadFromConfig(hfc.getConfigSetting(userorg+config));

	// this will create both the state store and the crypto store based
	// on the settings in the client section of the connection profile
	await client.initCredentialStores();

	// The getUserContext call tries to get the user from persistence.
	// If the user has been saved to persistence then that means the user has
	// been registered and enrolled. If the user is found in persistence
	// the call will then assign the user to the client object.
	if(username) {
		let user = await client.getUserContext(username, true);
		if(!user) {
			throw new Error(util.format('User was not found :', username));
		} else {
			logger.debug('User %s was found to be registered and enrolled', username);
		}
github hyperledger / fabric-sdk-node / test / integration / instantiate.js View on Github external
function instantiateChaincodeForError(request, error_snip, t) {

	Client.addConfigFile(path.join(__dirname, './e2e/config.json'));
	const ORGS = Client.getConfigSetting('test-network');

	const caRootsPath = ORGS.orderer.tls_cacerts;
	data = fs.readFileSync(path.join(__dirname, '/test', caRootsPath));
	const caroots = Buffer.from(data).toString();

	const userOrg = 'org1';
	const client = new Client();
	const channel_name = Client.getConfigSetting('E2E_CONFIGTX_CHANNEL_NAME', testUtil.END2END.channel);
	logger.debug(' channel_name %s', channel_name);
	const channel = client.newChannel(channel_name);
	const orgName = ORGS[userOrg].name;
	let tlsInfo = null;

	return e2eUtils.tlsEnroll(userOrg)
		.then((enrollment) => {
			t.pass('Successfully retrieved TLS certificate');
github hyperledger / fabric-sdk-node / test / scenario / features / steps / admin_steps.js View on Github external
this.Then(/^I can create and join a version_two capabilities channel named (.+?) to two organizations$/, {timeout: testUtil.TIMEOUTS.LONG_STEP}, async (channel_name) => {
		const client_org1  = Client.getConfigSetting('client-org1').value;
		const client_org2  = Client.getConfigSetting('client-org2').value;
		const peer_org1    = Client.getConfigSetting('peer-org1').value;
		const peer_org2    = Client.getConfigSetting('peer-org2').value;
		const orderer_org1 = Client.getConfigSetting('orderer-org1').value;
		const orderer_org2 = Client.getConfigSetting('orderer-org2').value;

		const channel_path = path.join(__dirname, '../../../fixtures/crypto-material/config-v2/' + channel_name + '.tx');
		await testUtil.createUpdateChannel(true, channel_path, channel_name, client_org1, client_org2, orderer_org1, orderer_org2);

		const channel_org1 = await testUtil.joinChannel(channel_name, peer_org1, orderer_org1, client_org1);
		const channel_org2 = await testUtil.joinChannel(channel_name, peer_org2, orderer_org2, client_org2);

		Client.setConfigSetting('channel-org1-' + channel_name, {value: channel_org1});
		Client.setConfigSetting('channel-org2-' + channel_name, {value: channel_org2});
	});
github dongmingh / v1performance / pte-execRequest.js View on Github external
var svcFile = uiContent.SCFile[0].ServiceCredentials;
logger.info('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] svcFile: %s, org: %s', Nid, channel.getName(), org, pid, svcFile, org);
hfc.addConfigFile(path.resolve(__dirname, svcFile));
var ORGS = hfc.getConfigSetting('test-network');
var goPath;
if ( typeof(ORGS.gopath) === 'undefined' ) {
    goPath = '';
} else if ( ORGS.gopath == 'GOPATH' ) {
    goPath = process.env['GOPATH'];
} else {
    goPath = ORGS.gopath;
}
logger.info('goPath: ', goPath);

var orgName = ORGS[org].name;
var users =  hfc.getConfigSetting('users');

//user parameters
var transMode = uiContent.transMode.toUpperCase();
var transType = uiContent.transType.toUpperCase();
var invokeType = uiContent.invokeType.toUpperCase();
var nRequest = parseInt(uiContent.nRequest);

logger.info('[Nid:chan:org:id=%d:%s:%s:%d pte-execRequest] transMode: %s, transType: %s, invokeType: %s, nRequest: %d', Nid, channel.getName(), org, pid,  transMode, transType, invokeType, nRequest);

//failover parameters
var peerList = [];
var currPeerId = 0;
var ordererList = [];
var currOrdererId = 0;
var peerFO = 'FALSE';
var ordererFO = 'FALSE';
github hyperledger-archives / caliper / src / fabric / install-chaincode.js View on Github external
module.exports.run = function (config_path) {
    Client.addConfigFile(config_path);
    testUtil.setupChaincodeDeploy();
    var fabricSettings = Client.getConfigSetting('fabric');
    var chaincodes     = fabricSettings.chaincodes;
    if(typeof chaincodes === 'undefined' || chaincodes.length === 0) {
        return Promise.resolve();
    }
    return new Promise(function(resolve, reject) {
        var t = global.tapeObj;
        t.comment('install all chaincodes......');
        chaincodes.reduce(function(prev, chaincode){
            return prev.then(() => {
                let promises = [];
                let channel  = testUtil.getChannel(chaincode.channel);
                if(channel === null) {
                    throw new Error('could not find channel in config');
                }
                for(let v in channel.organizations) {
                    promises.push(e2eUtils.installChaincode(channel.organizations[v], chaincode));