Skip to content

Commit

Permalink
Add a ${username} variable for use in targets
Browse files Browse the repository at this point in the history
In git-send-email, it requests a credential with a host and a username.
Normally this would be fine, but it can cause issues if you have
multiple email accounts on a single host (ex. multiple gmail accounts;
pass-git-helper sees them all as host=smtp.gmail.com:587). Having a
${username} (the variable matching the username requested) fixes this.
  • Loading branch information
somasis committed Apr 14, 2019
1 parent f84376d commit 6734abf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions passgithelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ def get_password(request, mapping) -> None:
return

host = request['host']
if 'username' in request:
username = request['username']
if 'path' in request:
host = '/'.join([host, request['path']])

Expand All @@ -354,6 +356,9 @@ def skip(line, skip):
# TODO handle exceptions
pass_target = mapping.get(section, 'target').replace(
"${host}", request['host'])
if 'username' in request:
pass_target = pass_target.replace(
"${username}", request['username'])

password_extractor = SpecificLineExtractor(
0, 0, option_suffix='_password')
Expand Down
2 changes: 1 addition & 1 deletion test_data/wildcard/git-pass-mapping.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[*]
target=dev/${host}
target=dev/${host}/${username}
3 changes: 2 additions & 1 deletion test_passgithelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_wildcard_matching(self, xdg_dir, monkeypatch, mocker, capsys):
monkeypatch.setattr('sys.stdin', io.StringIO('''
protocol=https
host=wildcard.com
username=wildcard
path=subpath/bar.git'''))

subprocess_mock = mocker.patch('subprocess.check_output')
Expand All @@ -217,7 +218,7 @@ def test_wildcard_matching(self, xdg_dir, monkeypatch, mocker, capsys):

subprocess_mock.assert_called_once()
subprocess_mock.assert_called_with(
['pass', 'show', 'dev/wildcard.com'])
['pass', 'show', 'dev/wildcard.com/wildcard'])

out, _ = capsys.readouterr()
assert out == 'password=narf-wildcard\n'
Expand Down

0 comments on commit 6734abf

Please sign in to comment.