1 |
commit: 706d8a250a5b915799daa89758ffaac98ca17786 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jul 25 10:50:31 2015 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Jul 25 10:50:31 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=706d8a25 |
7 |
|
8 |
gkeysgpg: Get the initail cli operations working with stubbed out Actions |
9 |
|
10 |
gkeys/gkeysgpg/action.py | 52 --------------------------- |
11 |
gkeys/gkeysgpg/actions.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++ |
12 |
gkeys/gkeysgpg/cli.py | 31 +++++++++++----- |
13 |
3 files changed, 114 insertions(+), 60 deletions(-) |
14 |
|
15 |
diff --git a/gkeys/gkeysgpg/action.py b/gkeys/gkeysgpg/action.py |
16 |
deleted file mode 100644 |
17 |
index 7eac144..0000000 |
18 |
--- a/gkeys/gkeysgpg/action.py |
19 |
+++ /dev/null |
20 |
@@ -1,52 +0,0 @@ |
21 |
-# |
22 |
-#-*- coding:utf-8 -*- |
23 |
- |
24 |
-""" |
25 |
- Gentoo-keys - gkeys-gpg/actions.py |
26 |
- |
27 |
- Primary api interface module |
28 |
- |
29 |
- @copyright: 2012 by Brian Dolbec <dol-sen@g.o> |
30 |
- @license: GNU GPL2, see COPYING for details. |
31 |
-""" |
32 |
- |
33 |
-from __future__ import print_function |
34 |
- |
35 |
-import os |
36 |
-import sys |
37 |
- |
38 |
-if sys.version_info[0] >= 3: |
39 |
- py_input = input |
40 |
- _unicode = str |
41 |
-else: |
42 |
- py_input = raw_input |
43 |
- _unicode = unicode |
44 |
- |
45 |
- |
46 |
-from collections import defaultdict |
47 |
- |
48 |
-from snakeoil.demandload import demandload |
49 |
- |
50 |
-from gkeys.gkey import GKEY |
51 |
-from gkeys.checks import SPECCHECK_SUMMARY, convert_pf, convert_yn |
52 |
- |
53 |
-demandload( |
54 |
- "json:load", |
55 |
- "gkeys.lib:GkeysGPG", |
56 |
- "gkeys.seedhandler:SeedHandler", |
57 |
-) |
58 |
- |
59 |
- |
60 |
-EXTENSIONS = ['.sig', '.asc', '.gpg','.gpgsig'] |
61 |
- |
62 |
- |
63 |
-class Actions(object): |
64 |
- '''Primary API actions''' |
65 |
- |
66 |
- def __init__(self, config, output=None, logger=None): |
67 |
- self.config = config |
68 |
- self.output = output |
69 |
- self.logger = logger |
70 |
- self.seeds = None |
71 |
- |
72 |
- |
73 |
|
74 |
diff --git a/gkeys/gkeysgpg/actions.py b/gkeys/gkeysgpg/actions.py |
75 |
new file mode 100644 |
76 |
index 0000000..d06aaff |
77 |
--- /dev/null |
78 |
+++ b/gkeys/gkeysgpg/actions.py |
79 |
@@ -0,0 +1,91 @@ |
80 |
+# |
81 |
+#-*- coding:utf-8 -*- |
82 |
+ |
83 |
+""" |
84 |
+ Gentoo-keys - gkeys-gpg/actions.py |
85 |
+ |
86 |
+ Primary api interface module |
87 |
+ |
88 |
+ @copyright: 2012 by Brian Dolbec <dol-sen@g.o> |
89 |
+ @license: GNU GPL2, see COPYING for details. |
90 |
+""" |
91 |
+ |
92 |
+from __future__ import print_function |
93 |
+ |
94 |
+import os |
95 |
+import sys |
96 |
+ |
97 |
+if sys.version_info[0] >= 3: |
98 |
+ _unicode = str |
99 |
+else: |
100 |
+ _unicode = unicode |
101 |
+ |
102 |
+ |
103 |
+from collections import OrderedDict |
104 |
+ |
105 |
+from snakeoil.demandload import demandload |
106 |
+ |
107 |
+from gkeys.gkey import GKEY |
108 |
+ |
109 |
+demandload( |
110 |
+ "json:load", |
111 |
+ "gkeys.lib:GkeysGPG", |
112 |
+ "gkeys.seedhandler:SeedHandler", |
113 |
+) |
114 |
+ |
115 |
+ |
116 |
+EXTENSIONS = ['.sig', '.asc', '.gpg','.gpgsig'] |
117 |
+ |
118 |
+Action_Map = OrderedDict([ |
119 |
+ ('sign', { |
120 |
+ 'func': 'sign', |
121 |
+ 'options': ['nick', 'name', 'fingerprint', ], |
122 |
+ 'desc': '''Sign a file''', |
123 |
+ 'long_desc': '''Sign a file with the designated gpg key. |
124 |
+ The default sign settings can be set in gpg.conf. These settings can be |
125 |
+ overridden on the command line using the 'nick', 'name', 'fingerprint' options''', |
126 |
+ 'example': '''gkeys-gpg --sign foo''', |
127 |
+ }), |
128 |
+ ('verify', { |
129 |
+ 'func': 'verify', |
130 |
+ 'options': [], |
131 |
+ 'desc': '''File automatic download and/or verification action.''', |
132 |
+ 'long_desc': '''File automatic download and/or verification action. |
133 |
+ Note: If the specified key/keyring to verify against does not contain |
134 |
+ the key used to sign the file. It will Auto-search for the correct key |
135 |
+ in the installed keys db. And verify against the matching key. |
136 |
+ It will report the success/failure along with the key information used for |
137 |
+ the verification''', |
138 |
+ 'example': '''$ gkeys-gpg --verify foo''' |
139 |
+ }), |
140 |
+]) |
141 |
+ |
142 |
+Available_Actions = ['sign', 'verify'] |
143 |
+ |
144 |
+ |
145 |
+class Actions(object): |
146 |
+ '''Primary API actions''' |
147 |
+ |
148 |
+ def __init__(self, config, output=None, logger=None): |
149 |
+ self.config = config |
150 |
+ self.output = output |
151 |
+ self.logger = logger |
152 |
+ self.seeds = None |
153 |
+ |
154 |
+ |
155 |
+ def verify(self, args): |
156 |
+ '''File verification action. |
157 |
+ Note: If the specified key/keyring to verify against does not contain |
158 |
+ the key used to sign the file. It will Auto-search for the correct key |
159 |
+ in the installed keys db. And verify against the matching key.''' |
160 |
+ |
161 |
+ ''' |
162 |
+ @param args: argparse.parse_args instance |
163 |
+ ''' |
164 |
+ print("Made it to the --verify option :)") |
165 |
+ return (True, ['Completed']) |
166 |
+ |
167 |
+ def sign(self, args): |
168 |
+ '''Sign a file''' |
169 |
+ print("Made it to the --sign option :)") |
170 |
+ return (True, ['Completed']) |
171 |
|
172 |
diff --git a/gkeys/gkeysgpg/cli.py b/gkeys/gkeysgpg/cli.py |
173 |
index 8a2dc26..15d765e 100644 |
174 |
--- a/gkeys/gkeysgpg/cli.py |
175 |
+++ b/gkeys/gkeysgpg/cli.py |
176 |
@@ -18,10 +18,9 @@ import sys |
177 |
|
178 |
from gkeys import __version__ |
179 |
from gkeys.base import CliBase |
180 |
-from gkeys.actions import Actions |
181 |
-from gkeys.action_map import Available_Actions, Action_Map |
182 |
+from gkeys.actions import Actions as gkeysActions |
183 |
from gkeys.config import GKeysConfig |
184 |
- |
185 |
+from gkeysgpg.actions import Actions, Available_Actions, Action_Map |
186 |
|
187 |
|
188 |
class Main(CliBase): |
189 |
@@ -38,15 +37,16 @@ class Main(CliBase): |
190 |
self.config = config or GKeysConfig(root=root) |
191 |
self.config.options['print_results'] = print_results |
192 |
self.cli_config = { |
193 |
- 'Actions': [], |
194 |
- 'Available_Actions': [], |
195 |
- 'Action_Map': [], |
196 |
- 'Base_Options': ['sign', 'verify'], |
197 |
+ 'Actions': Actions, |
198 |
+ 'Available_Actions': Available_Actions, |
199 |
+ 'Action_Map': Action_Map, |
200 |
+ 'Base_Options': Available_Actions, |
201 |
'prog': 'gkeys-gpg', |
202 |
'description': 'Gentoo-keys gpg command wrapper', |
203 |
'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!''' |
204 |
} |
205 |
self.version = __version__ |
206 |
+ self.need_Action = False |
207 |
|
208 |
|
209 |
def __call__(self, args=None): |
210 |
@@ -58,18 +58,33 @@ class Main(CliBase): |
211 |
if args: |
212 |
ok = self.setup(args, []) |
213 |
else: |
214 |
+ #print(" *** __call__()") |
215 |
args = self.parse_args(sys.argv[1:]) |
216 |
+ #print(" *** __call__(); parsed args") |
217 |
ok = self.setup(args, os.path.join(self.config['configdir'],'gkeys.conf')) |
218 |
if ok: |
219 |
return self.run(args) |
220 |
return False |
221 |
|
222 |
+ |
223 |
def run(self, args): |
224 |
'''Run the gpg command option |
225 |
|
226 |
@param args: list of argumanets to parse |
227 |
''' |
228 |
- self.logger.debug('Main: run; Found action: %s' % args.action) |
229 |
+ # establish our actions instance |
230 |
+ self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger) |
231 |
+ |
232 |
+ #print(" *** args:", args) |
233 |
+ for action in self.cli_config['Available_Actions']: |
234 |
+ if getattr(args, action): |
235 |
+ #print(" *** found action", action) |
236 |
+ break |
237 |
+ |
238 |
+ # run the action |
239 |
+ func = getattr(self.actions, '%s' |
240 |
+ % self.cli_config['Action_Map'][action]['func']) |
241 |
+ self.logger.debug('Main: run; Found action: %s' % action) |
242 |
success, results = func(args) |
243 |
if not results: |
244 |
print("No results found. Check your configuration and that the", |