in data-mesh-banking-labs/setup/resources/composer/dags/create_merchant_data_product_dq_job.py [0:0]
def get_session_headers():
"""
This method is to get the session and headers object for authenticating the api requests using credentials.
Args:
Returns: tuple
"""
# getting the credentials and project details for gcp project
credentials, your_project_id = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"])
# getting request object
auth_req = google.auth.transport.requests.Request()
print(credentials.valid) # logger.debugs False
credentials.refresh(auth_req) # refresh token
# cehck for valid credentials
print(credentials.valid) # logger.debugs True
auth_token = credentials.token
print(auth_token)
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + auth_token
}
with requests.Session() as session:
session.auth = OAuth2BearerToken(auth_token)
return (session, headers)