aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgkeys/bin/gkeys-gpg57
-rw-r--r--gkeys/gkeysgpg/action.py52
-rw-r--r--gkeys/gkeysgpg/cli.py114
3 files changed, 223 insertions, 0 deletions
diff --git a/gkeys/bin/gkeys-gpg b/gkeys/bin/gkeys-gpg
new file mode 100755
index 0000000..bf919de
--- /dev/null
+++ b/gkeys/bin/gkeys-gpg
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+'''Gentoo-keys is a gpg key manager for managing
+ gentoo's gpg-signing keys. It is these keys that are
+ used to verify and validate release media, etc..
+
+ This gkeys-gpg command is a wrapper to gnupg's gpg command
+ which uses the gentoo-keys keyring system to control the
+ keydirs and keyrings visible to gpg
+
+ Distributed under the terms of the GNU General Public License v2
+
+ Copyright:
+ (c) 2011 Brian Dolbec
+ Distributed under the terms of the GNU General Public License v2
+
+ Author(s):
+ Brian Dolbec <dolsen@gentoo.org>
+
+'''
+
+from __future__ import print_function
+
+from gkeysgpg.cli import Main
+
+import os
+import sys
+
+
+# This block ensures that ^C interrupts are handled quietly.
+try:
+ import signal
+
+ def exithandler(signum,frame):
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
+ signal.signal(signal.SIGTERM, signal.SIG_IGN)
+ print()
+ sys.exit(1)
+
+ signal.signal(signal.SIGINT, exithandler)
+ signal.signal(signal.SIGTERM, exithandler)
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+except KeyboardInterrupt:
+ print()
+ sys.exit(1)
+
+root = None
+if 'ROOT' in os.environ:
+ root = os.environ['ROOT']
+
+main = Main(root=root)
+success = main()
+
+# exit is boolean opposite normal True/False
+sys.exit(not success)
diff --git a/gkeys/gkeysgpg/action.py b/gkeys/gkeysgpg/action.py
new file mode 100644
index 0000000..7eac144
--- /dev/null
+++ b/gkeys/gkeysgpg/action.py
@@ -0,0 +1,52 @@
+#
+#-*- 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/cli.py b/gkeys/gkeysgpg/cli.py
new file mode 100644
index 0000000..8a2dc26
--- /dev/null
+++ b/gkeys/gkeysgpg/cli.py
@@ -0,0 +1,114 @@
+#
+#-*- coding:utf-8 -*-
+
+"""
+ Gentoo-keys - cli.py
+
+ Command line 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
+
+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.config import GKeysConfig
+
+
+
+class Main(CliBase):
+ '''Main command line interface class'''
+
+
+ def __init__(self, root=None, config=None, print_results=True):
+ """ Main class init function.
+
+ @param root: string, root path to use
+ """
+ CliBase.__init__(self)
+ self.root = root or "/"
+ 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'],
+ 'prog': 'gkeys-gpg',
+ 'description': 'Gentoo-keys gpg command wrapper',
+ 'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!'''
+ }
+ self.version = __version__
+
+
+ def __call__(self, args=None):
+ """Main class call function
+
+ @param args: Optional list of argumanets to parse and action to run
+ Defaults to sys.argv[1:]
+ """
+ if args:
+ ok = self.setup(args, [])
+ else:
+ args = self.parse_args(sys.argv[1:])
+ 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)
+ success, results = func(args)
+ if not results:
+ print("No results found. Check your configuration and that the",
+ "seed file exists.")
+ return success
+ if self.config.options['print_results'] and 'done' not in list(results):
+ self.output_results(results, '\n Gkey task results:')
+ return success
+
+
+ @staticmethod
+ def _option_blank(parser=None):
+ parser.add_argument('-', '--', dest='blank', nargs='', default=None,
+ help='fill me in')
+
+
+ @staticmethod
+ def _option_clearsign(parser=None):
+ parser.add_argument('--clearsign', dest='clearsign', default=None,
+ help='make a clear text signature')
+
+
+ @staticmethod
+ def _option_detachsign(parser=None):
+ parser.add_argument('-b', '--detach-sign', dest='detachsign', default=None,
+ help='make a detached signature')
+
+
+ @staticmethod
+ def _option_sign(parser=None):
+ parser.add_argument('-s', '--sign', dest='sign', default=None,
+ help='make a signature')
+
+
+ @staticmethod
+ def _option_verify(parser=None):
+ parser.add_argument('--verify', dest='verify', default=None,
+ help='verify a signature')
+
+
+
+