[英]calling google cloud functions from java spring boot application
I'm using google cloud functions with no problem in my mobile app using specific sdk for iOS and swift.我在我的移动应用程序中使用谷歌云功能没有问题,使用特定的 sdk for iOS 和 swift。 For integrations reason I would now need to call one of my functions from a java springboot server.出于集成原因,我现在需要从 java springboot 服务器调用我的函数之一。
I cannot find any example for that, does a specific client and example exist ?我找不到任何示例,是否存在特定的客户和示例?
I can find examples for other platform but not for java.我可以找到其他平台的示例,但不能找到 java。 Am I missing something ?我错过了什么吗? can someone move me in the right direction ?有人可以让我朝着正确的方向前进吗?
Thanks谢谢
You could simply do HTTP requests, that will trigger the cloud functions.您可以简单地执行 HTTP 请求,这将触发云功能。 Here is the documentation这是文档
GCP hasdocumentation regarding the authentication on Cloud Functions. GCP 有关于 Cloud Functions 身份验证的文档。 Since you need to authenticate on a Cloud Function from a VM inside your GCP project, I recommend you to read this section .由于您需要在 GCP 项目内的 VM 上对 Cloud Function 进行身份验证,因此我建议您阅读本部分。
As explained, you should get an Identity Token that can authenticate on Cloud Functions.如前所述,您应该获得可以在 Cloud Functions 上进行身份验证的身份令牌。 You can fetch the token either from gcloud
or the metadata server .您可以从gcloud
或元数据服务器获取令牌。 After you have that in whatever format you can access it without compromising your credentials (eg environment variable, file outside the repository) just perform the HTTP request to the trigger of the function.在您以任何格式访问它之后,您就可以在不影响您的凭据(例如环境变量、存储库外的文件)的情况下访问它,只需执行对函数触发器的 HTTP 请求即可。
In the end you should have something like this:最后你应该有这样的东西:
cf_trigger = "https://<region>-<project_id>.cloudfunctions.net/<function_name>"
identity_token = "foo"
HttpRequest.newBuilder()
.uri(URI.create(cf_trigger))
.header("Authorization", "bearer " + identity_token)
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.