def user_check(ko_value): try: username = input('Enter username with admin privileges: ') password = getpass.getpass('Enter password: '******'change': new_owner = ko_value[4] if new_owner: userlist = auth.getUser(name=new_owner) if not userlist: print('New owner ' + new_owner + ' not found in splunk') sys.exit(1) return session_key except: raise
def is_app_admin(self, app, user): ''' used to determine app administrator membership necessary because splunkd auth does not advertise inherited roles ''' sub_roles = [] admin_list = app.entity['eai:acl']['perms']['write'] if '*' in admin_list: return True for role in auth.getUser(name=user)['roles']: if role in admin_list: return True sub_roles.append(role) for role in sub_roles: for irole in auth.getRole(name=role)['imported_roles']: if irole in admin_list: return True return False
try: return handleShowConf(restArgList['name'], sessionKey, namespace, owner) except splunk.ResourceNotFound: #can throw this error if we try and show a non-existent config displayResourceError(cmd=cmd, obj=obj, uri=restArgList['name'], serverContent=None) return #show:default-index has already been done for us, reuse it elif '%s:%s' % (cmd, obj) == 'show:default-index': defIndexList = [] try: #first get the role associated with this user roles = auth.getUser(auth.getCurrentUser()['name'], sessionKey=sessionKey)['roles'] #get details of each role for role in roles: indexes = auth.getRole( role, sessionKey=sessionKey)['srchIndexesDefault'] for index in indexes: defIndexList.append(index) except: pass DISPLAY_CHARS[endpoint](cmd=cmd, obj=obj, sessionKey=sessionKey, defIndex=defIndexList) #handle sync/async search elif cmd in ['search', 'dispatch']:
if cmd == 'help': return handleHelp(endpoint, restArgList) #extraction of properties has already been written for us, so reuse it elif '%s:%s' % (cmd,obj) == 'show:config': try: return handleShowConf(restArgList['name'], sessionKey, namespace, owner) except splunk.ResourceNotFound: #can throw this error if we try and show a non-existent config displayResourceError(cmd=cmd, obj=obj, uri=restArgList['name'], serverContent=None) return #show:default-index has already been done for us, reuse it elif '%s:%s' % (cmd,obj) == 'show:default-index': defIndexList = [] try: #first get the role associated with this user roles = auth.getUser(auth.getCurrentUser()['name'], sessionKey=sessionKey)['roles'] #get details of each role for role in roles: indexes = auth.getRole(role, sessionKey=sessionKey)['srchIndexesDefault'] for index in indexes: defIndexList.append(index) except: pass DISPLAY_CHARS[endpoint](cmd=cmd, obj=obj, sessionKey=sessionKey, defIndex=defIndexList) #handle sync/async search elif cmd in ['search', 'dispatch']: if not restArgList['terms'].strip(): displayGenericError(cmd=cmd, terms='') return if restArgList.has_key('detach') and restArgList['detach'] == 'true':