Ejemplo n.º 1
0
    def execute(self, args):
        client = get_client_from_server_conf(args.path)
        request = {
            'return_internal': False,
            'include': args.include,
            'exclude': args.exclude,
        }

        response = client.invoke('zato.apispec.get-api-spec', request)
        data = response.data['response']['data']

        now = fs_safe_now()
        out_dir = '{}.{}'.format('apispec', now)
        out_dir = os.path.abspath(out_dir)
        os.mkdir(out_dir)

        for file_path, contents in data.items():
            full_file_path = os.path.join(out_dir, file_path)
            file_dir = os.path.abspath(os.path.dirname(full_file_path))
            try:
                os.makedirs(file_dir)
            except OSError:
                pass # Must have been already created
            finally:
                if contents:
                    f = open(full_file_path, 'w')
                    f.write(contents)
                    f.close()

        self.logger.info('Output saved to %s', out_dir)
Ejemplo n.º 2
0
def get_conn_info_from_path(path):
    """ Returns a Zato client basing on a path to a local server.
    """
    client = get_client_from_server_conf(path)

    # Just to be on the safe side
    client.invoke('zato.ping')

    pubapi_id = None

    # Get pubapi user or return None to signal that no connection info could be found
    for item in client.invoke('zato.security.get-list', {'cluster_id': client.cluster_id}).data:
        if item['username'] == 'pubapi':
            pubapi_id = item['id']
            break
    else:
        return None

    # Update password to a well-known one - there is no way to learn the previous one through the API
    password = uuid4().hex
    client.invoke('zato.security.basic-auth.change-password', {'id':pubapi_id, 'password1':password, 'password2':password})

    return {
        'ZATO_API_TEST_SERVER': client.address,
        'ZATO_API_TEST_PUBAPI_USER': '******',
        'ZATO_API_TEST_PUBAPI_PASSWORD': password,
        'ZATO_API_TEST_CLUSTER_ID': str(client.cluster_id)
        }
Ejemplo n.º 3
0
def get_conn_info_from_path(path):
    """ Returns a Zato client basing on a path to a local server.
    """
    client = get_client_from_server_conf(path)

    # Just to be on the safe side
    client.invoke('zato.ping')

    pubapi_id = None

    # Get pubapi user or return None to signal that no connection info could be found
    for item in client.invoke('zato.security.get-list', {'cluster_id': client.cluster_id}).data:
        if item['username'] == 'pubapi':
            pubapi_id = item['id']
            break
    else:
        return None

    # Update password to a well-known one - there is no way to learn the previous one through the API
    password = uuid4().hex
    client.invoke('zato.security.basic-auth.change-password', {'id':pubapi_id, 'password1':password, 'password2':password})

    return {
        'ZATO_API_TEST_SERVER': client.address,
        'ZATO_API_TEST_PUBAPI_USER': '******',
        'ZATO_API_TEST_PUBAPI_PASSWORD': password,
        'ZATO_API_TEST_CLUSTER_ID': str(client.cluster_id)
        }
Ejemplo n.º 4
0
Archivo: wait.py Proyecto: bip91/zato
    def execute(self, args, needs_sys_exit=True):
        # type: (Namespace)

        # We need to have a local or remote server on input ..
        if not (args.path or args.address):
            self.logger.warn('Exactly one of --path or --address is required (#1)')
            sys.exit(self.SYS_ERROR.INVALID_INPUT)


        # .. but we cannot have both of them at the same time.
        if args.path and args.address:
            self.logger.warn('Exactly one of --path or --address is required (#2)')
            sys.exit(self.SYS_ERROR.INVALID_INPUT)

        # We need to look up the server's address through its client ..
        if args.path:
            client = get_client_from_server_conf(args.path, False)
            address = client.address # type: str

        # .. unless we are given it explicitly.
        else:
            address = args.address # type: str

        # We can now wait for the server to respond
        is_success = wait_for_zato(address, args.url_path, int(args.timeout), float(args.interval))

        if not is_success:
            if needs_sys_exit:
                sys.exit(self.SYS_ERROR.SERVER_TIMEOUT)
            else:
                raise Exception('No response from `{}{}` after {}s'.format(address, args.url_path, args.timeout))
        else:
            return True
Ejemplo n.º 5
0
    def execute(self, args):
        client = get_client_from_server_conf(args.path)

        exclude = args.exclude.split(',') or []
        exclude = [elem.strip() for elem in exclude]

        if args.with_internal:
            for item in internal_patterns:
                try:
                    exclude.remove(item)
                except ValueError:
                    pass

        request = {
            'return_internal': args.with_internal,
            'include': args.include,
            'exclude': ','.join(exclude),
            'needs_api_invoke': args.with_api_invoke,
            'needs_rest_channels': args.with_rest_channels,
        }

        if args.with_api_invoke:
            request['api_invoke_path'] = args.api_invoke_path if args.api_invoke_path else '/zato/api/invoke/{service_name}'

        if not args.dir:
            now = fs_safe_now()
            out_dir = '{}.{}'.format('apispec', now)
        else:
            out_dir = args.dir

        out_dir = os.path.abspath(out_dir)

        if os.path.exists(out_dir):
            if args.delete_dir:
                self.logger.info('Deleting %s', out_dir)
                rmtree(out_dir)
            else:
                self.logger.warn('Output directory %s already exists and --delete-dir was not provided', out_dir)
                return

        os.mkdir(out_dir)

        response = client.invoke('zato.apispec.get-api-spec', request)
        data = response.data['response']['data']

        for file_path, contents in data.items():
            full_file_path = os.path.join(out_dir, file_path)
            file_dir = os.path.abspath(os.path.dirname(full_file_path))
            try:
                os.makedirs(file_dir)
            except OSError:
                pass # Must have been already created
            finally:
                if contents:
                    f = open(full_file_path, 'w')
                    f.write(contents)
                    f.close()

        self.logger.info('Output saved to %s', out_dir)
        self.logger.info('To build the documentation, run:\ncd %s\nmake html', out_dir)
Ejemplo n.º 6
0
    def execute(self, args):

        client = get_client_from_server_conf(args.path)

        headers = {}
        if args.headers:
            for pair in args.headers.strip().split(';'):
                k, v = pair.strip().split('=', 1)
                headers[k] = v

        # Prevents attempts to convert/escape XML into JSON
        to_json = True if args.data_format == DATA_FORMAT.JSON else False

        func = client.invoke_async if args. async else client.invoke
        response = func(args.name,
                        args.payload,
                        headers,
                        args.channel,
                        args.data_format,
                        args.transport,
                        to_json=to_json)

        if response.ok:
            self.logger.info(response.data or '(None)')
        else:
            self.logger.error(response.details)

        if args.verbose:
            self.logger.debug('inner.text:[{}]'.format(response.inner.text))
            self.logger.debug('response:[{}]'.format(response))