Right now I don't managed to have the Google Cloud Platform Data Loss Prevention (DLP) client library for python working behind a SSL proxy (it works fine with other GCP client lib for example for storage or bigquery): https://cloud.google.com/dlp/docs/libraries#client-libraries-usage-python
So I tried to use request.post
to use the API behind a SSL proxy
url = 'https://dlp.googleapis.com/v2/projects/'+os.environ['PROJECT_ID']+'/content:inspect'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {}'.format(subprocess.run('gcloud auth print-access-token', shell=True, check=True, stdout=subprocess.PIPE).stdout.decode().replace('\n', '').replace('\r', ''))
}
}
json_response = requests.post(url=url, json=parsed, headers=headers, proxies=proxies, verify=True)
json.loads(json_response.text)
This is working fine on CloudShell
but not on my local machine where SDK
is installed. The reason is that on CloudShell
:
gcloud auth print-access-token
give me the same token for a period of few minutes while on my local machine (Windows or Mac), every time I execute the command, I got a new token. On my local machine if I replace in the header the gcloud command by the token from CloudShell
it works fine. I have the latest version of SDK
on both my local machine and on CloudShell
.
question 1: it is expected that every time we run gcloud auth print-access-token
locally (SDK
), we get a new token ? (On CloudShell
it is the same token for a period of few minutes)
question 2: what is the easiest/best way to generate a token ? since gcloud auth print-access-token
doesn't seems the right way to do it when using local machine and SDK
. This is not a productive application. This is just to test the DLP API.