Skip to content

Commit

Permalink
FABN-1124: Use MSP ID from client user context
Browse files Browse the repository at this point in the history
If Client has a user context set, use the MSP ID of that user as
the default MSP ID for the client. If no user context is set,
use the MSP ID of the organization specified in the client section
of the common connection profile used to configure the client, as
before.

This allows the client section of the connection profile to be
omitted for discovery, and functions like Client.getPeersForOrg()
to return the correct results in this case.

Change-Id: I7e0f1bd79c904a0b665a3b411952beb65884e38e
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
  • Loading branch information
bestbeforetoday committed Jan 30, 2019
1 parent ffef003 commit 4de9150
Show file tree
Hide file tree
Showing 4 changed files with 361 additions and 301 deletions.
12 changes: 7 additions & 5 deletions fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Client = class extends BaseClient {

constructor() {
super();
this._mspid = null; // The mspid id and the organization id
this._clientConfigMspid = null; // MSP ID of the organization specified in the client section of the connection profile

this._stateStore = null;
this._userContext = null;
Expand Down Expand Up @@ -393,7 +393,7 @@ const Client = class extends BaseClient {
getPeersForOrg(mspid) {
let _mspid = mspid;
if (!mspid) {
_mspid = this._mspid;
_mspid = this.getMspid();
}
if (_mspid && this._network_config) {
const organization = this._network_config.getOrganizationByMspId(_mspid);
Expand Down Expand Up @@ -463,7 +463,7 @@ const Client = class extends BaseClient {
const temp_peers = {};
for (const i in channel_names) {
const channel = this.getChannel(channel_names[i]);
const channel_peers = channel.getPeersForOrg(this._mspid);
const channel_peers = channel.getPeersForOrg();
for (const j in channel_peers) {
const peer = channel_peers[j];
temp_peers[peer.getName()] = peer; // will remove duplicates
Expand Down Expand Up @@ -576,7 +576,9 @@ const Client = class extends BaseClient {
* section of the loaded common connection profile
*/
getMspid() {
return this._mspid;
const user = this._userContext;
const identity = (user && user.getIdentity());
return (identity && identity.getMSPId()) || this._clientConfigMspid;
}


Expand Down Expand Up @@ -1327,7 +1329,7 @@ const Client = class extends BaseClient {
if (client_config && client_config.organization) {
const organization_config = this._network_config.getOrganization(client_config.organization, true);
if (organization_config) {
this._mspid = organization_config.getMspid();
this._clientConfigMspid = organization_config.getMspid();
}
}
}
Expand Down
Loading

0 comments on commit 4de9150

Please sign in to comment.