def wsgi_execute(self, environ): result = None error = None _id = None lang = os.environ['LANG'] name = None args = () options = {} e = None if not 'HTTP_REFERER' in environ: return self.marshal(result, RefererError(referer='missing'), _id) if not environ['HTTP_REFERER'].startswith( 'https://%s/ipa' % self.api.env.host) and not self.env.in_tree: return self.marshal(result, RefererError(referer=environ['HTTP_REFERER']), _id) try: if ('HTTP_ACCEPT_LANGUAGE' in environ): lang_reg_w_q = environ['HTTP_ACCEPT_LANGUAGE'].split(',')[0] lang_reg = lang_reg_w_q.split(';')[0] lang_ = lang_reg.split('-')[0] if '-' in lang_reg: reg = lang_reg.split('-')[1].upper() else: reg = lang_.upper() os.environ['LANG'] = '%s_%s' % (lang_, reg) if (environ.get('CONTENT_TYPE', '').startswith(self.content_type) and environ['REQUEST_METHOD'] == 'POST'): data = read_input(environ) (name, args, options, _id) = self.unmarshal(data) else: (name, args, options, _id) = self.simple_unmarshal(environ) if name in self._system_commands: result = self._system_commands[name](self, *args, **options) elif name not in self.Command: raise CommandError(name=name) else: result = self.Command[name](*args, **options) except PublicError, e: if self.api.env.debug: self.debug('WSGI wsgi_execute PublicError: %s', traceback.format_exc()) error = e
def wsgi_execute(self, environ): result = None error = None _id = None name = None args = () options = {} command = None e = None if 'HTTP_REFERER' not in environ: return self.marshal(result, RefererError(referer='missing'), _id) if not environ['HTTP_REFERER'].startswith( 'https://%s/ipa' % self.api.env.host) and not self.env.in_tree: return self.marshal(result, RefererError(referer=environ['HTTP_REFERER']), _id) if self.api.env.debug: time_start = time.perf_counter_ns() try: if 'KRB5CCNAME' in environ: setattr(context, "ccache_name", environ['KRB5CCNAME']) if ('HTTP_ACCEPT_LANGUAGE' in environ): lang_reg_w_q = environ['HTTP_ACCEPT_LANGUAGE'].split(',')[0] lang_reg = lang_reg_w_q.split(';')[0] lang = lang_reg.split('-')[0] setattr(context, "languages", [lang]) if (environ.get('CONTENT_TYPE', '').startswith(self.content_type) and environ['REQUEST_METHOD'] == 'POST'): data = read_input(environ) (name, args, options, _id) = self.unmarshal(data) else: (name, args, options, _id) = self.simple_unmarshal(environ) if name in self._system_commands: result = self._system_commands[name](self, *args, **options) else: command = self._get_command(name) result = command(*args, **options) except PublicError as e: if self.api.env.debug: logger.debug('WSGI wsgi_execute PublicError: %s', traceback.format_exc()) error = e except Exception as e: logger.exception('non-public: %s: %s', e.__class__.__name__, str(e)) error = InternalError() finally: if hasattr(context, "languages"): delattr(context, "languages") principal = getattr(context, 'principal', 'UNKNOWN') if command is not None: try: params = command.args_options_2_params(*args, **options) except Exception as e: if self.api.env.debug: time_end = time.perf_counter_ns() logger.info('exception %s caught when converting options: %s', e.__class__.__name__, str(e)) # get at least some context of what is going on params = options error = e else: if self.api.env.debug: time_end = time.perf_counter_ns() if error: result_string = type(error).__name__ else: result_string = 'SUCCESS' logger.info('[%s] %s: %s(%s): %s', type(self).__name__, principal, name, ', '.join(command._repr_iter(**params)), result_string) if self.api.env.debug: logger.debug('[%s] %s: %s(%s): %s %s', type(self).__name__, principal, name, ', '.join(command._repr_iter(**params)), result_string, 'etime=' + str(time_end - time_start)) else: logger.info('[%s] %s: %s: %s', type(self).__name__, principal, name, type(error).__name__) version = options.get('version', VERSION_WITHOUT_CAPABILITIES) return self.marshal(result, error, _id, version)