示例#1
0
 def _do_find_errors_in_response(self, response):
     results = response['epp']['response']['resData']['chkData']['cd']
     if not results:
         logger.error('unexpected EPP response, no results')
         return [
             zerrors.EPPResponseEmpty(),
         ]
     if not isinstance(results, list):
         results = [
             results,
         ]
     for result in results:
         if not result.get('name', {}).get('#text'):
             logger.error(
                 'unexpected EPP response, unknown domain name: %s' %
                 response)
             return [
                 zerrors.EPPResponseEmpty(),
             ]
         if result.get('name', {}).get('@avail') == '0':
             if not result.get('reason').lower().count('the domain exists'):
                 return [
                     zerrors.exception_from_response(response=response),
                 ]
     return []
示例#2
0
 def doReportExisting(self, event, *args, **kwargs):
     """
     Action method.
     """
     if event == 'skip-check':
         return
     existing_domains = []
     results = args[0]['epp']['response']['resData']['chkData']['cd']
     if not results:
         self.outputs.append(zerrors.EPPResponseEmpty())
         return
     if not isinstance(results, list):
         results = [
             results,
         ]
     for result in results:
         name = result.get('name', {}).get('#text')
         if not name:
             logger.error(
                 'unexpected EPP response, unknown domain name: %s' %
                 args[0])
             continue
         if result.get('name', {}).get('@avail') == '0':
             if result.get('reason').lower().count('the domain exists'):
                 existing_domains.append(name)
                 self.check_results[name] = True
             else:
                 self.check_results[name] = zerrors.exception_from_response(
                     response=args[0])
         else:
             self.check_results[name] = False
     self.outputs.append(existing_domains)
     self.outputs.append(args[0])
示例#3
0
 def doReportTransferFailed(self, event, *args, **kwargs):
     """
     Action method.
     """
     if event == 'error':
         self.outputs.append(args[0])
     else:
         self.outputs.append(zerrors.exception_from_response(response=args[0]))
示例#4
0
 def doReportFailed(self, event, *args, **kwargs):
     """
     Action method.
     """
     # TODO: log error in the history here
     if event == 'error':
         self.outputs.append(args[0])
     else:
         self.outputs.append(
             zerrors.exception_from_response(response=args[0]))
示例#5
0
 def doReportFailed(self, event, *args, **kwargs):
     """
     Action method.
     """
     if event in [
             'error',
             'verify-failed',
     ]:
         self.outputs.append(args[0])
     else:
         self.outputs.append(
             zerrors.exception_from_response(response=args[0]))
示例#6
0
def run(json_request, raise_for_result=True, unserialize=True, logs=True):
    try:
        json_input = json.dumps(json_request)
    except Exception as exc:
        logger.error('epp request failed, invalid json input')
        raise zerrors.EPPBadResponse('epp request failed, invalid json input')

    if logs:
        logger.info('>>> %s\n' % json_input)

    try:
        out = do_rpc_request(json_request)
    except zerrors.EPPError as exc:
        logger.error('epp request failed with known error: %s' % exc)
        raise exc
    except Exception as exc:
        logger.error('epp request failed, unexpected error: %s' %
                     traceback.format_exc())
        raise zerrors.EPPBadResponse('epp request failed: %s' % exc)

    if not out:
        logger.error('empty response from epp_gate, connection error')
        raise zerrors.EPPBadResponse(
            'epp request failed: empty response, connection error')

    json_output = None
    if unserialize:
        try:
            try:
                json_output = json.loads(
                    xml2json.xml2json(out,
                                      XML2JsonOptions(),
                                      strip_ns=1,
                                      strip=1))
            except UnicodeEncodeError:
                json_output = json.loads(
                    xml2json.xml2json(out.encode('ascii', errors='ignore'),
                                      XML2JsonOptions(),
                                      strip_ns=1,
                                      strip=1))
        except Exception as exc:
            logger.error('epp response unserialize failed: %s' %
                         traceback.format_exc())
            raise zerrors.EPPBadResponse(
                'epp response unserialize failed: %s' % exc)

    if raise_for_result:
        if json_output:
            try:
                code = json_output['epp']['response']['result']['@code']
                msg = json_output['epp']['response']['result']['msg'].replace(
                    'Command failed;', '')
            except:
                if logs:
                    logger.error('bad formatted response: ' + json_output)
                raise zerrors.EPPBadResponse(
                    'bad formatted response, response code not found')
            good_response_codes = [
                '1000',
            ]
            if True:  # just to be able to debug poll script packets
                good_response_codes.extend([
                    '1300',
                    '1301',
                ])
            if code not in good_response_codes:
                if logs:
                    logger.error('response code failed: ' +
                                 json.dumps(json_output, indent=2))
                epp_exc = zerrors.exception_from_response(response=json_output,
                                                          message=msg,
                                                          code=code)
                raise epp_exc
        else:
            if out.count('Command completed successfully') == 0:
                if logs:
                    logger.error('response message failed: ' +
                                 json.dumps(json_output, indent=2))
                raise zerrors.EPPResponseFailed('Command failed')

    if logs:
        logger.info('<<< %s\n' % json.dumps(json_output, indent=2))

    return json_output or out