Skip to content

Commit

Permalink
Merge pull request gentoo#38 from gentoo/gkeys-gpg
Browse files Browse the repository at this point in the history
Gkeys-gpg
  • Loading branch information
dol-sen committed Aug 8, 2015
2 parents afee05b + 85357c2 commit 9de3098
Show file tree
Hide file tree
Showing 16 changed files with 708 additions and 179 deletions.
1 change: 1 addition & 0 deletions gkeys-gen/gkeygen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, root=None, config=None, print_results=True):
'Actions': Actions,
'Available_Actions': Available_Actions,
'Action_Map': Action_Map,
'Base_Options': [],
'prog': 'gkeys-gen',
'description': 'Gentoo Keys GPG key generator program',
'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!'''
Expand Down
1 change: 1 addition & 0 deletions gkeys-ldap/gkeyldap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, root=None, config=None, print_results=True):
'Actions': Actions,
'Available_Actions': Available_Actions,
'Action_Map': Action_Map,
'Base_Options': [],
'prog': 'gkeys-ldap',
'description': 'Gentoo-keys LDAP interface and seed file generator program',
'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!'''
Expand Down
56 changes: 56 additions & 0 deletions gkeys/bin/gkeys-gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/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 <[email protected]>
'''

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)
returncode = main()

sys.exit(returncode)
90 changes: 90 additions & 0 deletions gkeys/gkeys/actionbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
#-*- coding:utf-8 -*-

"""
Gentoo-keys - actionbase.py
Base api interface module
@copyright: 2012-2015 by Brian Dolbec <[email protected]>
@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 snakeoil.demandload import demandload

demandload(
"json:load",
"gkeys.lib:GkeysGPG",
"gkeys.keyhandler:KeyHandler",
)



class ActionBase(object):
'''Base actions class holding comon functions and init'''

def __init__(self, config, output=None, logger=None):
self.config = config
self.output = output
self.logger = logger
self.seeds = None
self._seedhandler = None
self._keyhandler = None
self._gpg = None
self.category = None


@property
def gpg(self):
'''Holds the classwide GkeysGPG instance'''
if not self._gpg:
self._gpg = GkeysGPG(self.config,
self._set_category(self.category), self.logger)
else:
self._gpg.basedir = self._set_category(self.category)
return self._gpg


@property
def keyhandler(self):
'''Holds the classwide KeyHandler instance'''
if not self._keyhandler:
self._init_keyhandler()
return self._keyhandler


def _init_keyhandler(self):
self._keyhandler = KeyHandler(self.config, self.logger)
self._seedhandler = self._keyhandler.seedhandler


@property
def seedhandler(self):
'''Holds the classwide SeedHandler instance
which is a convienience variable for the keyhandler's instance of it'''
if not self._seedhandler:
self._init_keyhandler()
return self._seedhandler


def _set_category(self, cat):
keyring = self.config.get_key('keyring')
if "foo-bar'd" in keyring:
raise
self.category = cat
catdir = os.path.join(keyring, cat)
self.logger.debug(_unicode("ACTIONS: _set_category; catdir = %s") % catdir)
return catdir


Loading

0 comments on commit 9de3098

Please sign in to comment.