我需要通过gcloud cli命令和gcloud sdk获取Google用户凭证。
获取Google用户凭证过程,包括->
- 创建新项目
- 启用api和服务
- 选择服务(例如:云视觉api,地图)
- 创建服务帐户并分配所有权。
- 创建凭证(Json)
我需要使用脚本实现上述过程。-如果有人知道上述过程的文档或教程链接,请帮助我。
在提出问题时不包括试图自己解决问题的细节被认为是不礼貌的。我假设你是真诚的,而且你真的找不到这方面的文件。你的问题更多是关于编写shell脚本,而不是gcloud
的特定问题。
如果你正在使用bash,格式为:
# Variables
BILLING=[YOUR-BILLING-ID]
PROJECT=[YOUR-PROJECT-ID]
SERVICES=(
"vision"
...
)
ACCOUNT=[YOUR-ACCOUNT-NAME]
# See: https://cloud.google.com/iam/docs/understanding-roles
ROLE=[GOOGLE-IAM-ROLE]
# Create Google Cloud Project
gcloud projects create ${PROJECT}
# Link the Project with a Billing Account
gcloud beta billing projects link ${PROJECT}
--billing-account=${BILLING}
# Enable Google services
for SERVICE in "${SERVICES[@]}"
do
gcloud services enable ${SERVICE}.googleapis.com
--project=${PROJECT}
done
# Create a Service Account
gcloud iam service-accounts create ${ACCOUNT}
--project=${PROJECT}
EMAIL=${ACCOUNT}@${PROJECT}.iam.gserviceaccount.com
# Create a Service Account Key
# This is generally discouraged as Keys increase security risk
gcloud iam service-accounts keys create ${PWD}/${ACCOUNT}.json
--project=${PROJECT}
# Revise the Project's (!) IAM policy
# Permit the Service Account
# To use the Role
gcloud projects add-iam-policy-binding ${PROJECT}
--role=${ROLE}
--member=serviceAccount:${EMAIL}
# Optional: Application Default Credentials
export GOOGLE_APPLICATION_CREDENTIALS=${PWD}/${ACCOUNT}.json