查看项目(node js)启用了哪些GCP服务?
See what GCP services are enabled for a project (node js)?
根据 documentation, with the gcloud
cli if you run gcloud services list --available
you can get a list of the services that are enabled or available to be enabled for a google cloud project. What is the equivalent library/call to use to do this in node? I've taken a look at the libs listed here 并且似乎无法找到如何执行此操作。
我正在使用 terraformer,它在节点 js 环境中 运行ning 以编程方式抓取帐户,但如果您在某个项目中未启用某些服务,它会出错试试 运行 吧。基本上,在我 运行 terraformer
之前,我想获得一个启用了哪些服务的列表,并且只导入这些服务。
Google 云文档非常好,我建议在大多数情况下进行快速 Google 搜索。您可以找到几个您要查找的示例 here。
实际的 http 请求如下所示(此示例未显示如何附加身份验证信息)
curl 'https://serviceusage.googleapis.com/v1/projects/357084163378/services?filter=state:ENABLED'
我建议向此端点提交 Ajax 请求。如果您已经在使用 Google SDK,您应该能够获得一个访问令牌以附加到 api 请求
以防万一其他人好奇:
import { google } from 'googleapis'
const usage = google.serviceusage('v1')
const project = "myProject"
const authorize = async (scopes) => {
const auth = new google.auth.GoogleAuth({ scopes })
return await auth.getClient()
}
const {
data: { services }
} = await usage.services.list({
parent: `projects/${project}`,
filter: 'state:ENABLED',
auth: await authorize(['https://www.googleapis.com/auth/cloud-platform'])
})
根据 documentation, with the gcloud
cli if you run gcloud services list --available
you can get a list of the services that are enabled or available to be enabled for a google cloud project. What is the equivalent library/call to use to do this in node? I've taken a look at the libs listed here 并且似乎无法找到如何执行此操作。
我正在使用 terraformer,它在节点 js 环境中 运行ning 以编程方式抓取帐户,但如果您在某个项目中未启用某些服务,它会出错试试 运行 吧。基本上,在我 运行 terraformer
之前,我想获得一个启用了哪些服务的列表,并且只导入这些服务。
Google 云文档非常好,我建议在大多数情况下进行快速 Google 搜索。您可以找到几个您要查找的示例 here。
实际的 http 请求如下所示(此示例未显示如何附加身份验证信息)
curl 'https://serviceusage.googleapis.com/v1/projects/357084163378/services?filter=state:ENABLED'
我建议向此端点提交 Ajax 请求。如果您已经在使用 Google SDK,您应该能够获得一个访问令牌以附加到 api 请求
以防万一其他人好奇:
import { google } from 'googleapis'
const usage = google.serviceusage('v1')
const project = "myProject"
const authorize = async (scopes) => {
const auth = new google.auth.GoogleAuth({ scopes })
return await auth.getClient()
}
const {
data: { services }
} = await usage.services.list({
parent: `projects/${project}`,
filter: 'state:ENABLED',
auth: await authorize(['https://www.googleapis.com/auth/cloud-platform'])
})