Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google docs credentials #120

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
node_modules
*.mo
dist
Expand Down
4 changes: 2 additions & 2 deletions backend/exporter/gdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.conf import settings
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from google.oauth2.credentials import Credentials
from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError, ResumableUploadError
from googleapiclient.http import MediaFileUpload
Expand All @@ -31,7 +31,7 @@ def __init__(self, main_template_id: str):
# TODO: use default_storage
if os.path.exists(settings.TOKEN_PATH):
with open(settings.TOKEN_PATH) as f:
self.creds = Credentials.from_authorized_user_info(json.load(f))
self.creds = Credentials.from_service_account_info(json.load(f))
self.drive_service = build("drive", "v3", credentials=self.creds, cache_discovery=False)
else:
raise RuntimeError("Unable to find token file")
Expand Down
9 changes: 9 additions & 0 deletions docs/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ Install development dependencies:

npm install

Export to Google Docs
~~~~~~~~~~~~~~~~~~~~~

For exporting to Google Docs, we use a Google `Service Account <https://developers.google.com/workspace/guides/create-credentials?hl=en#service-account/>`__.

For managing that account someone with the admin role can go to the `OCP Google Cloud console <https://console.cloud.google.com/apis/credentials?referrer=search&orgonly=true&project=pelican-289615&supportedpurview=organizationId/>`__.

For a guide on how to create a new account or download the account credentials, you can refer to the `official documentation <https://developers.google.com/workspace/guides/create-credentials?hl=en#service-account/>`__.

.. _development:

Development
Expand Down
6 changes: 6 additions & 0 deletions docs/export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The exported *document* is built from *templates* in Google Docs.

*Tags* are added to templates to generate content within the document.

.. note::

The main template, sub-templates and the export folder must be shared with the
`Service Account <https://developers.google.com/workspace/guides/create-credentials?hl=en#service-account/>`__
[email protected]

Tag syntax
----------

Expand Down