mintel / gcp-quota-exporter

Exports quota limits and usage for Google Compute Platform services
MIT License
7 stars 14 forks source link

When GCP Project is missing, read the value from the credentials file #5

Closed dmyerscough closed 4 years ago

dmyerscough commented 4 years ago

The service account key that is generated contains the GCP Project ID.

{
  "type": "service_account",
  "project_id": "XXXXXX",
  "private_key_id": "33652c67047c066bdc54ccae86b9b13ff665456a",
  "private_key": "-----BEGIN PRIVATE KEY-----\n",
  "client_email": "gcp-quota-exporter@XXXXXX.iam.gserviceaccount.com",
  "client_id": "117480266972970317496",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gcp-quota-exporter%XXXXX.iam.gserviceaccount.com"
}

With this patch, you can just provide the service account file, but still, override the project ID:-

$ ./gcp-quota-exporter --gcp.credentials-path=service-account-gcp-quota-exporter.json
INFO[0000] Starting gcp_quota_exporter (version=, branch=, revision=)  source="main.go:123"
INFO[0000] Build context (go=go1.14.1, user=, date=)     source="main.go:124"
INFO[0001] Listening on :9592                            source="main.go:154"
INFO[0001] GCP Project:  XXXXXX          source="main.go:155"
primeroz commented 4 years ago

@dmyerscough thanks for the contribution.

Unfortunately it came just at the time i needed to change the code a bit to get support for Workload Identity and so your code does not cleanly merge anymore ... and will require some changes

see https://github.com/mintel/gcp-quota-exporter/pull/6

This will shortly go in release 0.3.0

In particular now

If you still need this option of getting it from the credentials.json file maybe you can update your code and check if the env var is set and then extract the project_id from the location of the file ?

thanks!

dmyerscough commented 4 years ago

I just updated the PR #7