0

I'm trying to create a cloud function which includes certificate file in nodejs. Below is the code which I'm trying to execute:

    exports.invoke = async function(req, res) {

     const walletPath = path.join(process.cwd(), './wallet');
        const wallet = new FileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);

        // Check to see if we've already enrolled the user.
        const userExists = await wallet.exists('user1');
      console.log(userExists);
        if (!userExists) {
            console.log('An identity for the user "user1" does not exist in the wallet');
            console.log('Run the registerUser.js application before retrying');
            return;
        }
    }

Cloud function not able to read the certificate which is in the wallet folder.

Thanks in advance.

Pedro Mutter
  • 1,178
  • 1
  • 13
  • 18
Jax
  • 139
  • 2
  • 12
  • It is hard to understand why the method can't read certificates without knowing how it works. The paths seem to be set correctly. If `wallet` is a folder may be the trailing slash is needed `./wallet/`? – Emil Gi Mar 30 '20 at 09:05

2 Answers2

0

So you are trying to make your Cloud Function take HTTP(s) requests of another service using a custom certificate (correct me if I am wrong).

To do this you need first to make the certificate available to your Cloud Function code as an authentication secret. You can check the following link on how to achieve this.

But in general there are several options for getting the certificate files into the Cloud Function:

  • Upload on deploy (you can include the certificate files for your Google Cloud Function deployment by including them into your code directory as seen here)
  • Upload to Google Cloud Storage (this approach, you upload the certificate files to a Cloud Storage bucket, then load the file when your function instance starts up)
  • Load into an Environment Variable (if the size of your certificate data can fit into a variable, this is also a good option, but has some security risks.

And one of the most secure practices is facilitated by this tool.

I would suggest you trying one of these options since it seems it cannot read it from the wallet folder it might be because it cannot read it at the moment the function is created.

Would also be helpful if you would add the errors you are receiving in order to see what it is the actual problem.

Stefan Neacsu
  • 653
  • 3
  • 12
  • I have included certs in the code directory only. userExists always returning false. – Jax Mar 24 '20 at 12:35
0

I have used google bucket to store fabric certs and included in google cloud function which is working fine. Also as an alternative ibm has given some sample programs for fabric on serverless cloud function.

Jax
  • 139
  • 2
  • 12