From ed2bde2babe12ae5cb5707754dfefc63bfadba4e Mon Sep 17 00:00:00 2001 From: F M Date: Fri, 15 Jul 2022 21:01:01 +0200 Subject: [PATCH 1/7] Pin click due to some import issue See https://github.com/psf/black/issues/2964 --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 862c72b..f92cb4b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,9 +5,10 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/psf/black - rev: "22.1.0" + rev: "22.6.0" hooks: - id: black + additional_dependencies: ['click==8.0.4'] - repo: local hooks: - id: pylint From e57c0464a5b61cb2f31c6e8c2a79f0c2eb92e60d Mon Sep 17 00:00:00 2001 From: F M Date: Fri, 15 Jul 2022 21:01:25 +0200 Subject: [PATCH 2/7] Remove excess logging --- tests/test_kp_kp_sync.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/test_kp_kp_sync.py b/tests/test_kp_kp_sync.py index d96a155..1af1677 100644 --- a/tests/test_kp_kp_sync.py +++ b/tests/test_kp_kp_sync.py @@ -36,40 +36,32 @@ @pytest.fixture(name="cli1") def _cli1(): - LOGGER.info("Setup cli1") try: remove(KP1_FILENAME) except FileNotFoundError: pass # maybe file did not exist cli = KeepassDatabaseClient(KP1_FILENAME, KP1_PW) yield cli - LOGGER.info("Teardown cli1") @pytest.fixture(name="ds1") def _ds1(cli1): - LOGGER.info("Setup ds1") yield PasswordDataset(KP1_FILENAME, QUERY_INFO, cli1) - LOGGER.info("Teardown ds1") @pytest.fixture(name="cli2") def _cli2(): - LOGGER.info("Setup cli2") try: remove(KP2_FILENAME) except FileNotFoundError: pass # maybe file did not exist cli = KeepassDatabaseClient(KP2_FILENAME, KP2_PW) yield cli - LOGGER.info("Teardown cli2") @pytest.fixture(name="ds2") def _ds2(cli2): - LOGGER.info("Setup ds2") yield PasswordDataset(KP1_FILENAME, QUERY_INFO, cli2) - LOGGER.info("Teardown ds2") @pytest.fixture(name="sync") From 2e2181c0fa20d83c5593ab14b90932e0fbbccc19 Mon Sep 17 00:00:00 2001 From: F M Date: Fri, 15 Jul 2022 21:04:37 +0200 Subject: [PATCH 3/7] Bump versions --- README.md | 1 + setup.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 71635c8..8d8aa71 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ causes a create/delete modification! To synchronize, `pwsync` depends on: - The python [_diffsync_](https://pypi.org/project/diffsync/) module: determines the differences between two password databases. - The python [_pykeepass_](https://pypi.org/project/pykeepass/) module: modifies a Keepass_ file. +- The python [_prompt-toolkit_](https://pypi.org/project/prompt-toolkit/) module - Bitwarden's official(?) [_command line client_](https://bitwarden.com/help/article/cli/): modifies a Bitwarden online password database. An curated dump of the console output is shown below: diff --git a/setup.py b/setup.py index c0ae4d9..c4e3036 100644 --- a/setup.py +++ b/setup.py @@ -33,9 +33,9 @@ python_requires=">=3.7.0", packages=find_packages(), install_requires=[ - "pykeepass==4.0.1", - "diffsync==1.4.2", - "prompt-toolkit==3.0.28", + "pykeepass==4.0.3", + "diffsync==1.6.0", + "prompt-toolkit==3.0.30", ], extras_require={ "dev": [ From 2f819fea58be09bb5f5006d61ef7ccd10588be3a Mon Sep 17 00:00:00 2001 From: F M Date: Fri, 15 Jul 2022 23:18:27 +0200 Subject: [PATCH 4/7] Version numbering changed --- pwsync/bw_cli_wrapper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pwsync/bw_cli_wrapper.py b/pwsync/bw_cli_wrapper.py index 2f0d2c2..d474da9 100644 --- a/pwsync/bw_cli_wrapper.py +++ b/pwsync/bw_cli_wrapper.py @@ -38,7 +38,7 @@ # Bitwarden client 1.21.1 on MacOs has an issue with bw list items # (https://github.com/bitwarden/cli/issues/490) -BW_SUPPORTED_VERSION = "1.19.1" +BW_SUPPORTED_VERSION_MAJOR = 2022 # Item Types. Used with the create command to specify a Vault item type: USER_TYPE = 1 # a login item (has inside a login sub-type) @@ -200,7 +200,7 @@ def _check_output( @eet def _get_status(self): - version = check_output(["bw", "--version"]).strip().decode("utf-8") + version = tuple(map(int, check_output(["bw", "--version"]).strip().decode("utf-8").split("."))) status_obj = self._check_output(["bw", "--raw", "status"]) status = status_obj.get("status", "unauthenticated") # locked, unlocked, unauthenticated user_id = status_obj.get("userId", "") @@ -221,8 +221,8 @@ def _make_session( ): status, user_id, version = self._get_status() - if version != BW_SUPPORTED_VERSION: - raise PwsUnsupported(f"Use bitwareden-cli {BW_SUPPORTED_VERSION}. {version} is not supported!") + if version[0] < BW_SUPPORTED_VERSION_MAJOR: + raise PwsUnsupported(f"Use bitwareden-cli {BW_SUPPORTED_VERSION_MAJOR}. {version} is not supported!") if client_id != f"user.{user_id}" and status != "unauthenticated": self.logout() From 66b292d4d28ea5ba0dee908c021a1fc69ca96aff Mon Sep 17 00:00:00 2001 From: F M Date: Fri, 15 Jul 2022 23:20:20 +0200 Subject: [PATCH 5/7] Fix output as stdout --- pwsync/bw_cli_wrapper.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pwsync/bw_cli_wrapper.py b/pwsync/bw_cli_wrapper.py index d474da9..7781b03 100644 --- a/pwsync/bw_cli_wrapper.py +++ b/pwsync/bw_cli_wrapper.py @@ -194,7 +194,9 @@ def _check_output( self._logger.debug("cmd: %s, result: %s", cmd, result_json) return json.loads(result_json) except CalledProcessError as exc: - result_json = f"ret: {exc.returncode}, stdout: {exc.output}, stderr: {exc.stderr}" + out = exc.stdout.decode("utf-8") if exc.stdout is not None else "''" + err = exc.stderr.decode("utf-8") if exc.stderr is not None else "''" + result_json = f"ret: {exc.returncode}, stdout: {out}, stderr: {err}" self._logger.error("cmd: %s, result: %s", cmd, result_json) raise exc From b3902a07a3fe99441565926baa8abbf8adf124e5 Mon Sep 17 00:00:00 2001 From: F M Date: Sat, 16 Jul 2022 06:43:17 +0200 Subject: [PATCH 6/7] Bump node & npm version in CI --- .github/workflows/ci.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d8f85ea..ff3608b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,10 +26,9 @@ jobs: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion - nvm install 14.4.0 - npm install -g npm@7.24.2 + nvm install 18.6.0 npm --version - npm i @bitwarden/cli@1.19.1 + npm i @bitwarden/cli PATH=$PATH:$GITHUB_WORKSPACE/node_modules/.bin bw --version python --version From 51c31825a73b963765778ab0a32a24674662d158 Mon Sep 17 00:00:00 2001 From: F M Date: Sat, 16 Jul 2022 08:08:58 +0200 Subject: [PATCH 7/7] Hide node related temporaries --- .gitignore | 3 +++ README.md | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index de73f70..bb6488f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +node_modules/ +package-lock.json +package.json __pycache__/ .venv/ .venv_install_check/ diff --git a/README.md b/README.md index 8d8aa71..6228712 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ This tool and its installation description can be found [here](https://bitwarden.com/help/article/cli/#download-and-install). ```bash -npm install -g @bitwarden/cli@1.19.1 +npm install -g @bitwarden/cli ``` ```bash @@ -126,6 +126,9 @@ export TEST_BW_CLIENT_SECRET= export TEST_BW_MASTER_PASSWORD= python -m pytest -s -vvv --cov=pwsync --cov-report=xml:cov.xml tests || echo "FAILED" +# or run a specific individual test +python -m pytest -s -vvv tests/test_bwc.py -k test_create_one_collection + # for distribution # for the proper version to be generated, use the main branch with a tag like v0.1b5 python -m build