Last active
January 29, 2019 06:51
-
-
Save tylertreat/e6e8f1fcd95d29e2f804fbee631bdf4b to your computer and use it in GitHub Desktop.
GCP OIDC proxy send request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global _oidc_token | |
if not _oidc_token or _oidc_token.is_expired(): | |
_oidc_token = _get_google_oidc_token() | |
logging.info('Renewed OIDC bearer token for {}'.format( | |
_adc_credentials.service_account_email)) | |
# Add the Authorization header with the OIDC token. | |
headers['Authorization'] = 'Bearer {}'.format(_oidc_token) | |
# We don't want to forward the Host header. | |
headers.pop('Host', None) | |
request = Request(proxied_request.method, url, | |
headers=headers, | |
data=proxied_request.data) | |
# Send the proxied request. | |
prepped = request.prepare() | |
logging.info('{} {}'.format(prepped.method, prepped.url)) | |
resp = _session.send(prepped) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment