function

package module
v0.0.0-...-83bad3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 15 Imported by: 0

README

GCP Storage Proxy function

This Google Cloud Function acts as a proxy to list and download Google Storage Bucket objects.

Usage

List objects in a bucket

curl  -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
https://functionid.a.run.app/info?bucket=<bucket_name>

Download a file from a bucket

curl  -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
https://functionid.a.run.app/download?bucket=<bucket_name>&filename=<file_name>

To call the function using custom authentication, fill the apikey query parameter with your API key stored in Firebase.

curl https://functionid.a.run.app/download?bucket=<bucket_name>&filename=<file_name>&apikey=<api_key>

Deploy

Google Cloud CLI (gcloud) is required for deployment with the following command. Otherwise the function can be deployed from Google Cloud Console as well (requires manual source code copying).

gcloud functions deploy gcp-storage-proxy --trigger-http --gen2 --runtime go119 \
--region=europe-west1 --source . --entry-point Handler

Custom authentication via Firebase/Firestore is also supported. To use custom auth instead of native GCP authentication, deploy the function as follows

gcloud functions deploy gcp-storage-proxy --set-env-vars AUTH_ENABLED=true,PROJECT_ID=<your_project_id> --allow-unauthenticated --trigger-http --gen2 --runtime go119 --region=europe-west1 --source . --entry-point Handler

Local testing

WARNING: This doesn't seem to work on Windows systems

For interacting with storage buckets locally, you need to be authenticated to GCP - either via gcloud CLI or a credentials file (found in $HOME/.config/gcloud/application_default_credentials.json).

git clone https://github.com/Loupeznik/gcp-storage-proxy
cd gcp-storage-proxy

export FUNCTION_TARGET=Handler
go run cmd/main.go

curl http://localhost:8080/info?bucket=<bucket_name>

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL