From 9a5bc5eb33c208da7abbc376d18bf17032be5286 Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 9 Sep 2013 16:29:07 -0600 Subject: [PATCH 1/2] Success field also in ret events Fixed user field in events changed __stamp__ to _stamp in events Conflicts: salt/master.py --- salt/master.py | 90 ++++++++++++++++++++++++++++++--------------- salt/runner.py | 2 +- salt/utils/event.py | 3 +- 3 files changed, 63 insertions(+), 32 deletions(-) diff --git a/salt/master.py b/salt/master.py index 4bb7f131a4..a02c7eec3a 100644 --- a/salt/master.py +++ b/salt/master.py @@ -1788,7 +1788,7 @@ class ClearFuncs(object): clear_load['fun']) if not good: msg = ('Authentication failure of type "token" occurred for ' - 'user {0}.').format(clear_load.get('username', 'UNKNOWN')) + 'user {0}.').format(token['name']) log.warning(msg) return '' @@ -1798,7 +1798,7 @@ class ClearFuncs(object): return runner_client.async( fun, clear_load.get('kwarg', {}), - clear_load.get('user', 'UNKNOWN')) + token['name']) except Exception as exc: log.error('Exception occurred while ' 'introspecting {0}: {1}'.format(fun, exc)) @@ -1842,7 +1842,7 @@ class ClearFuncs(object): runner_client = salt.runner.RunnerClient(self.opts) return runner_client.async(fun, clear_load.get('kwarg', {}), - clear_load.get('user', 'UNKNOWN')) + clear_load.get('username', 'UNKNOWN')) except Exception as exc: log.error('Exception occurred while ' 'introspecting {0}: {1}'.format(fun, exc)) @@ -1879,30 +1879,40 @@ class ClearFuncs(object): log.warning('Authentication failure of type "token" occurred.') return '' good = self.ckminions.wheel_check( - self.opts['external_auth'][token['eauth']][token['name']] if token['name'] in self.opts['external_auth'][token['eauth']] else self.opts['external_auth'][token['eauth']]['*'], + self.opts['external_auth'][token['eauth']][token['name']] \ + if token['name'] in self.opts['external_auth'][token['eauth']] \ + else self.opts['external_auth'][token['eauth']]['*'], clear_load['fun']) if not good: msg = ('Authentication failure of type "token" occurred for ' - 'user {0}.').format(token['user']) + 'user {0}.').format(token['name']) log.warning(msg) return '' + + jid = salt.utils.gen_jid() + fun = clear_load.pop('fun') + tag = tagify(jid, prefix='wheel') + data = {'fun': "wheel.{0}".format(fun), + 'jid': jid, + 'tag': tag, + 'user': token['name']} try: - log.debug('ClearFunc.wheel with {0}'.format(clear_load)) - jid = salt.utils.gen_jid() - fun = clear_load.pop('fun') - data = {'fun': "wheel.{0}".format(fun), - 'jid': jid, - 'user': token['name']} self.event.fire_event(data, tagify([jid, 'new'], 'wheel')) ret = self.wheel_.call_func(fun, **clear_load.get('kwarg', {})) data['ret'] = ret - self.event.fire_event(data, tagify([jid, 'ret'], 'wheel')) - return data + data['success'] = True + self.event.fire_event(data, tagify([jid, 'ret'], 'wheel')) + return tag except Exception as exc: log.error(exc) log.error('Exception occurred while ' 'introspecting {0}: {1}'.format(fun, exc)) - return '' + data['ret'] = 'Exception occured in wheel {0}: {1}'.format( + fun, + exc, + ) + self.event.fire_event(data, tagify([jid, 'ret'], 'wheel')) + return tag if 'eauth' not in clear_load: msg = ('Authentication failure of type "eauth" occurred for ' @@ -1918,7 +1928,8 @@ class ClearFuncs(object): try: name = self.loadauth.load_name(clear_load) - if not ((name in self.opts['external_auth'][clear_load['eauth']]) | ('*' in self.opts['external_auth'][clear_load['eauth']])): + if not ((name in self.opts['external_auth'][clear_load['eauth']]) | + ('*' in self.opts['external_auth'][clear_load['eauth']])): msg = ('Authentication failure of type "eauth" occurred for ' 'user {0}.').format(clear_load.get('username', 'UNKNOWN')) log.warning(msg) @@ -1929,29 +1940,39 @@ class ClearFuncs(object): log.warning(msg) return '' good = self.ckminions.wheel_check( - self.opts['external_auth'][clear_load['eauth']][name] if name in self.opts['external_auth'][clear_load['eauth']] else self.opts['external_auth'][token['eauth']]['*'], + self.opts['external_auth'][clear_load['eauth']][name] \ + if name in self.opts['external_auth'][clear_load['eauth']] \ + else self.opts['external_auth'][token['eauth']]['*'], clear_load['fun']) if not good: msg = ('Authentication failure of type "eauth" occurred for ' 'user {0}.').format(clear_load.get('username', 'UNKNOWN')) log.warning(msg) return '' - + + jid = salt.utils.gen_jid() + fun = clear_load.pop('fun') + tag = tagify(jid, prefix='wheel') + data = {'fun': "wheel.{0}".format(fun), + 'jid': jid, + 'tag': tag, + 'user': clear_load.get('username', 'UNKNOWN')} try: - jid = salt.utils.gen_jid() - fun = clear_load.pop('fun') - data = {'fun': "wheel.{0}".format(fun), - 'jid': jid, - 'user': clear_load.get('user', 'UNKNOWN')} self.event.fire_event(data, tagify([jid, 'new'], 'wheel')) ret = self.wheel_.call_func(fun, **clear_load.get('kwarg', {})) data['ret'] = ret + data['success'] = True self.event.fire_event(data, tagify([jid, 'ret'], 'wheel')) - return data + return tag except Exception as exc: log.error('Exception occurred while ' 'introspecting {0}: {1}'.format(fun, exc)) - return '' + data['ret'] = 'Exception occured in wheel {0}: {1}'.format( + fun, + exc, + ) + self.event.fire_event(data, tagify([jid, 'ret'], 'wheel')) + return tag except Exception as exc: log.error( @@ -1973,7 +1994,8 @@ class ClearFuncs(object): return '' try: name = self.loadauth.load_name(clear_load) - if not ((name in self.opts['external_auth'][clear_load['eauth']]) | ('*' in self.opts['external_auth'][clear_load['eauth']])): + if not ((name in self.opts['external_auth'][clear_load['eauth']]) | + ('*' in self.opts['external_auth'][clear_load['eauth']])): log.warning('Authentication failure of type "eauth" occurred.') return '' if not self.loadauth.time_auth(clear_load): @@ -2053,11 +2075,14 @@ class ClearFuncs(object): if token['eauth'] not in self.opts['external_auth']: log.warning('Authentication failure of type "token" occurred.') return '' - if not ((token['name'] in self.opts['external_auth'][token['eauth']]) | ('*' in self.opts['external_auth'][token['eauth']])): + if not ((token['name'] in self.opts['external_auth'][token['eauth']]) | + ('*' in self.opts['external_auth'][token['eauth']])): log.warning('Authentication failure of type "token" occurred.') return '' good = self.ckminions.auth_check( - self.opts['external_auth'][token['eauth']][token['name']] if token['name'] in self.opts['external_auth'][token['eauth']] else self.opts['external_auth'][token['eauth']]['*'], + self.opts['external_auth'][token['eauth']][token['name']] \ + if token['name'] in self.opts['external_auth'][token['eauth']] \ + else self.opts['external_auth'][token['eauth']]['*'], clear_load['fun'], clear_load['tgt'], clear_load.get('tgt_type', 'glob')) @@ -2068,6 +2093,8 @@ class ClearFuncs(object): 'Authentication failure of type "token" occurred.' ) return '' + clear_load['user'] = token['name'] + log.debug('Minion tokenized user = "{0}"'.format(clear_load['user'])) elif 'eauth' in extra: if extra['eauth'] not in self.opts['external_auth']: # The eauth system is not enabled, fail @@ -2077,7 +2104,8 @@ class ClearFuncs(object): return '' try: name = self.loadauth.load_name(extra) - if not ((name in self.opts['external_auth'][extra['eauth']]) | ('*' in self.opts['external_auth'][extra['eauth']])): + if not ((name in self.opts['external_auth'][extra['eauth']]) | + ('*' in self.opts['external_auth'][extra['eauth']])): log.warning( 'Authentication failure of type "eauth" occurred.' ) @@ -2093,7 +2121,9 @@ class ClearFuncs(object): ) return '' good = self.ckminions.auth_check( - self.opts['external_auth'][extra['eauth']][name] if name in self.opts['external_auth'][extra['eauth']] else self.opts['external_auth'][extra['eauth']]['*'], + self.opts['external_auth'][extra['eauth']][name] \ + if name in self.opts['external_auth'][extra['eauth']] \ + else self.opts['external_auth'][extra['eauth']]['*'], clear_load['fun'], clear_load['tgt'], clear_load.get('tgt_type', 'glob')) @@ -2104,7 +2134,7 @@ class ClearFuncs(object): 'Authentication failure of type "eauth" occurred.' ) return '' - clear_load['user'] = self.loadauth.load_name(extra) + clear_load['user'] = name # Verify that the caller has root on master elif 'user' in clear_load: if clear_load['user'].startswith('sudo_'): diff --git a/salt/runner.py b/salt/runner.py index a17e5e1dc1..3793862bf9 100644 --- a/salt/runner.py +++ b/salt/runner.py @@ -111,7 +111,7 @@ class RunnerClient(object): def master_call(self, **kwargs): ''' - Send a function call to a wheel module through the master network + Send a function call to a runner module through the master network interface. Expects that one of the kwargs is key 'fun' whose value is the namestring of the function to call. diff --git a/salt/utils/event.py b/salt/utils/event.py index 5c413b1d6b..9b279d19d2 100644 --- a/salt/utils/event.py +++ b/salt/utils/event.py @@ -264,7 +264,7 @@ class SaltEvent(object): if not self.cpush: self.connect_pull() - data['__stamp__'] = datetime.datetime.now().isoformat('_') + data['_stamp'] = datetime.datetime.now().isoformat('_') tagend = '' if len(tag) <= 20: # old style compatible tag @@ -318,6 +318,7 @@ class SaltEvent(object): data['success'] = False data['return'] = 'Error: {0}.{1}'.format(tags[0], tags[-1]) data['fun'] = load['fun'] + data['user'] = load['user'] self.fire_event( data, tagify([load['jid'], From c446e1dbd3e43ae7ec93249f720549810aa816ca Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Wed, 11 Sep 2013 16:52:34 -0600 Subject: [PATCH 2/2] added .DS_Store --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 121e1ce336..64092f84a5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ MANIFEST *# *.wpr *.wpu +*.DS_Store # virtualenv # - ignores directories of a virtualenv when you create it right on