jwbmisc 0.0.6__tar.gz → 0.0.7__tar.gz
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-0.0.6/src/jwbmisc.egg-info → jwbmisc-0.0.7}/PKG-INFO +1 -1
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/_version.py +3 -3
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/passwd.py +22 -15
- {jwbmisc-0.0.6 → jwbmisc-0.0.7/src/jwbmisc.egg-info}/PKG-INFO +1 -1
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_passwd.py +3 -3
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/LICENSE +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/MANIFEST.in +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/Makefile +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/README.md +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/pyproject.toml +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/release.sh +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/setup.cfg +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/__init__.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/collection.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/exec.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/fs.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/interactive.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/json.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/keeper.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc/string.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc.egg-info/SOURCES.txt +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc.egg-info/dependency_links.txt +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc.egg-info/requires.txt +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/src/jwbmisc.egg-info/top_level.txt +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/conftest.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/fzf +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/pass +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_collection.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_exec.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_fs.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_interactive.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_json.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_keeper.py +0 -0
- {jwbmisc-0.0.6 → jwbmisc-0.0.7}/tests/test_string.py +0 -0
|
@@ -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
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g60a16ac84'
|
|
@@ -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("/", "__")
|
|
@@ -47,26 +55,25 @@ def get_pass(*pass_keys: str):
|
|
|
47
55
|
raise KeyError(f"Could not acquire password from one of {pass_keys}")
|
|
48
56
|
|
|
49
57
|
|
|
50
|
-
def _call_unix_pass(key,
|
|
58
|
+
def _call_unix_pass(key: str, idcs: list[int] | None = None, format: str = "list") -> str | list[str] | None:
|
|
51
59
|
proc = sp.Popen([PASS_BIN, "show", key], stdout=sp.PIPE, stderr=sp.PIPE, encoding="utf-8")
|
|
52
60
|
value, stderr = proc.communicate()
|
|
53
61
|
|
|
54
62
|
if proc.returncode != 0:
|
|
55
63
|
raise KeyError(f"pass failed for '{key}': {stderr.strip()}")
|
|
56
64
|
|
|
57
|
-
if
|
|
58
|
-
return value.
|
|
59
|
-
lines = value.splitlines()
|
|
65
|
+
if idcs is None or idcs == [-1]:
|
|
66
|
+
return value.rstrip()
|
|
60
67
|
|
|
68
|
+
lines = value.splitlines()
|
|
61
69
|
try:
|
|
62
|
-
|
|
63
|
-
pw = [lines[ln - 1].strip() for ln in lnum]
|
|
64
|
-
else:
|
|
65
|
-
pw = lines[lnum - 1].strip()
|
|
70
|
+
lines = [lines[idx] for idx in idcs]
|
|
66
71
|
except IndexError:
|
|
67
|
-
raise KeyError(f"could not retrieve
|
|
72
|
+
raise KeyError(f"could not retrieve line idcs {idcs} for {key}")
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
if format == "list":
|
|
75
|
+
return lines
|
|
76
|
+
return "\n".join(lines)
|
|
70
77
|
|
|
71
78
|
|
|
72
79
|
def _keeper_password(record_uid: str, field_path: str | None = None) -> str:
|
|
@@ -13,18 +13,18 @@ class TestUnixPass:
|
|
|
13
13
|
assert result == "password123"
|
|
14
14
|
|
|
15
15
|
def test_pass_url_with_line_number(self):
|
|
16
|
-
result = pw.get_pass("pass://test/multiline?2")
|
|
16
|
+
result = pw.get_pass("pass://test/multiline?lines=2")
|
|
17
17
|
assert result == "line2"
|
|
18
18
|
|
|
19
19
|
def test_pass_url_with_all_lines(self):
|
|
20
|
-
result = pw.get_pass("pass://test/multiline?
|
|
20
|
+
result = pw.get_pass("pass://test/multiline?lines=all&format=list")
|
|
21
21
|
assert "line1" in result
|
|
22
22
|
assert "line2" in result
|
|
23
23
|
assert "line3" in result
|
|
24
24
|
|
|
25
25
|
def test_pass_url_with_invalid_line_number(self):
|
|
26
26
|
with pytest.raises(KeyError):
|
|
27
|
-
pw.get_pass("pass://test/multiline?99")
|
|
27
|
+
pw.get_pass("pass://test/multiline?lines=99")
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
class TestGetPass:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|