Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Blockchain by (16.8k points)

I'm working on a proof of concept for blockchain. I've am using bluemix network for blockchain and deploying my application, which I develop locally. I want to test the CA functionalities and want to add users with attributes to the membersrvs.yaml, and perform Attribute Based Access control. However, I'm not able to find out how can I edit/update the file while my network is hosted on bluemix. Pardon me if this seems very basic, I'm still getting a hang on things. 

1 Answer

0 votes
by (14.4k points)

Though you cannot edit or customize membersrvs.yaml that is inherently present in the IBM Bluemix Blockchain Service, you can add users through API. However, REST APIs cannot be used. Therefore, you may use gRPC via HFC SDK.

I will tell you how to do that exactly. Before moving on to the code, let us consider some assumptions:
1. A new user is registered in the new membership service for IBM Bluemix Blockchain.
2. @param enrollment_ID - This is the name of the user which is to be registered.
3. @param callback - This is the call back of the form: function(error, user_credentials)

module.exports.registerUser = function (enrollment_ID, callback) {

    console.log(TAG, 'registerUser() called');

    if (!chain) {

        cb(new Error('Cannot register a user before setup() is called.'));

        return;

    }

    chain.getMember(enrollment_ID, function (err, usr) {

        if (!usr.isRegistered()) {

            console.log(TAG, 'Sending registration request for:', enrollment_ID);

            var registrationRequest = {

                enrollmentID: enrollment_ID,

                affiliation: 'group1'

            };

            usr.register(registrationRequest, function (err, enrollSecret) {

                if (err) {

                    callback(err);

                } else {

                    var credential = {

                        id: enrollID,

                        secret: enrollSecret

                    };

                    console.log(TAG, 'Registration request completed >successfully!');

                    callback(null, credential);

                }

           });

        } else {

            callback(new Error('Cannot register an existing user'));

        }

    });

};

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...