Esempio n. 1
0
    def validate(func, self, *args, **kwargs):
        ''' function that calls authrozing function'''

        isAuthEnabled = True
        isPkiEnabled = False
        authPassed = False

        try:
            appGlobal = config['pylons.app_globals']

            isAuthEnabled = configutil.getConfigAsBool('basicauth.local')
            isPkiEnabled = (appGlobal.encryptedtokens
                            and configutil.getConfigAsBool('pkiauth_enabled'))

        except BaseException as excep:
            LOG.error('Error loading auth config %s - %s' %
                      (str(excep), traceback.format_exc(2)))

        if isAuthEnabled:

            if 'Authorization' not in request.headers and 'authorization' not in request.headers:
                return invalidAuthHandler('Authorization header missing', {})

            message = None
            result = {}

            # base authentication
            if not isPkiEnabled:
                token = ('%s:%s' % (configutil.getConfig('username.local'),
                                    configutil.getConfig('password.local')))
                try:
                    isAuthenticated(token)
                    authPassed = True
                except UnauthorizedException:
                    message = 'Please provide valid username and password'
                    result['scheme'] = 'base'

            if not authPassed:
                # pki authentication
                token = appGlobal.authztoken
                try:
                    isAuthenticated(token)
                    authPassed = True
                except UnauthorizedException:
                    if isPkiEnabled:
                        result['scheme'] = 'pki'
                        user = request.headers[
                            'AuthorizationUser'] if 'AuthorizationUser' in request.headers else 'agent'
                        pubKey = '%s.cert' % user
                        if pubKey in appGlobal.encryptedtokens:
                            message = appGlobal.encryptedtokens[pubKey]
                            result['key'] = appGlobal.encryptedtokens[pubKey]
                        else:
                            message = 'Unknown AuthroizationUser %s' % user

                    return invalidAuthHandler(message, result)

        return func(self, *args, **kwargs)
Esempio n. 2
0
    def validate(func, self, *args, **kwargs):
        ''' function that calls authrozing function'''
        
        isAuthEnabled = True
        isPkiEnabled = False
        authPassed = False
        
        try:
            appGlobal = config['pylons.app_globals']

            isAuthEnabled = configutil.getConfigAsBool('basicauth.local')
            isPkiEnabled = (appGlobal.encryptedtokens and configutil.getConfigAsBool('pkiauth_enabled'))
        
        except BaseException as excep:
            LOG.error('Error loading auth config %s - %s' % (str(excep), traceback.format_exc(2)))
            
        if isAuthEnabled:
            
            if 'Authorization' not in request.headers and 'authorization' not in request.headers:
                return invalidAuthHandler('Authorization header missing', {})

            message = None
            result = {}
            
            # base authentication
            if not isPkiEnabled:
                token = ('%s:%s' % (configutil.getConfig('username.local'), configutil.getConfig('password.local')))
                try:
                    isAuthenticated(token)
                    authPassed = True
                except UnauthorizedException:
                    message = 'Please provide valid username and password'
                    result['scheme'] = 'base'
                
            if not authPassed:
                # pki authentication
                token = appGlobal.authztoken 
                try: 
                    isAuthenticated(token)
                    authPassed = True
                except UnauthorizedException:
                    if isPkiEnabled:
                        result['scheme'] = 'pki'
                        user = request.headers['AuthorizationUser'] if 'AuthorizationUser' in request.headers else 'agent'  
                        pubKey = '%s.cert' % user 
                        if pubKey in appGlobal.encryptedtokens:
                            message = appGlobal.encryptedtokens[pubKey]
                            result['key'] = appGlobal.encryptedtokens[pubKey]
                        else:
                            message = 'Unknown AuthroizationUser %s' % user

                    return invalidAuthHandler(message, result)

        return func(self, *args, **kwargs)
Esempio n. 3
0
    def selfupdate(self):
        """ agent selfupdate through api
        """
        LOG.info('selfupdate agent with body: %s', request.body)
        try:
            appGlobal = config['pylons.app_globals']
            wisbVersion = None
            wisbSource = None

            if request.body:
                requestjson = json.loads(request.body)
                if 'version' not in requestjson:
                    raise AgentException(Errors.INVALID_REQUEST, 'version is required')
                
                wisbVersion = requestjson['version']
                wisbSource = requestjson['wisbSource'] if 'wisbSource' in requestjson else configutil.getConfig('selfupdate_source')

            updateThread = AgentUpdate(appGlobal.threadMgr, wisbVersion, wisbSource)
            self.injectJobCtx(updateThread)

            updateThread.start()
            updateThread.threadMgrEvent.wait()

            return statusResult(request, response, updateThread, controller = self)

        except AgentException as aexcep:
            return errorResult(request, response, error = aexcep.getCode(),
                               errorMsg = aexcep.getMsg(), controller = self)

        except Exception as excep:
            msg = 'Unknown error for agent update(%s) - %s - %s' % (wisbVersion, str(excep), traceback.format_exc(2))
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = msg, controller = self)
Esempio n. 4
0
    def selfupdate(self):
        """ agent selfupdate through api
        """
        LOG.info('selfupdate agent with body: %s', request.body)
        try:
            appGlobal = config['pylons.app_globals']
            wisbVersion = None
            wisbSource = None

            if request.body:
                requestjson = json.loads(request.body)
                if 'version' not in requestjson:
                    raise AgentException(Errors.INVALID_REQUEST, 'version is required')
                
                wisbVersion = requestjson['version']
                wisbSource = requestjson['wisbSource'] if 'wisbSource' in requestjson else configutil.getConfig('selfupdate_source')
                skipProp = asbool(requestjson['skipProp']) if 'skipProp' in requestjson else True

            updateThread = AgentUpdate(appGlobal.threadMgr, wisbVersion, wisbSource, skipProp = skipProp)
            self.injectJobCtx(updateThread)

            updateThread.start()
            updateThread.threadMgrEvent.wait()

            return statusResult(request, response, updateThread, controller = self)

        except AgentException as aexcep:
            return errorResult(request, response, error = aexcep.getCode(),
                               errorMsg = aexcep.getMsg(), controller = self)

        except Exception as excep:
            msg = 'Unknown error for agent update(%s) - %s - %s' % (wisbVersion, str(excep), traceback.format_exc(2))
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = msg, controller = self)