go get -d -v ./...
Optional if you want to run app with docker.
# With go 1.15
go run .
# You can also use docker
make run
You can check it here: http://localhost:8080/up
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"
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"
You can build the docker image:
make build
Or a go binary:
env GOOS=target-OS GOARCH=target-architecture go build .
/upSimple call to test if application is ready.
| Response code | Response body |
|---|---|
200 | Up |
/killThis call can be use to stop the application.
| Response code | Response body |
|---|---|
200 | Killed |
/apiThis 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:
| Variable | Description |
|---|---|
| GCP_PROJECT | Google project ID |
| GCP_FUNCTIONS_REGION | Cloud functions region |
There is 2 ways to set it.
Now to authenticate your calls, there is 2 ways again:
GCP_TOKEN set in request's header with an OIDC token which identify an account/user with cloudfunctions.functions.invoke permission.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 code | Response body |
|---|---|
200 | The response body of the cloud function target if everythings is good. |
400 | Error: GCP_PROJECT and GCP_FUNCTIONS_REGION are required when missing GCP_PROJECT or GCP_FUNCTIONS_REGION |
500 | If 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 |
Content type
Image
Digest
Size
15.6 MB
Last updated
over 5 years ago
docker pull aligor/cloud-functions-proxy