Compare commits

...

4 Commits

Author SHA1 Message Date
Felipe M 91c9b54762
Updated README 2021-02-01 08:45:58 +01:00
Felipe M 752373bda1
Added commands to fill only username and password 2021-02-01 08:45:01 +01:00
Felipe M aef61caf06
Updated dependencies 2021-02-01 08:44:53 +01:00
Felipe M 6c4985dadb
Using python3 directly on pre-commit 2021-02-01 08:44:40 +01:00
5 changed files with 634 additions and 325 deletions

View File

@ -19,4 +19,4 @@ repos:
rev: stable
hooks:
- id: black
language_version: python3.7
language_version: python3

View File

@ -19,7 +19,7 @@ Right now it defaults to the `my` account, will be configurable in the future.
usage: qute_1pass.py [-h] [--auto-submit] [--cache-session] command
positional arguments:
command fill_credentials, fill_totp
command fill_credentials, fill_totp, fill_username, fill_password
optional arguments:
-h, --help show this help message and exit

890
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,14 +8,14 @@ authors = ["Felipe Martin <me@fmartingr.com>"]
python = "^3.7"
[tool.poetry.dev-dependencies]
black = {version = "^18.3-alpha.0", allows-prereleases = true}
flake8 = "^3.7"
isort = "^4.3"
pre-commit = "^1.18"
rope = "^0.14.0"
ipdb = "^0.12.2"
pylint = "^2.4"
mypy = "^0.730.0"
black = "*"
flake8 = "*"
isort = "*"
pre-commit = "*"
rope = "*"
ipdb = "*"
pylint = "*"
mypy = "*"
[build-system]
requires = ["poetry>=0.12"]

View File

@ -36,7 +36,9 @@ CMD_OP_GET_TOTP = "op get totp {uuid} --session={session_id}"
QUTE_FIFO = os.environ["QUTE_FIFO"]
parser = argparse.ArgumentParser()
parser.add_argument("command", help="fill_credentials, fill_totp")
parser.add_argument(
"command", help="fill_credentials, fill_totp, fill_username, fill_password"
)
parser.add_argument(
"--auto-submit", help="Auto submit after filling", action="store_true"
)
@ -82,6 +84,12 @@ class Qute:
if submit:
cls.fake_key("<Return>")
@classmethod
def fill_single_field_tabmode(cls, value, submit=False):
cls.fake_key(value)
if submit:
cls.fake_key("<Return>")
@classmethod
def fill_totp(cls, totp, submit=True):
cls.fake_key(totp)
@ -226,7 +234,7 @@ class OnePass:
)
Qute.message_warning("Filled incomplete credentials")
return username, password
return {"username": username, "password": password}
@classmethod
def get_totp(cls, uuid):
@ -259,18 +267,39 @@ class CLI:
sys.exit(0)
return item
def fill_credentials(self):
item = self._get_item()
username, password = OnePass.get_credentials(item)
Qute.fill_credentials_tabmode(
username, password, submit=self.arguments.auto_submit
)
# Store a reference to this items in case we need a quick reference to the UUID
# to get the TOTP later
def _store_last_item(self, item):
"""
Stores a reference to an item to easily get single information from it (password, TOTP)
right after filling the username or credentials.
"""
last_item = {"host": extract_host(os.environ["QUTE_URL"]), "uuid": item["uuid"]}
with open(LAST_ITEM_PATH, "w") as handler:
handler.write(json.dumps(last_item))
def _fill_single_field(self, field):
item = self._get_item()
credentials = OnePass.get_credentials(item)
Qute.fill_single_field_tabmode(
credentials[field], submit=self.arguments.auto_submit
)
return item
def fill_username(self):
item = self._fill_single_field("username")
self._store_last_item(item)
def fill_password(self):
item = self._fill_single_field("password")
self._store_last_item(item)
def fill_credentials(self):
item = self._get_item()
credentials = OnePass.get_credentials(item)
Qute.fill_credentials_tabmode(
*credentials.values(), submit=self.arguments.auto_submit
)
self._store_last_item(item)
def fill_totp(self):
# Check last item first
# If theres a last_item file created in the last LAST_ITEM_DURATION seconds