Skip to content

Commit

Permalink
Merge pull request #20 from mas90/ignore-unknown-hooks
Browse files Browse the repository at this point in the history
Ignore unrecognised hooks, as required by current dehydrated
  • Loading branch information
eferdman authored Jun 20, 2018
2 parents 8865fcc + 1cf94b2 commit cedf2e6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion dehydrated-hook-ddns-tsig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import sys
import time
import logging
import collections
import dns.resolver
import dns.tsig
import dns.tsigkeyring
Expand Down Expand Up @@ -628,7 +629,7 @@ def parse_args():
help="Lower verbosity",
action='count', default=0)

subparsers = parser.add_subparsers(help='sub-command help')
subparsers = parser.add_subparsers(help='sub-command help', dest='_hook')

parser_deploychallenge = subparsers.add_parser(
'deploy_challenge',
Expand Down Expand Up @@ -824,6 +825,14 @@ def parse_args():
_func=exit_hook,
_parser=parser_exit_hook)

# prepare to ignore unrecognised hooks
fallback_parser = argparse.ArgumentParser()
fallback_parser.add_argument('_hook_arg', nargs='*')
subparsers._name_parser_map = collections.defaultdict(
lambda: fallback_parser,
subparsers._name_parser_map)
subparsers.choices = None

args = parser.parse_args()
try:
while(args._extra[0]):
Expand All @@ -843,6 +852,12 @@ def parse_args():
set_verbosity(verbosity)

cfg = read_config(args)

# ignore unrecognised hooks
if not hasattr(args, '_func'):
logger.debug("ignoring unknown hook: %s", args._hook)
return (lambda cfg: None, cfg)

return (args._func, cfg)


Expand Down

0 comments on commit cedf2e6

Please sign in to comment.