Skip to content

Commit

Permalink
Merge pull request #3703 from webkom/fix-external-sync-google
Browse files Browse the repository at this point in the history
Fix external sync for google
  • Loading branch information
norbye authored Dec 15, 2024
2 parents 2b0c4fd + fe99fa1 commit cf9062e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ENV RELEASE ${RELEASE}

RUN mkdir /app
COPY pyproject.toml /app/pyproject.toml
COPY poetry.lock /app/poetry.lock
WORKDIR /app

RUN pip install poetry
Expand Down
12 changes: 6 additions & 6 deletions lego/apps/external_sync/utils/gsuite.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials

scopes = [
"https://www.googleapis.com/auth/admin.directory.user",
Expand All @@ -24,7 +23,7 @@ def __init__(self):
self.client = build(
"admin",
"directory_v1",
http=credentials.authorize(Http()),
credentials=credentials,
cache_discovery=False,
)

Expand All @@ -35,10 +34,11 @@ def get_credentials(self):
if settings.GSUITE_CREDENTIALS is None:
raise ImproperlyConfigured("Missing GSuite credentials")

credentials = ServiceAccountCredentials.from_json_keyfile_dict(
settings.GSUITE_CREDENTIALS, scopes
return service_account.Credentials.from_service_account_info(
settings.GSUITE_CREDENTIALS,
scopes=scopes,
subject=settings.GSUITE_DELEGATED_ACCOUNT,
)
return credentials.create_delegated(settings.GSUITE_DELEGATED_ACCOUNT)

def get_user(self, user_key):
return self.client.users().get(userKey=user_key).execute()
Expand Down
61 changes: 21 additions & 40 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ beautifulsoup4 = "4.12.2"
bleach = "5.0.1"
requests = "2.32.2"
ldap3 = "2.9.1"
google-api-python-client = "2.96.0"
oauth2client = "4.1.3"
google-api-python-client = "^2.155.0"
google-auth = "^2.37.0"
libthumbor = "2.0.2"
django-health-check = "3.17.0"
djangorestframework = "3.14.0"
Expand Down

0 comments on commit cf9062e

Please sign in to comment.