Skip to content

Commit

Permalink
fix: client_secret instead of credential everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravio1i committed Oct 30, 2021
1 parent fa5fd57 commit 05da839
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ If you want to update the setup within the cli or only map the credentials, you'

```yaml
docker run --net=host -it \
-v ~/.notion-gcal-sync/client_credentials.json:/home/worker/notion-gcal-sync/client_credentials.json \
-v ~/.notion-gcal-sync/client_secret.json:/home/worker/notion-gcal-sync/client_secret.json \
notion-gcal-sync
```

Expand Down
17 changes: 9 additions & 8 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ The default `config.yml` is included in the installation and can be found in the
The following is a summary of [this](https://developers.google.com/workspace/guides/create-credentials) and will get you the
credentials for authenticating against your Google calendar.

1. New Project and call it something e.g `notion`. (Note: Make sure to select the newly created project)
2. Navigate to the [API Library](https://console.cloud.google.com/apis/).
3. Search for `Google Calendar API` and `Enable`.
4. Navigate to the [API Credentials Page](https://console.cloud.google.com/apis/credentials).
5. Click `+ Create Credentials` > `OAuth client ID`
6. If Consent Screen > `CONFIGURE CONSENT SCREEN`
1. Open [Google Cloud Platform Console](https://console.cloud.google.com/).
2. New Project and call it something e.g `notion`. (Note: Make sure to select the newly created project)
3. Navigate to the [API Library](https://console.cloud.google.com/apis/).
4. Search for `Google Calendar API` and `Enable`.
5. Navigate to the [API Credentials Page](https://console.cloud.google.com/apis/credentials).
6. Click `+ Create Credentials` > `OAuth client ID`
7. If Consent Screen > `CONFIGURE CONSENT SCREEN`
1. OAuth consent Screen
1. Set User Type to `External`
2. For App information use any App name, like `notion-gcal-sync` and for support email use your email.
Expand All @@ -48,8 +49,8 @@ credentials for authenticating against your Google calendar.
3. Test users
1. `+ Add users` and add your email
2. `Save and continue` (The error `Ineligible accounts not added` can be ignored)
7. Navigate to the [API Credentials Page](https://console.cloud.google.com/apis/credentials).
8. Click `+ Create Credentials` > `OAuth client ID`
8. Navigate to the [API Credentials Page](https://console.cloud.google.com/apis/credentials).
9. Click `+ Create Credentials` > `OAuth client ID`
1. Select `Desktop App` with any name, like `notion-gcal-sync`
2. `Create`
3. In the new prompt `DOWNLOAD JSON` or on the just created credentials on `Actions` click the `Download OAuth client`
Expand Down
12 changes: 6 additions & 6 deletions notion_gcal_sync/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
CONFIG_FILE = os.path.join(CONFIG_PATH, "config.yml")
CONFIG_DEFAULT_FILE = os.path.join(CONFIG_PATH, "config.default.yml")
TOKEN_FILE = os.path.join(CONFIG_PATH, "token.json")
CREDENTIALS_FILE = os.path.join(CONFIG_PATH, "client_credentials.json")
CLIENT_SECRET_FILE = os.path.join(CONFIG_PATH, "client_secret.json")


def confirm_create_path(path: str) -> bool:
Expand Down Expand Up @@ -55,23 +55,23 @@ def config_file_created() -> bool:
return True


def credentials_created() -> bool:
if not os.path.exists(TOKEN_FILE) and os.path.exists(CREDENTIALS_FILE):
def client_secret_created() -> bool:
if not os.path.exists(TOKEN_FILE) and os.path.exists(CLIENT_SECRET_FILE):
logging.info("{} does not exist".format(TOKEN_FILE))
logging.info("Generating token file {}".format(TOKEN_FILE))
GCalClient.get_credentials()
if os.path.exists(TOKEN_FILE):
return True
logging.error("{} nor {} exist".format(CREDENTIALS_FILE, TOKEN_FILE))
logging.error("{} nor {} exist".format(CLIENT_SECRET_FILE, TOKEN_FILE))
logging.info(
"Please follow the instructions on setting up the client_credentials.json: "
"Please follow the instructions on setting up the client_secret.json: "
"https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md#setup-credentials-for-google-calendar"
)
return False


def configure():
confirmed = config_path_created() and config_file_created() and credentials_created()
confirmed = config_path_created() and config_file_created() and client_secret_created()
if not confirmed:
logging.info("Exiting...")
sys.exit()
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,28 @@ def prompt(text, default):
"credentials_path_exists, token_path_exists, expected",
[(False, False, False), (False, True, True), (True, False, False), (True, True, True)],
)
def test_credentials_created(mocker, credentials_path_exists, token_path_exists, expected):
def test_client_secret_created(mocker, credentials_path_exists, token_path_exists, expected):
def path_exists(path):
if path == install.TOKEN_FILE:
return token_path_exists
if path == install.CREDENTIALS_FILE:
if path == install.CLIENT_SECRET_FILE:
return credentials_path_exists

mocker.patch("os.path.exists", side_effect=path_exists)
mocker.patch("notion_gcal_sync.clients.GCalClient.GCalClient.get_credentials")
assert install.credentials_created() is expected
assert install.client_secret_created() is expected


def test_configure(mocker, config_dict_fixture):
mocker.patch("notion_gcal_sync.install.config_path_created", return_value=True)
mocker.patch("notion_gcal_sync.install.config_file_created", return_value=True)
mocker.patch("notion_gcal_sync.install.credentials_created", return_value=True)
mocker.patch("notion_gcal_sync.install.client_secret_created", return_value=True)
mocker.patch("builtins.open", mocker.mock_open(read_data=str(config_dict_fixture)))
assert install.configure().to_dict() == config_dict_fixture


@pytest.mark.parametrize(
"config_path_created, config_file_created, credentials_created",
"config_path_created, config_file_created, client_secret_created",
[
(False, False, False),
(False, False, True),
Expand All @@ -80,9 +80,9 @@ def test_configure(mocker, config_dict_fixture):
(True, True, False),
],
)
def test_configure_not_confirmed(mocker, config_path_created, config_file_created, credentials_created):
def test_configure_not_confirmed(mocker, config_path_created, config_file_created, client_secret_created):
mocker.patch("notion_gcal_sync.install.config_path_created", return_value=config_path_created)
mocker.patch("notion_gcal_sync.install.config_file_created", return_value=config_file_created)
mocker.patch("notion_gcal_sync.install.credentials_created", return_value=credentials_created)
mocker.patch("notion_gcal_sync.install.client_secret_created", return_value=client_secret_created)
with pytest.raises(SystemExit):
install.configure()

0 comments on commit 05da839

Please sign in to comment.