简体   繁体   中英

What is the Correct Way to Use Secret Manager in Firebase Cloud Function?

I started to add Secret Manager with a SECRET_NAME contains a certain password inside Cloud Function using Node.js. I tried both ways. First, adding Secret Manager using Console and another, adding Secret Manager directly through Firebase CLI. Unfortunately, both ways give an empty Secret value in Cloud Function variable of Secret as shown in picture below.
图片链接

I used parameter runWith({secret: ["SECRET_NAME"]}) as shown in code below.

 exports.Auth = functions.runWith(secret).https.onCall(async (data, context) => { const response = 129132; return Promise.resolve(response); }); const secret = { timeoutSeconds: 120, memory: "1GB", secret: ["SECRET_NAME"], minInstances: 0, };

I followed the documentation written in Firebase Cloud Function ( https://firebase.google.com/docs/functions/config-env ).

I had wasted almost a week to figure out where I got wrong and found nothing. I also added a role "Secret Manager Secret Accessor" to current SECRET_NAME in Google Cloud Console, and it gave result to nothing at all. As written in this stackoverflow post reference

My question is should I add SECRET_NAME manually in Cloud Function Console in Google Cloud Platform? If so, then what is the use of documentation written above? Is Firebase trying to lead us to nowhere?

I am sorry guys.
Apparently, I was wrong in writing the code:

 const secret = { timeoutSeconds: 120, memory: "1GB", secrets: ["SECRET_NAME"], //Must use secrets not secret minInstances: 0, };
在此处输入图像描述

Thank you, @MichaelBleigh.
Problem is now solved.

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