Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ target=git-logins/${host}

The above configuration directive will lead to any host that did not match any previous section in the ini file to being looked up under the `git-logins` directory in your password store.

Apart from `${host}`, the variables `${username}` and `${protocol}` can be used for replacements.
Apart from `${host}`, the variables `${username}`, `${path}` and `${protocol}` can be used for replacements. Given the remote url `https://github.com/languitar/pass-git-helper.git`, variables are filled as follow:

| var | value |
| --- | --- |
| `${host}` | `github.com` |
| `${username}` | `languitar` |
| `${path}` | `languitar/pass-git-helper.git` |
| `${protocol}` | `https` |

#### DEFAULT Section

Expand Down
3 changes: 3 additions & 0 deletions passgithelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ def define_pass_target(
) -> str:
"""Determine the pass target by filling in potentially used variables."""
pass_target = section["target"].replace("${host}", request["host"])

if "path" in request:
pass_target = pass_target.replace("${path}", request["path"])
if "username" in request:
pass_target = pass_target.replace("${username}", request["username"])
if "protocol" in request:
Expand Down
2 changes: 2 additions & 0 deletions test_data/wildcard_path/git-pass-mapping.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*]
target=dev/${protocol}/${host}/${username}/${path}
23 changes: 23 additions & 0 deletions test_passgithelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@ def test_wildcard_matching(self, capsys: Any) -> None:
out, _ = capsys.readouterr()
assert out == "password=narf-wildcard\n"

@pytest.mark.parametrize(
"helper_config",
[
HelperConfig(
"test_data/wildcard_path",
"""
protocol=https
host=path_wildcard.com
username=path_wildcard
path=subpath/bar.git""",
b"daniele-tentoni-path-wildcard",
"dev/https/path_wildcard.com/path_wildcard/subpath/bar.git",
),
],
indirect=True,
)
@pytest.mark.usefixtures("helper_config")
def test_wildcard_path_matching(self, capsys: Any) -> None:
passgithelper.main(["get"])

out, _ = capsys.readouterr()
assert out == "password=daniele-tentoni-path-wildcard\n"

@pytest.mark.parametrize(
"helper_config",
[
Expand Down