我希望与 Gmail API 集成,并希望使用具有全网域委托的服务用户来代表 Google Workspaces 中的用户请求数据。我的代码在AWS的EC2中运行。通读文档,最佳实践似乎是使用工作负载身份联合来作为服务用户进行身份验证,这样就不存在密钥泄露的风险。
我已按照Google 网站上的步骤设置与 AWS 的工作负载身份联合,此外,还在 google cloud shell 中运行以下命令:
gcloud iam service-accounts add-iam-policy-binding <service_account_email> \
--role=roles/iam.workloadIdentityUser \
--member="principalSet://iam.googleapis.com/projects/<project_id>/locations/global/workloadIdentityPools/<pool_id>/attribute.aws_role/arn:aws:sts::<aws_account_id>:assumed-role/<aws_role_name>" \
--project <google_cloud_project_name>
Run Code Online (Sandbox Code Playgroud)
我有以下测试应用程序代码:
const { google } = require("googleapis");
const { GoogleAuth } = require("google-auth-library");
const path = require("path");
module.exports = async (req, res) => {
const scopes = [
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/admin.directory.user.readonly",
];
let status = "";
try {
//Inject the client library config as the GOOGLE_APPLICATION_CREDENTIALS
const configPath = path.join(__dirname, "client_library_config.json");
process.env["GOOGLE_APPLICATION_CREDENTIALS"] = …
Run Code Online (Sandbox Code Playgroud) amazon-web-services node.js google-cloud-platform gmail-api workload-identity
我是python的新手,想创建一个具有字典的类,该字典对应于该类中的不同方法。我目前有:
class Test:
functions = {"Test1":test1, "Test2":test2}
def test1(self, arg1):
print "test1"
def test2(self, arg1):
print "test2" + arg1
def call_me(self, arg):
self.functions[arg](arg)
Run Code Online (Sandbox Code Playgroud)
然后在我的main.py中,我有以下内容:
from Test import Test
t = Test()
t.call_me('Test1')
Run Code Online (Sandbox Code Playgroud)
当我调用此函数时,出现错误消息,提示未定义名称test1。谁能告诉我我在做什么错?任何帮助将不胜感激。