Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add Service Account
Browse files Browse the repository at this point in the history
  • Loading branch information
Sina Jalali authored and Sina Jalali committed Dec 22, 2023
1 parent a843c4d commit c79ef4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion api/procurement_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import requests
from backoff import on_exception, expo
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from ratelimit import limits, RateLimitException
Expand All @@ -21,7 +22,11 @@ class ProcurementApi(object):
"""Utilities for interacting with the Procurement API."""

def __init__(self, project_id):
self.service = build(PROCUREMENT_API, "v1", cache_discovery=False)
if settings.use_service_account:
credentials = service_account.Credentials.from_service_account_file('service-account.json', scopes=[])
self.service = build(PROCUREMENT_API, "v1", cache_discovery=False, credentials=credentials)
else:
self.service = build(PROCUREMENT_API, "v1", cache_discovery=False)
self.project_id = project_id

##########################
Expand Down
7 changes: 5 additions & 2 deletions api/services_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class ServicesApi(object):
"""Utilities for interacting with the Services API."""

def __init__(self, project_id):
credentials = service_account.Credentials.from_service_account_file('service-account.json', scopes=[])
self.service = build(SERVICES_API, "v1", cache_discovery=False, credentials=credentials)
if settings.use_service_account:
credentials = service_account.Credentials.from_service_account_file('service-account.json', scopes=[])
self.service = build(SERVICES_API, "v1", cache_discovery=False, credentials=credentials)
else:
self.service = build(SERVICES_API, "v1", cache_discovery=False)
self.project_id = project_id

@on_exception(expo, RateLimitException, max_tries=8)
Expand Down

0 comments on commit c79ef4e

Please sign in to comment.