简体   繁体   中英

How to modify the connection.json file in the cards issued by the Hyperledger Composer REST server

I followed the tutorial Using Google OAUTH 2.0 with a REST server to persist the business network cards using the MongoDB Docker images. I am trying to build a web application in which there are two composer rest servers.

The first one has no authentication, and allow users to create a new participant and to issue a new card.

At this point, the second composer REST server, after authentication (with Google OAUTH2.0) should allow users to perform all the other operations. Anyway, I keep receiving the error:

Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]

I am almost sure that the problem is that since the REST server is in docker, the file connection.json in the business cards should be changed in order for the host to be reachable.

I already did this for the card that I used to install and start the network, so now the file for that card is:

{"name":"hlfv1",
"x-type":"hlfv1",
"x-commitTimeout":300,
"version":"1.0.0",
"client":
{"organization":"Org1"
    ,"connection":
    {"timeout":
        {
            "peer":{"endorser":"300","eventHub":"300","eventReg":"300"},
            "orderer":"300"
        }
    }
},
"channels":
{"composerchannel":
    {
        "orderers":["orderer.example.com"],
        "peers":{"peer0.org1.example.com":{}}
    }
},

"organizations":
{
    "Org1":{
        "mspid":"Org1MSP",
        "peers":["peer0.org1.example.com"],
        "certificateAuthorities":["ca.org1.example.com"]
    }
},
"orderers":
{
    "orderer.example.com":
    {"url":"grpc://orderer.example.com:7050"}
},
"peers":
{
    "peer0.org1.example.com":
    {"url":"grpc://peer0.org1.example.com:7051"}
},
"certificateAuthorities":
{
    "ca.org1.example.com":
    {"url":"http://ca.org1.example.com:7054","caName":"ca.org1.example.com"}
}

}

But my question is, how do I change this file for every new card issued by the REST server? Is there a way to configure the REST server to do this automatically?

Assuming you are running a simple Fabric locally (such as the Development Fabric provided by the Composer Tools) then you take advantage of Docker Port Forwarding to connect to the Fabric on localhost (usually 127.0.0.1). However when you are running inside a Docker container localhost just reflects back into the container, so the port forwarding on the Docker host is not used. The tutorial creates a dedicated 'restadmin' card for the container which replaces the localhost URLs with URLs containing the container names for the Fabric containers, and because they use the same Docker networking bridge (composer_default) it all works ok.

When you Issue an Identity with the Composer REST server, the new identity (and card) is issued with the Connection.json of the 'current' ID.

So I'm guessing that in your case you have your first REST server (no authentication) running locally NOT in a container, and the 2nd Multi User REST server running inside a container. So you have a mismatch between the Fabric URLs of the 2 REST servers.

Maybe the solution is to run them both locally, or Both as Containers, so that the cards between the servers will be consistent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM