Skip to content

Commit

Permalink
[FAB-6652] NodeSDK - access client config
Browse files Browse the repository at this point in the history
Allow quick access to the client section of the
connetion profile from the top level fabric-client
client instance object.

Change-Id: I17f613878520133adb64a0f0048c5065c80b8c73
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Oct 18, 2017
1 parent 0c9ebd1 commit dafb979
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 13 additions & 0 deletions fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ var Client = class extends BaseClient {
return ca_service;
}

/**
* Returns the "client" section of the network configuration.
*
* @returns {object} The cleint section from the configuration
*/
getClientConfig() {
let result = null;
if(this._network_config && this._network_config.hasClient()) {
result = this._network_config.getClientConfig();
}

return result;
}
/**
* Returns a new {@link TransactionID} object. Fabric transaction ids are constructed
* as a hash of a nonce concatenated with the signing identity's serialized bytes. The
Expand Down
7 changes: 5 additions & 2 deletions fabric-client/lib/impl/NetworkConfig_1_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ var NetworkConfig_1_0 = class {
var result = {};
if(this._network_config && this._network_config.client) {
let client_config = this._network_config.client;
if(client_config.organization) {
result.organization = client_config.organization;
for(let setting in client_config) {
// copy all except credentialStore, special case to handle paths
if(setting !== 'credentialStore') {
result[setting] = client_config[setting];
}
}
if(client_config.credentialStore) {
result.credentialStore = {};
Expand Down
10 changes: 6 additions & 4 deletions test/unit/network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ test('\n\n ** configuration testing **\n\n', function (t) {
t.doesNotThrow(
() => {
var client = Client.loadFromConfig('test/fixtures/network.yaml');
client.loadFromConfig({ version:'1.0.0', client : {organization : 'Org1'}});
client.loadFromConfig('test/fixtures/org1.yaml');
t.equals('Org1', client._network_config._network_config.client.organization, ' org should be Org1');
client.loadFromConfig({ version:'1.0.0', client : {organization : 'Org2'}});
client.loadFromConfig('test/fixtures/org2.yaml');
t.equals('Org2', client._network_config._network_config.client.organization, ' org should be Org2');
var channel = client.getChannel('mychannel2');
let event_hubs = client.getEventHubsForOrg();
t.equals('localhost:8053', event_hubs[0].getPeerAddr(), ' Check to see if we got the right event hub');
t.equals('localhost:8053', event_hubs[0].getPeerAddr(), ' Check to see if we got the right event hub for org2 by default');
event_hubs = client.getEventHubsForOrg('Org1');
t.equals('localhost:7053', event_hubs[0].getPeerAddr(), ' Check to see if we got the right event hub');
t.equals('localhost:7053', event_hubs[0].getPeerAddr(), ' Check to see if we got the right event hub for org1 by specifically asking for org1');
let client_config = client.getClientConfig();
t.equals('wallet-name', client_config.credentialStore.wallet, ' check to see if we can get the wallet name from the client config');
},
null,
'2 Should be able to instantiate a new instance of "Channel" with the definition in the network configuration'
Expand Down

0 comments on commit dafb979

Please sign in to comment.