Common connection profile missing error while adding user for organization

♀尐吖头ヾ 提交于 2020-01-02 15:01:59

问题


I am getting

Error: Common connection profile is missing this client's organization and certificate authority 

Error, while running gateway.getClient().getCertificateAuthority() code line. My connection profile file is there and as per my understanding it has no issues.

Following is my nodejs client code.

'use strict';

const { FileSystemWallet, Gateway, X509WalletMixin } = require('fabric-network');
const path = require('path');

const ccpPath = "../connection-ogr4.json";

async function main() {
    try {

        let user = 'user2';
        // Create a new file system based wallet for managing identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet = new FileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);

        const userExists = await wallet.exists(user);

        // Check to see if we've already enrolled the admin user.
        const adminExists = await wallet.exists('admin');

        // Create a new gateway for connecting to our peer node.
        const gateway = new Gateway();
        await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
        // Get the CA client object from the gateway for interacting with the CA.
        const ca = gateway.getClient().getCertificateAuthority()

It uses the following connection json file.

{
"name": "network-org4",
"version": "1.0.0",
"client": {
    "organization": "Org4",
    "connection": {
        "timeout": {
            "peer": {
                "endorser": "300"
            }
        }
    }
},
"organizations": {
    .......
},
"certificateAuthorities": {
    "ca.org4.bc4scm.de": {
        "url": "https://localhost:9054",
        "caName": "ca-org4",
        "tlsCACerts": {
            "path": "crypto-config/peerOrganizations/org4.bc4scm.de/tlsca/tlsca.org4.bc4scm.de-cert.pem"
        },
        "httpOptions": {
            "verify": false
        }
    }
}

}

What is the reason for this issue? Appreciate your insights.


回答1:


There might be "channels", orderers, peers ,missing.For more insight you could refer - https://fabric-sdk-node.github.io/tutorial-network-config.html Meanwhile below is the running snippet, you only need to change the configuration according to your network.

{
  "name": "dockercompose_default",
  "version": "1.0",
  "client": {
     "organization": "org1",
     "connection": {
         "timeout": {
             "peer": {
                 "endorser": "300"
             },
             "orderer": "300"
         }
     }
 },
  "channels": {
      "common": {
          "orderers": [
              "orderer.example.com"
          ],
          "peers": {
              "peer0.org.example.com": {
                  "endorsingPeer": true,
                  "chaincodeQuery": true,
                  "ledgerQuery": true,
                  "eventSource": true
              },
              "peer1.org.example.com": {
                  "endorsingPeer": true,
                  "chaincodeQuery": false,
                  "ledgerQuery": true,
                  "eventSource": false
              }

          }
      },
      "a-b": {
          "orderers": [
              "orderer.example.com"
          ],
          "peers": {
              "peer0.org.example.com": {
                  "endorsingPeer": true,
                  "chaincodeQuery": true,
                  "ledgerQuery": true,
                  "eventSource": true
              },
              "peer1.org.example.com": {
                  "endorsingPeer": true,
                  "chaincodeQuery": false,
                  "ledgerQuery": true,
                  "eventSource": false
              }

          }
      }
  },
  "organizations": {
      "org1": {
          "mspid": "org1MSP",
          "peers": [
              "peer0.org.example.com",
              "peer1.org.example.com"
          ],
          "certificateAuthorities": [
              "ca.org.example.com"
          ],
          "adminPrivateKey": {
              "path": "../artifacts/crypto-config/peerOrganizations/org.example.com/users/Admin@org.example.com/msp/keystore/d30f6a06fa605d23da82f7f98bce3c00b37707f6363ca698331c6a1d834c47d4_sk"
          },
          "signedCert": {
              "path": "../artifacts/crypto-config/peerOrganizations/org.example.com/users/Admin@org.example.com/msp/signcerts/Admin@org.example.com-cert.pem"
          }
      }    
  },
  "orderers": {
      "orderer.example.com": {
          "url": "grpcs://localhost:7050",
          "grpcOptions": {
              "ssl-target-name-override": "orderer.example.com",
              "grpc-max-send-message-length": -1
          },
          "tlsCACerts": {
              "path": "../artifacts/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt"
          }
      }
  },
  "peers": {
      "peer0.org.example.com": {
          "url": "grpcs://localhost:7051",
          "eventUrl": "grpcs://localhost:7053",
          "grpcOptions": {
              "ssl-target-name-override": "peer0.org.example.com",
              "grpc.keepalive_time_ms": 600000
          },
          "tlsCACerts": {
              "path": "../artifacts/crypto-config/peerOrganizations/org.example.com/peers/peer0.org.example.com/tls/ca.crt"
          }
      },
      "peer1.org.example.com": {
          "url": "grpcs://localhost:7056",
          "eventUrl": "grpcs://localhost:7058",
          "grpcOptions": {
              "ssl-target-name-override": "peer1.org.example.com"
          },
          "tlsCACerts": {
              "path": "../artifacts/crypto-config/peerOrganizations/org.example.com/peers/peer1.org.example.com/tls/ca.crt"
          }
      }        
  },
  "certificateAuthorities": {
      "ca.org.example.com": {
          "url": "https://localhost:7054",
          "httpOptions": {
              "verify": true
          },
          "tlsCACerts": {
              "path": "../artifacts/crypto-config/peerOrganizations/org.example.com/peers/peer0.org.example.com/tls/ca.crt"
          },
          "registrar": [
              {
                  "enrollId": "admin",
                  "enrollSecret": "adminpw"
              }
          ],
          "caName": "ca.org.example.com"
      }        
  }
}


来源:https://stackoverflow.com/questions/56828682/common-connection-profile-missing-error-while-adding-user-for-organization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!