简体   繁体   English

App Engine 项目访问谷歌云存储的默认凭据?

[英]Default credential for app engine project accessing google cloud storage?

I have an app engine project, I want to access my google cloud storage default bucket.我有一个应用程序引擎项目,我想访问我的谷歌云存储默认存储桶。 The first step of getting a Credential object fails, doing the following on a live instance:获取凭证 object 的第一步失败,在实时实例上执行以下操作:

Credential creds = GoogleCredential.getApplicationDefault();

The exception message I get:我收到的异常消息:

"The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information." “应用程序默认凭据不可用。如果在 Google Compute Engine 中运行,则它们可用。否则,环境变量 GOOGLE_APPLICATION_CREDENTIALS 必须定义为指向定义凭据的文件。请参阅https://developers.google.com/accounts/docs /application-default-credentials了解更多信息。”

The doc here says that production app engine projects should have access to the default credentials?:此处的文档说生产应用程序引擎项目应该有权访问默认凭据?:

https://developers.google.com/identity/protocols/application-default-credentials https://developers.google.com/identity/protocols/application-default-credentials

"3. If you are running in Google App Engine production, the built-in service account associated with the application will be used." “3. 如果您在 Google App Engine 生产环境中运行,将使用与该应用程序关联的内置服务帐户。”

Is there some setup I'm missing?我缺少一些设置吗?

My app engine version (gradle):我的应用引擎版本(gradle):

com.google.appengine:appengine-java-sdk:1.9.18

and google cloud storage lib version:和谷歌云存储库版本:

com.google.apis:google-api-services-storage:v1-rev35-1.20.0

Thanks谢谢

Go to Google Developers Console -> Credentials and create a default service account .json key. 转到Google Developers Console - >凭据并创建默认服务帐户.json密钥。 When you do that, it will download a file like default-account-credentials.json for you. 当你这样做时,它会为你下载一个像default-account-credentials.json这样的文件。 You must then put that file somewhere in your app engine project. 然后,您必须将该文件放在app引擎项目中的某个位置。 This file will be referenced when you call 您致电时将引用此文件

Credential creds = GoogleCredential.getApplicationDefault();

However, before that works you must set the environmental variable to that files location. 但是,在此之前,您必须将环境变量设置为该文件位置。 To do that open up your appengine-web.xml file and put this line into it: 为此,打开你的appengine-web.xml文件并将这一行放入其中:

<env-variables>
            <env-var name="GOOGLE_APPLICATION_CREDENTIALS"
                value="WEB-INF/default-account-credentials.json" />
        </env-variables>

Where value is the path to your .json creds file you just downloaded. 其中value是您刚刚下载的.json creds文件的路径。

Now it will work. 现在它会起作用。 (your gradle imports are fine) (你的gradle进口很好)

I am posting this solution to help others like me who still need help with this error.我发布这个解决方案是为了帮助像我这样仍然需要帮助解决这个错误的人。 Install gcloud on your system, select the project you want to use in the gcloud window, and then authenticate yourself using this command in the gcloud window: "gcloud auth application-default login" to generate a file called application_default_credentials.json.在你的系统上安装gcloud,select你要在gcloud window中使用的项目,然后在gcloud window中使用这个命令验证自己: “gcloud auth application-default login”生成一个名为application_default_credentials.json的文件。 Your program running on the same system will then use this file automatically for authentication.在同一系统上运行的程序将自动使用此文件进行身份验证。 Follow this link to install gcloud: https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=en_GB按照此链接安装 gcloud: https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=en_GB

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

相关问题 APP Engine Google Cloud Storage - 下载文件时出现错误 500 - APP Engine Google Cloud Storage - Error 500 when downloading a file google cloud app engine 是否支持 tomcats 默认 200 个线程? - Does google cloud app engine support tomcats default 200 threads? 提供来自 Google Cloud Storage 的 static SPA 和来自 Google App Engine 的 API - Serve static SPA from Google Cloud Storage and API from Google App Engine 无需下载即可访问 Google Cloud Storage 中的数据 - Accessing data in Google Cloud Storage without downloading it Google Cloud Run 的默认存储空间是多少? - What's the default storage for Google Cloud Run? Quarkus 部署到 Google Cloud App 引擎失败 - Quarkus deployment to Google Cloud App engine fails Google Cloud App Engine 中的 Angular 7 路由不起作用 - Angular 7 Routing in Google Cloud App Engine not working Spring 在 Google Cloud App Engine 上启动托管 - Spring Boot hosting on Google Cloud App Engine 删除 Google Cloud Storage (GCS) 上的所有用户默认 acl - Removing allUsers default acl on Google Cloud Storage (GCS) 在我不属于的项目中访问谷歌云存储 object - Access Google Cloud Storage object in a project that I don't belong to
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM