Beispiel #1
0
    def post(self):
        """

    .. http:post::  /products

        This api will be used to send sku_data_import task to queue

        **Example request**:

        .. sourcecode:: http

           POST  /products  HTTP/1.1 HEADERS
           File

        **Example response**:

            {
                "message": "SUCCESS"
            }

        .. sourcecode:: http

           HTTP/1.1 200 OK
           Vary: Accept


        :statuscode 200: success
        :statuscode 400: bad request error

        """
        products_file = request.files["products_csv"]
        products_file_object = products_file.read()
        if not DepotManager._default_depot:
            DepotManager.configure(
                'default', {
                    'depot.backend': 'depot.io.boto3.S3Storage',
                    'depot.access_key_id': config.get('AWS_ACCESS_KEY', None),
                    'depot.secret_access_key': config.get(
                        'AWS_SECRET_KEY', None),
                    'depot.bucket': 'fulfilio-files',
                    'depot.region_name': 'eu-central-1'
                })
        csv_object = BulkCSVUploadMethods.create_record(
            dict(csv=products_file_object))
        db.commit()
        send_csv_import_task(csv_object.id)
        db.commit()
        return make_response(render_template('operations.html'), 200)
Beispiel #2
0
def register_account_api_endpoints(app, config, auth, log_hooks=[]):
    account_plugins = stethoscope.plugins.utils.instantiate_plugins(
        config, namespace='stethoscope.plugins.sources.accounts')

    if config.get('ENABLE_ACCOUNT_ENDPOINTS',
                  config['DEBUG']) and len(account_plugins.names()) > 0:
        account_plugins.map(_add_route,
                            app,
                            auth,
                            'account',
                            'email',
                            log_hooks=log_hooks)

    @auth.match_required
    @stethoscope.validation.check_valid_email
    def _merged_accounts(request, email, **_kwargs):
        userinfo = _kwargs.pop('userinfo')

        # required so that app.route can get a '__name__' attribute from decorated function
        _kwargs['callbacks'] = [
            functools.partial(log_response, 'account', 'merged'),
            functools.partial(
                log_access, 'account', userinfo, email, context='merged'),
        ] + [
            functools.partial(
                hook.obj.log, 'account', userinfo, email, context='merged')
            for hook in log_hooks
        ]
        return merged_accounts(request, email, account_plugins, **_kwargs)

    app.route('/accounts/merged/<string:email>',
              endpoint='accounts-merged',
              methods=['GET'])(_merged_accounts)
Beispiel #3
0
def register_feedback_api_endpoints(app, config, auth, csrf, log_hooks=[]):
  feedback_plugins = stethoscope.plugins.utils.instantiate_plugins(config,
      namespace='stethoscope.plugins.feedback')

  if config.get('ENABLE_FEEDBACK_ENDPOINTS', config['DEBUG']) \
      and len(feedback_plugins.names()) > 0:
    feedback_plugins.map(_add_post_route, app, config, auth, csrf, 'feedback')
Beispiel #4
0
  def setup_endpoint_kwargs(endpoint_type, args, kwargs):
    userinfo = kwargs.pop('userinfo')

    kwargs['callbacks'] = [transform.obj.transform for transform in transforms] + [
      functools.partial(log_response, 'device', endpoint_type),
      functools.partial(log_access, 'device', userinfo, *args),
    ] + [functools.partial(hook.obj.log, 'device', userinfo, *args) for hook in log_hooks]

    kwargs.setdefault('debug', config.get('DEBUG', False))
    return kwargs
Beispiel #5
0
  def __get_devices_by_stages(request, email, **_kwargs):
    userinfo = _kwargs.pop('userinfo')

    # required so that app.route can get a '__name__' attribute from decorated function
    _kwargs['callbacks'] = [transform.obj.transform for transform in transforms] + [
      functools.partial(log_response, 'device', 'staged'),
      functools.partial(log_access, 'device', userinfo, email, context='merged'),
    ] + [functools.partial(hook.obj.log, 'device', userinfo, email, context='merged')
        for hook in log_hooks]
    logger.debug("callbacks:\n{!s}", pprint.pformat(_kwargs['callbacks']))
    _kwargs.setdefault('debug', config.get('DEBUG', False))
    return merged_devices_by_stages(request, email, predevice_plugins, device_plugins, transforms,
        **_kwargs)
Beispiel #6
0
    def __get_devices_by_macaddr(request, macaddr, **_kwargs):
        userinfo = _kwargs.pop('userinfo')

        # required so that app.route can get a '__name__' attribute from decorated function
        _kwargs['callbacks'] = [
            filter_devices,
            functools.partial(log_response, 'device', 'macaddr'),
            functools.partial(log_access, 'device', userinfo, macaddr),
        ] + [
            functools.partial(hook.obj.log, 'device', userinfo, macaddr)
            for hook in log_hooks
        ]
        _kwargs.setdefault('debug', config.get('DEBUG', False))
        return merged_devices_by_macaddr(request, macaddr, device_plugins,
                                         **_kwargs)
Beispiel #7
0
def modules():
    ms = []
    m = lookup()
    config = readconfig()
    for mm in m:
        if mm in config.get('modeules', []):
            ms.append({'name': mm, 'status': True, 'des': ''})
        else:
            ms.append({'name': mm, 'status': False, 'des': ''})
    #m = ['482021','48tools','douyin','cookbook','szbus','48','BILI','Acfun','music','Imgbot','LiveBILI','weibo','一言','demo']
    return json.dumps(
        {
            'code': 200,
            'msg': '读取配置文件失败,仅列出所有模块,是否使用未知' if config == {} else '',
            'data': ms
        },
        ensure_ascii=False)
Beispiel #8
0
def register_device_api_endpoints(app, config, auth, log_hooks=[]):
    practices = stethoscope.plugins.utils.instantiate_practices(
        config, namespace='stethoscope.plugins.practices.devices')

    # for use by endpoints to apply each practice to each device
    def apply_practices(devices):
        for device in devices:
            practices.map_method('inject_status', device)
        return devices

    # transforms to apply to device lists
    transforms = stethoscope.plugins.utils.instantiate_plugins(
        config, namespace='stethoscope.plugins.transform.devices')

    # initial-stage plugins provide ownership attribution
    predevice_plugins = stethoscope.plugins.utils.instantiate_plugins(
        config, namespace='stethoscope.plugins.sources.predevices')

    if config.get('ENABLE_PREDEVICE_ENDPOINTS', config['DEBUG']) and \
        len(predevice_plugins.names()) > 0:
        # individual endpoints for each plugin for device lookup by mac, email, serial
        predevice_plugins.map(_add_route,
                              app,
                              auth,
                              'devices',
                              'email',
                              log_hooks=log_hooks)
        predevice_plugins.map(_add_route,
                              app,
                              auth,
                              'devices',
                              'macaddr',
                              log_hooks=log_hooks)
        predevice_plugins.map(_add_route,
                              app,
                              auth,
                              'devices',
                              'serial',
                              log_hooks=log_hooks)

    # instantiate the second-stage plugins which provide detailed device data
    device_plugins = stethoscope.plugins.utils.instantiate_plugins(
        config, namespace='stethoscope.plugins.sources.devices')

    if config.get('ENABLE_DEVICE_ENDPOINTS',
                  config['DEBUG']) and len(device_plugins.names()) > 0:
        # individual endpoints for each plugin for device lookup by mac, email, serial
        device_plugins.map(_add_route,
                           app,
                           auth,
                           'devices',
                           'email',
                           log_hooks=log_hooks)
        device_plugins.map(_add_route,
                           app,
                           auth,
                           'devices',
                           'macaddr',
                           log_hooks=log_hooks)
        device_plugins.map(_add_route,
                           app,
                           auth,
                           'devices',
                           'serial',
                           log_hooks=log_hooks)

        # 'merged' endpoints which merge device data across all second-stage device plugins
        # (without the initial ownership-attribution stage) for lookup by mac, email, serial
        register_merged_device_endpoints(app,
                                         config,
                                         auth,
                                         device_plugins,
                                         apply_practices,
                                         transforms=transforms,
                                         log_hooks=log_hooks)

    # primary device api endpoint ('merged' or 'staged') which merges device data across all
    # device plugins (both initial and second-stage)
    @serialized_endpoint(apply_practices,
                         stethoscope.api.devices.merge_devices)
    def merged_devices_by_stages(*args, **kwargs):
        """Endpoint returning (as JSON) all devices for given email (including second-stage lookups)."""
        return get_devices_by_stages(*args, **kwargs)

    @auth.match_required
    @stethoscope.validation.check_valid_email
    def __get_devices_by_stages(request, email, **_kwargs):
        userinfo = _kwargs.pop('userinfo')

        # required so that app.route can get a '__name__' attribute from decorated function
        _kwargs['callbacks'] = [
            transform.obj.transform for transform in transforms
        ] + [
            functools.partial(log_response, 'device', 'staged'),
            functools.partial(
                log_access, 'device', userinfo, email, context='merged'),
        ] + [
            functools.partial(
                hook.obj.log, 'device', userinfo, email, context='merged')
            for hook in log_hooks
        ]
        logger.debug("callbacks:\n{!s}", pprint.pformat(_kwargs['callbacks']))
        _kwargs.setdefault('debug', config.get('DEBUG', False))
        return merged_devices_by_stages(request, email, predevice_plugins,
                                        device_plugins, transforms, **_kwargs)

    app.route('/devices/staged/<string:email>',
              endpoint='devices-staged',
              methods=['GET'])(__get_devices_by_stages)
    app.route('/devices/merged/<string:email>',
              endpoint='devices-merged',
              methods=['GET'])(__get_devices_by_stages)
Beispiel #9
0
def init_app(app, env_name):
    app.config.from_object(config.get(env_name))