如何在 google 云函数中加载结构客户端证书?
How to load fabric client certs in google cloud function?
我正在尝试在 nodejs 中创建一个包含证书文件的云函数。下面是我要执行的代码:
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 Functions 使用自定义证书接受其他服务的 HTTP(s) 请求(如果我错了请纠正我)。
为此,您首先需要将证书作为身份验证密码提供给您的 Cloud Function 代码。您可以查看以下 如何实现此目的。
但一般来说,将证书文件导入 Cloud Function 有几种选择:
- 部署时上传(您可以将 Google Cloud Function 部署的证书文件包含到您的代码目录中,如此处所示)
- 上传到 Google 云存储(这种方法,您将证书文件上传到云存储桶,然后在函数实例启动时加载文件)
- 加载到一个环境变量中(如果你的证书数据的大小可以放入一个变量中,这也是一个不错的选择,但有一些安全风险。
最安全的做法之一是通过此 tool 促进的。
我建议您尝试这些选项之一,因为它似乎无法从钱包文件夹中读取它,这可能是因为它在创建函数时无法读取它。
如果您添加收到的错误以查看实际问题是什么,也会有所帮助。
我已经使用 google 存储桶来存储结构证书并包含在 google 云功能中,该功能运行良好。此外,作为替代方案,IBM 还为无服务器云功能上的结构提供了一些示例程序。
我正在尝试在 nodejs 中创建一个包含证书文件的云函数。下面是我要执行的代码:
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 Functions 使用自定义证书接受其他服务的 HTTP(s) 请求(如果我错了请纠正我)。
为此,您首先需要将证书作为身份验证密码提供给您的 Cloud Function 代码。您可以查看以下
但一般来说,将证书文件导入 Cloud Function 有几种选择:
- 部署时上传(您可以将 Google Cloud Function 部署的证书文件包含到您的代码目录中,如此处所示)
- 上传到 Google 云存储(这种方法,您将证书文件上传到云存储桶,然后在函数实例启动时加载文件)
- 加载到一个环境变量中(如果你的证书数据的大小可以放入一个变量中,这也是一个不错的选择,但有一些安全风险。
最安全的做法之一是通过此 tool 促进的。
我建议您尝试这些选项之一,因为它似乎无法从钱包文件夹中读取它,这可能是因为它在创建函数时无法读取它。
如果您添加收到的错误以查看实际问题是什么,也会有所帮助。
我已经使用 google 存储桶来存储结构证书并包含在 google 云功能中,该功能运行良好。此外,作为替代方案,IBM 还为无服务器云功能上的结构提供了一些示例程序。