Configure firebase functions to use a service account for deploying.

huangapple go评论67阅读模式
英文:

Configure firebase functions to use a service account for deploying

问题

以下是您要翻译的内容:

在查看云函数文档时,它显示了一种使用服务账号部署函数的选项,而不是让它在默认服务账号下运行:

gcloud functions deploy <function> --service-account <service_account_email>

在运行 firebase deploy 时,Firebase 是否有一种配置以使用服务账号部署函数的方法?

我尝试了直接将其添加到 .firebaserc 文件的简单方法,但我不知道是否支持或正确的语法是什么:

{
  "projects": {
    "default": "<project>"
  },
  "targets": {
    "<project>": {
      "functions": {
        "service-account": "<...>@<project>.iam.gserviceaccount.com"
      }
    }
  }
}
英文:

When looking at the docs for cloud functions it shows an option to deploy the function using a service account instead of having it run with the default service account:

gcloud functions deploy &lt;function&gt; --service-account &lt;service_account_email&gt;

Is there is a way in firebase to configure it to deploy a function using a service account when running firebase deploy?

I've tried doing a straight-forward dumb approach of adding it to the .firebaserc file, but I don't know if that is supported or what the correct syntax would be:

{
  &quot;projects&quot;: {
    &quot;default&quot;: &quot;&lt;project&gt;&quot;
  },
  &quot;targets&quot;: {
    &quot;&lt;project&gt;&quot;: {
      &quot;functions&quot;: {
        &quot;service-account&quot;: &quot;&lt;...&gt;@&lt;project&gt;.iam.gserviceaccount.com&quot;
      },
  }
}

答案1

得分: 1

你可以使用RunTime options interface更改Firebase函数部署的服务帐户。例如:

import * as functions from "firebase-functions";

export const myfunc = functions.runWith({serviceAccount:"sa@goog.com"}).https.onCall(async (request, context) => {
}

当您在不添加任何额外参数的情况下使用Firebase CLI 时,该函数应该使用指定的服务帐户进行部署。

firebase deploy --only functions:myfunc

如果操作正确,您将看到函数详细信息部分的服务帐户已更改为指定的服务帐户。

英文:

You can change the service account the firebase function is deployed with using the RunTime options interface. For example:

import * as functions from &quot;firebase-functions&quot;;

export const myfunc = functions.runWith({serviceAccount:&quot;sa@goog.com&quot;}).https.onCall(async (request, context) =&gt; {
}

When you use the firebase cli without any additional parameters, the function should be deployed with the specified service account.

firebase deploy --only functions:myfunc

If done correctly, you will see that the Service Account in the details section of the function is changed to the specified service account.

huangapple
  • 本文由 发表于 2023年5月10日 12:52:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定