kalleknast / Microgrid

Hyperledger network for microgrids
GNU General Public License v3.0
4 stars 1 forks source link

How to change the affiliation? #4

Open kalleknast opened 5 years ago

kalleknast commented 5 years ago

In registerUser.js, the call to fabric_ca_client.register(...) only seems to work when affiliation is set to 'org1.department1'. Trying with 'house01' gives an error.

$ node registerUser.js
 Store path:./hfc-key-store
Successfully loaded admin from persistence
Failed to register: Error: fabric-ca request register failed with errors [[{"code":0,"message":"Registration of 'user1' failed in affiliation validation: Failed getting affiliation 'house01': : scode: 404, code: 63, msg: Failed to get Affiliation: sql: no rows in result set"}]]

It seems like the affiliations are hardcoded in /etc/hyperledger/fabric-ca-server/fabric-ca-server-config.yaml in the ca.microgrid.org container.

How to set the affiliations properly?

erickzzh commented 5 years ago

hmm I have never dealt with a CA before I will try things out and let you know.

I am having trouble starting the fabric-ca container. This is what I am receiving after I ran the scripts. Does it run on your environment?

screen shot 2018-10-28 at 8 09 33 pm

I also couldn't find the enrollAdmin.js file. Let me know if you left that one out on purpose.

kalleknast commented 5 years ago

I just forgot to push enrollAdmin.js. It is done now.

The fabric-ca container starts fine for me. I think it is important to properly clean out everything and run configure.sh. I just used ./stop.sh, ./configure.sh and then started the network. However, I think there is still something weird. If you look on line 12 of docker-compose-base.yaml, you'll see what looks like a hardcoded key. Does that make sense? If not, how can we replace it?

erickzzh commented 5 years ago

Oh yea I don't think it makes sense and I found two examples on how to replace it. I am still trying to figure out what it means exactly but here are the two examples.

  1. https://github.com/Taction/hyperledger-example/blob/1db4b111f203b2108535a88a9059cad332162b12/my-network/docker-compose-ca-template.yaml#L25

https://github.com/Taction/hyperledger-example/blob/1db4b111f203b2108535a88a9059cad332162b12/my-network/replace.sh#L42

2. https://github.com/brucezhu512/blockchain-samples/blob/f7c8e442d9c7cd620c1f76f3bb262b769bf0f826/pilot/base/ca-base-template.yaml#L16

https://github.com/brucezhu512/blockchain-samples/blob/f7c8e442d9c7cd620c1f76f3bb262b769bf0f826/pilot/generate-artifacts.sh#L113

As you can see both methods are under the replacePrivateKey() function

erickzzh commented 5 years ago

https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html#dynamically-updating-affiliations

I found a way to update, modify or delete the affiliation using the client-ca.

kalleknast commented 5 years ago

Great! I'll fix it tomorrow evening.

kalleknast commented 5 years ago

I got stuck. I tried using the SDK fabric_ca_client.newAffiliationService().create({ "name": "house01" }, admin_user) but it doesn't fly.

However, the real issues come when I try to run queries or writing. I thought that maybe it would be better to follow the balance-transfer example, but I cannot even run the example. I hope I'll get more time to troubleshoot this in the weekend.

erickzzh commented 5 years ago

I think the reason why you couldn't run query is that you don't have a function called "Query". That's a key variable that needs to be implemented within the chaincode file.

You can take a look at the IBM tut here https://www.ibm.com/developerworks/community/blogs/8d277a63-4204-4fd3-8cb8-b7cb222cd522/entry/Write_deploy_invoke_and_query_Chaincode_on_Blockchain_Hyperlegder_network?lang=en

Since our chaincode is called carecords, the complete command is bash peer chaincode query -C $CHANNEL_NAME -n carecords -c '{"Args":["getRecord","a"]}'

erickzzh commented 5 years ago

There were little errors in the chaincode file and I also added the testing script that you can run section by section against the smart contract. I pushed them to my branch if you want to take a look.

kalleknast commented 5 years ago

Thanks! I'll get to it next week.

rakeshjha2k6 commented 4 years ago

Hi Team , I am using Hyperledger Fabric Sdk , Balance Transfer 1.4 getiing the below issue , when adding "org3 " in network as :-- [2019-10-19 17:52:24.159] [ERROR] Helper - Failed to get registered user: Jim_003 with error: Error: fabric-ca request register failed with errors [[{"code":0,"message":"Registration of 'Jim_003' failed in affiliation validation: Failed getting affiliation 'org3.department1': : scode: 404, code: 63, msg: Failed to get Affiliation: sql: no rows in result set"}]]

Kindly help me how i can fix this issue .

xuxucode commented 4 years ago

@rakeshjha2k6

affiliations are hardcoded in /etc/hyperledger/fabric-ca-server/fabric-ca-server-config.yaml:

affiliations:
   org1:
      - department1
      - department2
   org2:
      - department1

You need to provide your own customized config file instead of the auto-generated one.