jwbmisc 0.0.5__py3-none-any.whl → 0.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jwbmisc/_version.py +2 -2
- jwbmisc/exec.py +5 -0
- jwbmisc/keeper.py +34 -7
- jwbmisc/passwd.py +25 -20
- {jwbmisc-0.0.5.dist-info → jwbmisc-0.0.7.dist-info}/METADATA +1 -1
- jwbmisc-0.0.7.dist-info/RECORD +15 -0
- {jwbmisc-0.0.5.dist-info → jwbmisc-0.0.7.dist-info}/WHEEL +1 -1
- jwbmisc-0.0.5.dist-info/RECORD +0 -15
- {jwbmisc-0.0.5.dist-info → jwbmisc-0.0.7.dist-info}/licenses/LICENSE +0 -0
- {jwbmisc-0.0.5.dist-info → jwbmisc-0.0.7.dist-info}/top_level.txt +0 -0
jwbmisc/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.0.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 0,
|
|
31
|
+
__version__ = version = '0.0.7'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 0, 7)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
jwbmisc/exec.py
CHANGED
|
@@ -9,6 +9,7 @@ def run_cmd(
|
|
|
9
9
|
stdin=None,
|
|
10
10
|
contains_sensitive_data=False,
|
|
11
11
|
timeout=20,
|
|
12
|
+
cwd=None,
|
|
12
13
|
decode=True,
|
|
13
14
|
dry_run=False,
|
|
14
15
|
):
|
|
@@ -22,6 +23,9 @@ def run_cmd(
|
|
|
22
23
|
|
|
23
24
|
cmd = [str(v) for v in cmd]
|
|
24
25
|
|
|
26
|
+
if cwd is not None:
|
|
27
|
+
cwd = str(cwd)
|
|
28
|
+
|
|
25
29
|
if dry_run:
|
|
26
30
|
print(cmd)
|
|
27
31
|
if capture:
|
|
@@ -35,6 +39,7 @@ def run_cmd(
|
|
|
35
39
|
env=env,
|
|
36
40
|
check=True,
|
|
37
41
|
timeout=timeout,
|
|
42
|
+
cwd=cwd,
|
|
38
43
|
input=stdin,
|
|
39
44
|
)
|
|
40
45
|
except sp.CalledProcessError as ex:
|
jwbmisc/keeper.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
from typing import Any
|
|
2
3
|
from keepercommander import vault
|
|
3
4
|
from keepercommander import api
|
|
4
5
|
from time import sleep
|
|
@@ -67,15 +68,41 @@ class MinimalKeeperUI:
|
|
|
67
68
|
step.resume()
|
|
68
69
|
|
|
69
70
|
|
|
70
|
-
def
|
|
71
|
-
if not isinstance(
|
|
72
|
-
|
|
71
|
+
def as_strings(vs: list[Any] | Any) -> list[str]:
|
|
72
|
+
if not isinstance(vs, list):
|
|
73
|
+
vs = [vs]
|
|
74
|
+
return [str(v) for v in vs]
|
|
73
75
|
|
|
74
|
-
value = record.get_typed_field(field) or record.get_typed_field(None, field)
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
def extract_record_field(record, field: str | None) -> str | None | list[dict[str, str | list[str]]]:
|
|
78
|
+
if isinstance(record, vault.PasswordRecord):
|
|
79
|
+
values = [
|
|
80
|
+
{"type": "password", "label": "login", "value": as_strings(record.login)},
|
|
81
|
+
{"type": "password", "label": "password", "value": as_strings(record.password)},
|
|
82
|
+
{"type": "password", "label": "link", "value": as_strings(record.link)},
|
|
83
|
+
] + [{"type": f.type, "label": f.name, "value": as_strings(f.value)} for f in record.custom]
|
|
78
84
|
|
|
85
|
+
elif isinstance(record, vault.TypedRecord):
|
|
86
|
+
fields = record.fields + record.custom
|
|
87
|
+
values = [{"type": f.type, "label": f.label, "value": as_strings(f.value)} for f in fields]
|
|
88
|
+
else:
|
|
89
|
+
raise TypeError("only TypedRecord & PasswordRecord are supported")
|
|
90
|
+
|
|
91
|
+
if not field:
|
|
92
|
+
return values
|
|
93
|
+
|
|
94
|
+
value = next(
|
|
95
|
+
(
|
|
96
|
+
v
|
|
97
|
+
for v in values
|
|
98
|
+
if (v["type"] and v["type"].lower() == field.lower())
|
|
99
|
+
or (v["label"] and v["label"].lower() == field.lower())
|
|
100
|
+
),
|
|
101
|
+
None,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
if value and value["value"]:
|
|
105
|
+
return value["value"][0]
|
|
79
106
|
return None
|
|
80
107
|
|
|
81
108
|
|
|
@@ -105,7 +132,7 @@ def perform_login(params):
|
|
|
105
132
|
raise KeyError(f"Keeper login failed: {e}") from e
|
|
106
133
|
|
|
107
134
|
|
|
108
|
-
def get_password(record_uid: str, field_path: str) -> str:
|
|
135
|
+
def get_password(record_uid: str, field_path: str | None) -> str:
|
|
109
136
|
CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
110
137
|
|
|
111
138
|
params = KeeperParams(config_filename=str(CONFIG_FILE))
|
jwbmisc/passwd.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import subprocess as sp
|
|
2
2
|
import os
|
|
3
|
+
from urllib.parse import urlparse, parse_qs
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
|
|
5
6
|
PASS_BIN = os.environ.get("JWBMISC_PASS_BIN", "pass")
|
|
@@ -11,11 +12,18 @@ def get_pass(*pass_keys: str):
|
|
|
11
12
|
|
|
12
13
|
for pass_key in pass_keys:
|
|
13
14
|
if pass_key.startswith("pass://"):
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
url = urlparse(pass_key, scheme="pass")
|
|
16
|
+
query = parse_qs(url.query)
|
|
17
|
+
lines = query.get("lines", ["1"])[0]
|
|
18
|
+
format = query.get("format", ["raw"])[0]
|
|
19
|
+
if lines == "all":
|
|
20
|
+
lines = None
|
|
21
|
+
else:
|
|
22
|
+
lines = [int(n) - 1 for n in lines.split(",")]
|
|
23
|
+
netloc = url.netloc.rstrip("/")
|
|
24
|
+
path = url.path.lstrip("/")
|
|
25
|
+
key = f"{netloc}/{path}".lstrip("/")
|
|
26
|
+
return _call_unix_pass(key, lines, format)
|
|
19
27
|
|
|
20
28
|
if pass_key.startswith("env://"):
|
|
21
29
|
env_var = pass_key.removeprefix("env://").replace("/", "__")
|
|
@@ -40,38 +48,35 @@ def get_pass(*pass_keys: str):
|
|
|
40
48
|
|
|
41
49
|
if pass_key.startswith("keeper://"):
|
|
42
50
|
path = pass_key.removeprefix("keeper://")
|
|
43
|
-
if "/" not in path:
|
|
44
|
-
raise KeyError("Invalid keeper:// format. Expected: keeper://RECORD_UID/field/fieldname")
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
return _keeper_password(
|
|
52
|
+
parts = path.split("/")
|
|
53
|
+
return _keeper_password(*parts)
|
|
48
54
|
|
|
49
55
|
raise KeyError(f"Could not acquire password from one of {pass_keys}")
|
|
50
56
|
|
|
51
57
|
|
|
52
|
-
def _call_unix_pass(key,
|
|
58
|
+
def _call_unix_pass(key: str, idcs: list[int] | None = None, format: str = "list") -> str | list[str] | None:
|
|
53
59
|
proc = sp.Popen([PASS_BIN, "show", key], stdout=sp.PIPE, stderr=sp.PIPE, encoding="utf-8")
|
|
54
60
|
value, stderr = proc.communicate()
|
|
55
61
|
|
|
56
62
|
if proc.returncode != 0:
|
|
57
63
|
raise KeyError(f"pass failed for '{key}': {stderr.strip()}")
|
|
58
64
|
|
|
59
|
-
if
|
|
60
|
-
return value.
|
|
61
|
-
lines = value.splitlines()
|
|
65
|
+
if idcs is None or idcs == [-1]:
|
|
66
|
+
return value.rstrip()
|
|
62
67
|
|
|
68
|
+
lines = value.splitlines()
|
|
63
69
|
try:
|
|
64
|
-
|
|
65
|
-
pw = [lines[ln - 1].strip() for ln in lnum]
|
|
66
|
-
else:
|
|
67
|
-
pw = lines[lnum - 1].strip()
|
|
70
|
+
lines = [lines[idx] for idx in idcs]
|
|
68
71
|
except IndexError:
|
|
69
|
-
raise KeyError(f"could not retrieve
|
|
72
|
+
raise KeyError(f"could not retrieve line idcs {idcs} for {key}")
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
if format == "list":
|
|
75
|
+
return lines
|
|
76
|
+
return "\n".join(lines)
|
|
72
77
|
|
|
73
78
|
|
|
74
|
-
def _keeper_password(record_uid: str, field_path: str) -> str:
|
|
79
|
+
def _keeper_password(record_uid: str, field_path: str | None = None) -> str:
|
|
75
80
|
from .keeper import get_password as keeper_get_password
|
|
76
81
|
|
|
77
82
|
return keeper_get_password(record_uid, field_path)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
jwbmisc/__init__.py,sha256=5VXxKCMejjLWaiECh64309WJ2LpHHSULxaGOvCAOzyU,581
|
|
2
|
+
jwbmisc/_version.py,sha256=AV58KqMkBGaCvmPdbd3g9huyNXfIVxjw8QbCMdaeivU,704
|
|
3
|
+
jwbmisc/collection.py,sha256=mICHxBFfk2XY8ajdWkLvmQF1R6oo6d0torpRAeDvd1c,663
|
|
4
|
+
jwbmisc/exec.py,sha256=_3Xf0D342VDoVwtCZLjnyJ8N-WuHJfeIrBGFsL2qUW4,1260
|
|
5
|
+
jwbmisc/fs.py,sha256=Vf28qbOnBeHEbXNMUZjOQXtMWBurjkzD2KmfV2gJQXM,599
|
|
6
|
+
jwbmisc/interactive.py,sha256=qMgpQNHvUg4AYw-aAAy2qdxri1aKr-mffoLfUgh8TWE,423
|
|
7
|
+
jwbmisc/json.py,sha256=h3CBDNNZjcTDxydViyydPsQufXQLuxqP24wBBAT2nDs,1198
|
|
8
|
+
jwbmisc/keeper.py,sha256=mKhrUjNvlePxDv89tMcDs4dEgHWTVbtzMPH1jMRuylU,5201
|
|
9
|
+
jwbmisc/passwd.py,sha256=VfE3P6B_DpRS7htzKTdvtxlxQj9OkFMVGeGZxNZ9B5w,2856
|
|
10
|
+
jwbmisc/string.py,sha256=0_AvtAyXUlyVL6yw1iMjs3vMunubTTTWS0PSu_qKgi8,1232
|
|
11
|
+
jwbmisc-0.0.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
12
|
+
jwbmisc-0.0.7.dist-info/METADATA,sha256=LuXHFOVggPnK2nA1w9Hg9_LBchkGHtVumeH7bUwqzuY,14507
|
|
13
|
+
jwbmisc-0.0.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
14
|
+
jwbmisc-0.0.7.dist-info/top_level.txt,sha256=FqEYs8zdG3iGOJmC6cutDXfGQUNptzfYeKsaG43y1HE,8
|
|
15
|
+
jwbmisc-0.0.7.dist-info/RECORD,,
|
jwbmisc-0.0.5.dist-info/RECORD
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
jwbmisc/__init__.py,sha256=5VXxKCMejjLWaiECh64309WJ2LpHHSULxaGOvCAOzyU,581
|
|
2
|
-
jwbmisc/_version.py,sha256=YRV1ohn6CdKEhsUOmFFMmr5UTjMv4Ydw3WJGxF2BHBs,704
|
|
3
|
-
jwbmisc/collection.py,sha256=mICHxBFfk2XY8ajdWkLvmQF1R6oo6d0torpRAeDvd1c,663
|
|
4
|
-
jwbmisc/exec.py,sha256=9g1Jc7iDkBj1Y-dn5VhnwH1JqvWSbrFe6Mmvnf-iqag,1177
|
|
5
|
-
jwbmisc/fs.py,sha256=Vf28qbOnBeHEbXNMUZjOQXtMWBurjkzD2KmfV2gJQXM,599
|
|
6
|
-
jwbmisc/interactive.py,sha256=qMgpQNHvUg4AYw-aAAy2qdxri1aKr-mffoLfUgh8TWE,423
|
|
7
|
-
jwbmisc/json.py,sha256=h3CBDNNZjcTDxydViyydPsQufXQLuxqP24wBBAT2nDs,1198
|
|
8
|
-
jwbmisc/keeper.py,sha256=Fj9k8vWpfp2UMFiCfghWlnc5UxnkcR0oBQgY7NiJhsM,4241
|
|
9
|
-
jwbmisc/passwd.py,sha256=pTa0Lo7Qq10oo7PDlbq8lS3f5IaMFspKB27QI1NQB5k,2593
|
|
10
|
-
jwbmisc/string.py,sha256=0_AvtAyXUlyVL6yw1iMjs3vMunubTTTWS0PSu_qKgi8,1232
|
|
11
|
-
jwbmisc-0.0.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
12
|
-
jwbmisc-0.0.5.dist-info/METADATA,sha256=PEKl-YazmyJFlnl8uAYVHcpUhPbyUWp4L5ly1eEf_T4,14507
|
|
13
|
-
jwbmisc-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
-
jwbmisc-0.0.5.dist-info/top_level.txt,sha256=FqEYs8zdG3iGOJmC6cutDXfGQUNptzfYeKsaG43y1HE,8
|
|
15
|
-
jwbmisc-0.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|