Skip to content

Commit 1622737

Browse files
committed
feat: add support for password extractor
1 parent 6a893bd commit 1622737

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

passgithelper.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import xdg.BaseDirectory
2323

2424

25-
__version__ = "3.1.0"
25+
__version__ = "3.2.0"
2626

2727
LOGGER = logging.getLogger()
2828
CONFIG_FILE_NAME = "git-pass-mapping.ini"
@@ -314,6 +314,13 @@ def get_value(
314314
),
315315
"entry_name": EntryNameExtractor(option_suffix="_username"),
316316
}
317+
_password_extractors = {
318+
_line_extractor_name: SpecificLineExtractor(0, 0, option_suffix="_password"),
319+
"regex_search": RegexSearchExtractor(
320+
r"^password: +(.*)$", option_suffix="_password"
321+
),
322+
"entry_name": EntryNameExtractor(option_suffix="_password"),
323+
}
317324

318325

319326
def find_mapping_section(
@@ -386,7 +393,17 @@ def get_password(
386393

387394
pass_target = define_pass_target(section, request)
388395

389-
password_extractor = SpecificLineExtractor(0, 0, option_suffix="_password")
396+
password_extractor_name: str = section.get("password_extractor") # type: ignore
397+
398+
if password_extractor_name:
399+
password_extractor = _password_extractors.get(password_extractor_name)
400+
else:
401+
password_extractor = SpecificLineExtractor(0, 0, option_suffix="_password")
402+
403+
if password_extractor is None:
404+
raise ValueError(
405+
f"A password_extractor of type '{password_extractor_name}' does not exist"
406+
)
390407
password_extractor.configure(section)
391408

392409
username_extractor_name: str = section.get( # type: ignore

0 commit comments

Comments
 (0)