Skip to content

Commit

Permalink
Merge pull request #52 from antonplagemann/development
Browse files Browse the repository at this point in the history
v4.1.2 Remove OAuth out-of-band (OOB) flow
  • Loading branch information
antonplagemann authored Sep 30, 2022
2 parents f10610c + a10b106 commit 594ca41
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ jobs:
- name: Check out source repository
uses: actions/checkout@v3
- name: Setup Python environment
uses: actions/setup-python@v3
uses: actions/setup-python@v4.1.0
with:
python-version: 3.8
python-version: '3.10'
- name: flake8 Lint
uses: py-actions/flake8@v2
with:
Expand All @@ -95,10 +95,12 @@ jobs:
isort_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Check out source repository
uses: actions/checkout@v3
- name: Setup Python environment
uses: actions/setup-python@v4.1.0
with:
python-version: 3.8
python-version: '3.10'
- uses: isort/isort-action@master
with:
configuration: "--check-only --profile black"
Expand All @@ -122,7 +124,9 @@ jobs:
- name: Check out source repository
uses: actions/checkout@v3
- name: Setup python environment
uses: actions/setup-python@v3
uses: actions/setup-python@v4.1.0
with:
python-version: '3.10'
- name: Setup testing environment
uses: ./.github/actions/setup-environment
with:
Expand Down Expand Up @@ -249,7 +253,9 @@ jobs:
- name: Check out source repository
uses: actions/checkout@v3
- name: Setup python environment
uses: actions/setup-python@v3
uses: actions/setup-python@v4.1.0
with:
python-version: '3.10'
- name: Setup testing environment
uses: ./.github/actions/setup-environment
with:
Expand Down
2 changes: 1 addition & 1 deletion GMSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from helpers.MonicaHelper import Monica
from helpers.SyncHelper import Sync

VERSION = "v4.1.1"
VERSION = "v4.1.2"
LOG_FOLDER = "logs"
LOG_FILENAME = "sync.log"
DEFAULT_CONFIG_FILEPATH = join("helpers", ".env.default")
Expand Down
2 changes: 1 addition & 1 deletion Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ To configure the OAuth consent screen:
4. Open a command prompt inside the main directory run initial sync using the following command (on Windows replace `$(pwd)` with `%cd%`)

```bash
docker run -v "$(pwd)/data":/usr/app/data -v "$(pwd)/logs":/usr/app/logs --env-file .env -it antonplagemann/google-monica-sync sh -c "python -u GMSync.py -i"
docker run -v "$(pwd)/data":/usr/app/data -v "$(pwd)/logs":/usr/app/logs -p 56411:56411 --env-file .env -it antonplagemann/google-monica-sync sh -c "python -u GMSync.py -i"
```

5. On the first run the script will print a Google consent URL in the console. Copy this URL and open it in a browser on the host machine.
Expand Down
8 changes: 5 additions & 3 deletions helpers/GoogleHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ def __build_service(self) -> Resource:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
elif self.is_interactive:
prompt = "\nPlease visit this URL to authorize this application:\n{url}\n"
flow = InstalledAppFlow.from_client_secrets_file(
self.credentials_file,
scopes=["https://www.googleapis.com/auth/contacts"],
)
creds = flow.run_console(prompt="consent", authorization_prompt_message=prompt)
creds = flow.run_local_server(
port=56411, bind_addr="0.0.0.0", prompt="consent" # nosec B104
)
else:
self.log.error("The 'token.pickle' file was not found or invalid!")
self.log.info(
Expand Down Expand Up @@ -340,7 +341,7 @@ def __get_label_mapping(self) -> dict:
returns a {name: id} mapping."""
try:
# Get all contact groups
response = self.service.contactGroups().list().execute()
response = self.service.contactGroups().list(pageSize=1000).execute()
self.api_requests += 1
groups = response.get("contactGroups", [])

Expand Down Expand Up @@ -397,6 +398,7 @@ def create_label(self, label_name: str) -> str:

group_id = response.get("resourceName", "contactGroups/myContacts")
self.label_mapping.update({label_name: group_id})
self.reverse_label_mapping.update({group_id: label_name})
return group_id

except HttpError as error:
Expand Down
5 changes: 3 additions & 2 deletions helpers/SyncHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,9 @@ def create_google_contact(self, monica_contact: dict) -> dict:
def __get_monica_middle_name(
self, first_name: str, last_name: str, nickname: str, full_name: str
) -> str:
"""Monica contacts have for some reason a hidden field middlename that can be set (creation/update)
but sadly can not retrieved later. This function computes it by using the complete_name field."""
"""Monica contacts have for some reason a hidden field middlename
that can be set (creation/update) but sadly can not retrieved later.
This function computes it by using the complete_name field."""
try:
# If there is a nickname it will be parenthesized with a space
nickname_length = len(nickname) + 3 if nickname else 0
Expand Down

0 comments on commit 594ca41

Please sign in to comment.