【发布时间】:2021-12-29 10:59:48
【问题描述】:
我有一个使用骆驼从对象存储(谷歌云平台)获取数据的 Spring Boot 应用程序。
这是我在 Eclipse 中的代码:
package footballRestAPIs;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
import core.ErrorProcessor;
@Component
public class ListObjFromGCP extends RouteBuilder{
@Override
public void configure() throws Exception {
onException(Exception.class).handled(true)
.process(new ErrorProcessor());
rest("/").produces("application.json")
.get("selectPhoto")
.to("direct:selectPhoto");
from("direct:selectPhoto")
.to("google-storage://sagessapp_test?operation=listObjects")
.log("${body}");
}
}
这是 application.properties 文件,其中服务帐户密钥的路径是:
spring.cloud.gcp.credentials.location=/Users/User/Downloads/gcp-credentials.json
当我运行 spring boot 应用程序时,我收到以下错误:
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
GET https://storage.googleapis.com/storage/v1/b/sagessapp_test?projection=full
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Anonymous caller does not have storage.buckets.get access to the Google Cloud Storage bucket.",
"reason" : "required"
} ],
"message" : "Anonymous caller does not have storage.buckets.get access to the Google Cloud Storage bucket."
}
是否有其他方法可以提供服务帐户密钥的路径,或者存在其他问题。谢谢!
【问题讨论】:
-
您是否在工作站上运行代码?您是否通过
gcloud auth application-default login进行了身份验证?您是否设置了 GOOGLE_APPLICATION_CREDENTIALS 环境变量?您如何管理运行时环境的身份验证? -
您有机会查看我的answer吗?
标签: java spring-boot google-cloud-platform apache-camel cloud-object-storage