diff options
Diffstat (limited to 'gkeys')
-rw-r--r-- | gkeys/gkeysgpg/action.py | 52 | ||||
-rw-r--r-- | gkeys/gkeysgpg/actions.py | 91 | ||||
-rw-r--r-- | gkeys/gkeysgpg/cli.py | 31 |
3 files changed, 114 insertions, 60 deletions
diff --git a/gkeys/gkeysgpg/action.py b/gkeys/gkeysgpg/action.py deleted file mode 100644 index 7eac144..0000000 --- a/gkeys/gkeysgpg/action.py +++ /dev/null @@ -1,52 +0,0 @@ -# -#-*- coding:utf-8 -*- - -""" - Gentoo-keys - gkeys-gpg/actions.py - - Primary api interface module - - @copyright: 2012 by Brian Dolbec <dol-sen@gentoo.org> - @license: GNU GPL2, see COPYING for details. -""" - -from __future__ import print_function - -import os -import sys - -if sys.version_info[0] >= 3: - py_input = input - _unicode = str -else: - py_input = raw_input - _unicode = unicode - - -from collections import defaultdict - -from snakeoil.demandload import demandload - -from gkeys.gkey import GKEY -from gkeys.checks import SPECCHECK_SUMMARY, convert_pf, convert_yn - -demandload( - "json:load", - "gkeys.lib:GkeysGPG", - "gkeys.seedhandler:SeedHandler", -) - - -EXTENSIONS = ['.sig', '.asc', '.gpg','.gpgsig'] - - -class Actions(object): - '''Primary API actions''' - - def __init__(self, config, output=None, logger=None): - self.config = config - self.output = output - self.logger = logger - self.seeds = None - - diff --git a/gkeys/gkeysgpg/actions.py b/gkeys/gkeysgpg/actions.py new file mode 100644 index 0000000..d06aaff --- /dev/null +++ b/gkeys/gkeysgpg/actions.py @@ -0,0 +1,91 @@ +# +#-*- coding:utf-8 -*- + +""" + Gentoo-keys - gkeys-gpg/actions.py + + Primary api interface module + + @copyright: 2012 by Brian Dolbec <dol-sen@gentoo.org> + @license: GNU GPL2, see COPYING for details. +""" + +from __future__ import print_function + +import os +import sys + +if sys.version_info[0] >= 3: + _unicode = str +else: + _unicode = unicode + + +from collections import OrderedDict + +from snakeoil.demandload import demandload + +from gkeys.gkey import GKEY + +demandload( + "json:load", + "gkeys.lib:GkeysGPG", + "gkeys.seedhandler:SeedHandler", +) + + +EXTENSIONS = ['.sig', '.asc', '.gpg','.gpgsig'] + +Action_Map = OrderedDict([ + ('sign', { + 'func': 'sign', + 'options': ['nick', 'name', 'fingerprint', ], + 'desc': '''Sign a file''', + 'long_desc': '''Sign a file with the designated gpg key. + The default sign settings can be set in gpg.conf. These settings can be + overridden on the command line using the 'nick', 'name', 'fingerprint' options''', + 'example': '''gkeys-gpg --sign foo''', + }), + ('verify', { + 'func': 'verify', + 'options': [], + 'desc': '''File automatic download and/or verification action.''', + 'long_desc': '''File automatic download and/or verification action. + Note: If the specified key/keyring to verify against does not contain + the key used to sign the file. It will Auto-search for the correct key + in the installed keys db. And verify against the matching key. + It will report the success/failure along with the key information used for + the verification''', + 'example': '''$ gkeys-gpg --verify foo''' + }), +]) + +Available_Actions = ['sign', 'verify'] + + +class Actions(object): + '''Primary API actions''' + + def __init__(self, config, output=None, logger=None): + self.config = config + self.output = output + self.logger = logger + self.seeds = None + + + def verify(self, args): + '''File verification action. + Note: If the specified key/keyring to verify against does not contain + the key used to sign the file. It will Auto-search for the correct key + in the installed keys db. And verify against the matching key.''' + + ''' + @param args: argparse.parse_args instance + ''' + print("Made it to the --verify option :)") + return (True, ['Completed']) + + def sign(self, args): + '''Sign a file''' + print("Made it to the --sign option :)") + return (True, ['Completed']) diff --git a/gkeys/gkeysgpg/cli.py b/gkeys/gkeysgpg/cli.py index 8a2dc26..15d765e 100644 --- a/gkeys/gkeysgpg/cli.py +++ b/gkeys/gkeysgpg/cli.py @@ -18,10 +18,9 @@ import sys from gkeys import __version__ from gkeys.base import CliBase -from gkeys.actions import Actions -from gkeys.action_map import Available_Actions, Action_Map +from gkeys.actions import Actions as gkeysActions from gkeys.config import GKeysConfig - +from gkeysgpg.actions import Actions, Available_Actions, Action_Map class Main(CliBase): @@ -38,15 +37,16 @@ class Main(CliBase): self.config = config or GKeysConfig(root=root) self.config.options['print_results'] = print_results self.cli_config = { - 'Actions': [], - 'Available_Actions': [], - 'Action_Map': [], - 'Base_Options': ['sign', 'verify'], + 'Actions': Actions, + 'Available_Actions': Available_Actions, + 'Action_Map': Action_Map, + 'Base_Options': Available_Actions, 'prog': 'gkeys-gpg', 'description': 'Gentoo-keys gpg command wrapper', 'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!''' } self.version = __version__ + self.need_Action = False def __call__(self, args=None): @@ -58,18 +58,33 @@ class Main(CliBase): if args: ok = self.setup(args, []) else: + #print(" *** __call__()") args = self.parse_args(sys.argv[1:]) + #print(" *** __call__(); parsed args") ok = self.setup(args, os.path.join(self.config['configdir'],'gkeys.conf')) if ok: return self.run(args) return False + def run(self, args): '''Run the gpg command option @param args: list of argumanets to parse ''' - self.logger.debug('Main: run; Found action: %s' % args.action) + # establish our actions instance + self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger) + + #print(" *** args:", args) + for action in self.cli_config['Available_Actions']: + if getattr(args, action): + #print(" *** found action", action) + break + + # run the action + func = getattr(self.actions, '%s' + % self.cli_config['Action_Map'][action]['func']) + self.logger.debug('Main: run; Found action: %s' % action) success, results = func(args) if not results: print("No results found. Check your configuration and that the", |