aboutsummaryrefslogtreecommitdiff
blob: d06aaffef27ab492e11efab6ef79b2a219bb17f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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'])