简体   繁体   English

如何获取谷歌用户凭据

[英]how to obtain google user credentials

i need to obtain google user credentials using gcloud cli command and gcloud sdk.我需要使用 gcloud cli 命令和 gcloud sdk 获取 google 用户凭据。

obtain google user credentials process which includes ->获取 google 用户凭据过程,其中包括 ->

  1. creating new project.创建新项目。
  2. Enabling api and services启用 api 和服务
  3. Selecting services(Ex: Cloud vision api,Maps)选择服务(例如:Cloud vision api、Maps)
  4. Creating Service Account and assigning ownership.创建服务帐户并分配所有权。
  5. Creating Credentials (Json)创建凭证 (Json)

I need to implement above process using script.我需要使用脚本来实现上述过程。 -please help me if anyone knows documentation or any tutorial link for above process. - 如果有人知道上述过程的文档或任何教程链接,请帮助我。

It's considered bad form to ask questions without including details of an attempt to solve the problem for yourself.在不包括尝试为自己解决问题的细节的情况下提出问题被认为是一种不好的形式。 I'm assuming good faith and that you're genuinely unable to find documentation for this.我假设你是真诚的,你真的无法找到这方面的文件。 Your question is more about writing shell scripts than a specific issue with gcloud .您的问题更多是关于编写 shell 脚本,而不是gcloud的特定问题。

If you're using bash something of the form:如果您使用 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Google Cloud Run 上获取 GCP 服务帐户凭据? - How Can I Obtain GCP service account credentials on Google Cloud Run? 在 myaccount.google.com/permissions 撤销权限后如何从“不可用的凭据无法获取元数据”中恢复 - How to recover from “Unavailable credentials failed to obtain metadata” after revoking permissions at myaccount.google.com/permissions 临时容器内的用户 Google Cloud 凭据? - User Google Cloud credentials inside ephemeral container? Google Identity Service - 如何从经过身份验证的用户获取配置文件/Email 信息 - Google Identity Service - How Obtain Profile / Email Information From Authenticated user 在 Cloud Functions 中获取服务帐户凭据以在 GCP 之外调用 google 服务 - Obtain a service account credentials within a Cloud Functions to call a google service outside GCP flutter,获取访问凭证失败 - flutter, failed to obtain access credentials 是否可以识别其凭据用于调用Google Cloud API的用户? - Is it possible to identify the user whose credentials are used to call the Google Cloud API? Google Cloud Storage:为每个对象授予用户/传递凭据 - Google Cloud Storage: Grant User / Pass credentials per object 如何避免使用GOOGLE_APPLICATION_CREDENTIALS - How to avoid using GOOGLE_APPLICATION_CREDENTIALS 如何在 Rails 中设置 Google 应用程序凭据 - How to set Google application credentials in Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM