Sign inSign up

aligor/cloud-functions-proxy

By aligor

Updated over 5 years ago

Image
0

320

aligor/cloud-functions-proxy repository overview

cloud-functions-proxy

Install

go get -d -v ./...

Optional if you want to run app with docker.

Run

# With go 1.15
go run .
# You can also use docker
make run

You can check it here: http://localhost:8080/up

Quick call

Without service account
GCP_PROJECT=#Google project ID
GCP_FUNCTIONS_REGION=#Cloud functions region
GCP_TOKEN=$(gcloud auth print-identity-token) #OIDC token
CLOUD_FUNCTION=#Cloud function's path
curl "localhost:8080/api/$CLOUD_FUNCTION" -H "GCP_PROJECT: $GCP_PROJECT" -H "GCP_FUNCTIONS_REGION: $GCP_FUNCTIONS_REGION" -H "GCP_TOKEN: $GCP_TOKEN"
With service account
export GOOGLE_APPLICATION_CREDENTIALS="PATH_TO_CREDENTIALS"
GCP_PROJECT=#Google project ID
GCP_FUNCTIONS_REGION=#Cloud functions region
CLOUD_FUNCTION=#Cloud function's path
curl "localhost:8080/api/$CLOUD_FUNCTION" -H "GCP_PROJECT: $GCP_PROJECT" -H "GCP_FUNCTIONS_REGION: $GCP_FUNCTIONS_REGION"

Build

You can build the docker image:

make build

Or a go binary:

env GOOS=target-OS GOARCH=target-architecture go build .

Functionnalities

Endpoint /up

Simple call to test if application is ready.

Response codeResponse body
200Up
Endpoint /kill

This call can be use to stop the application.

Response codeResponse body
200Killed
Endpoint /api

This is the base endpoint to use proxy call.

To target a Google Cloud Function with a path like /my-function, you have to call /api/my-function of this proxy.

In order to specify which audience you want to call, you need to set these variables:

VariableDescription
GCP_PROJECTGoogle project ID
GCP_FUNCTIONS_REGIONCloud functions region

There is 2 ways to set it.

  1. In an environment variable with the same name.
  2. In a header of the request call with the same name. (Override the first way).

Now to authenticate your calls, there is 2 ways again:

  1. With GCP_TOKEN set in request's header with an OIDC token which identify an account/user with cloudfunctions.functions.invoke permission.
  2. With a service account:
    Set GOOGLE_APPLICATION_CREDENTIALS environement variable to target path to json/p12 credentials file of the service account with cloudfunctions.functions.invoke permission. This cannot be overriden by the first way.
Response codeResponse body
200The response body of the cloud function target if everythings is good.
400Error: GCP_PROJECT and GCP_FUNCTIONS_REGION are required when missing GCP_PROJECT or GCP_FUNCTIONS_REGION
500If GOOGLE_APPLICATION_CREDENTIALS is set and an error becomes when trying to use it. The body contains the error thrown away.
*If a response is received from cloud function, code and body is generaly set to the applicaton response

Tag summary

Content type

Image

Digest

Size

15.6 MB

Last updated

over 5 years ago

docker pull aligor/cloud-functions-proxy