Merge pull request #7195 from SmithSamuelM/tempdevelop

Fixed user in event data for wheel jobs. Also adding success field on successful returns
This commit is contained in:
Samuel Smith 2013-09-12 09:45:29 -07:00
commit a658610d75
4 changed files with 64 additions and 32 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ MANIFEST
*#
*.wpr
*.wpu
*.DS_Store
# virtualenv
# - ignores directories of a virtualenv when you create it right on

View File

@ -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_'):

View File

@ -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.

View File

@ -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'],