Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 4de9150

Browse files
FABN-1124: Use MSP ID from client user context
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>
1 parent ffef003 commit 4de9150

File tree

4 files changed

+361
-301
lines changed

4 files changed

+361
-301
lines changed

fabric-client/lib/Client.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const Client = class extends BaseClient {
7070

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

7575
this._stateStore = null;
7676
this._userContext = null;
@@ -393,7 +393,7 @@ const Client = class extends BaseClient {
393393
getPeersForOrg(mspid) {
394394
let _mspid = mspid;
395395
if (!mspid) {
396-
_mspid = this._mspid;
396+
_mspid = this.getMspid();
397397
}
398398
if (_mspid && this._network_config) {
399399
const organization = this._network_config.getOrganizationByMspId(_mspid);
@@ -463,7 +463,7 @@ const Client = class extends BaseClient {
463463
const temp_peers = {};
464464
for (const i in channel_names) {
465465
const channel = this.getChannel(channel_names[i]);
466-
const channel_peers = channel.getPeersForOrg(this._mspid);
466+
const channel_peers = channel.getPeersForOrg();
467467
for (const j in channel_peers) {
468468
const peer = channel_peers[j];
469469
temp_peers[peer.getName()] = peer; // will remove duplicates
@@ -576,7 +576,9 @@ const Client = class extends BaseClient {
576576
* section of the loaded common connection profile
577577
*/
578578
getMspid() {
579-
return this._mspid;
579+
const user = this._userContext;
580+
const identity = (user && user.getIdentity());
581+
return (identity && identity.getMSPId()) || this._clientConfigMspid;
580582
}
581583

582584

@@ -1327,7 +1329,7 @@ const Client = class extends BaseClient {
13271329
if (client_config && client_config.organization) {
13281330
const organization_config = this._network_config.getOrganization(client_config.organization, true);
13291331
if (organization_config) {
1330-
this._mspid = organization_config.getMspid();
1332+
this._clientConfigMspid = organization_config.getMspid();
13311333
}
13321334
}
13331335
}

0 commit comments

Comments
 (0)