Firebase环境配置-在private_key_id

时间:2018-11-05 20:19:34

标签: firebase google-cloud-functions continuous-deployment service-accounts

目标

我正在更新service_account密钥并将其存储为Firebase环境变量。

错误

运行firebase deploy --only functions时,我看到:

Silver-Sliver:Issy dchaddportwine$ firebase deploy --only functions

=== Deploying to 'development-is'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

Error: Failed to parse private key: Error: Invalid PEM formatted message.

问题

使用firebase functions:config:set更新会在字符串中引入额外的\个字符。这是在将:set应用于private_key_id之后在终端中看到的内容。看到多余的反斜杠,其中\n变成\\n吗?

Silver-Sliver:Issy dchaddportwine$ firebase functions:config:set service_account.private_key_id="-----BEGIN PRIVATE KEY-----\nMIIE...L5A==\n-----END PRIVATE KEY-----\n"
✔  Functions config updated.

Please deploy your functions for the change to take effect by running firebase deploy --only functions

Silver-Sliver:Issy dchaddportwine$ firebase functions:config:get
{
  "service_account": {
    "private_key_id": "-----BEGIN PRIVATE KEY-----\\nMIIE...L5A==\\n-----END PRIVATE KEY-----\\n",

问题

这是添加一个大大的错误,还是我自己的用户错误。我应该以其他方式更新private_key_id吗?我该如何解决?

2 个答案:

答案 0 :(得分:1)

TLDR :将密钥的值括在单引号中,并以>>> pd.RangeIndex(0, 7).difference(df.index) Int64Index([1, 6], dtype='int64') 作为前缀进行特殊处理。

假设1

换行是由Shell程序完成的。

测试1

创建一个脚本,以记录在外壳程序中解析的参数。

$

运行

> echo "console.log(process.argv)" > shell-args.js

假设2

串联并打印文件作为输入,使shell参数保持原样。

> node shell-args.js x="Always\nEscape"

[ '/Users/alẹ́tilẹ́/.nvm/versions/node/v9.10.1/bin/node',
  '/Users/alẹ́tilẹ́/Tests/shell-args.js',
  'x=Always\\nEscape' ]

测试2

运行

echo "Always\nEscape" > always_escape

> node shell-args.js x="$(< always_escape)"

假设3

使用ANSI C扩展时,换行符会得到特殊处理。

> node shell-args.js x="`< always_escape`" [ '/Users/alẹ́tilẹ́/.nvm/versions/node/v9.10.1/bin/node', '/Users/alẹ́tilẹ́/Tests/shell-args.js', 'x=Always\nEscape' ]

  

$'string'形式的单词经过特殊处理。这个词扩展为      字符串,其中反斜杠转义字符由       ANSI C标准... 展开的结果用单引号引起来,就像没有美元符号一样。

测试3

运行

man bash

结论

将键值括在单引号中,并以> node shell-args.js x=$'Always\nEscape' [ '/Users/alẹ́tilẹ́/.nvm/versions/node/v9.10.1/bin/node', '/Users/alẹ́tilẹ́/Tests/shell-args.js', 'x=Always\nEscape' ] 作为前缀以进行特殊处理。

答案 1 :(得分:0)

有一个 bug in the Firebase CLI(自 2017 年以来开放)导致它在函数配置变量中双重转义换行符。

最简单的解决方法是在访问配置变量时简单地替换它们:

const doubleEscapedValue = functions.config().service_account.private_key_id;
const correctResult = value.replace(/\\n/g, '\n');
相关问题