コード例 #1
0
class ProductApi(Resource):
    findByIdPermissions = lambda f: admin_required(
        f,
        roles=[
            'ROLE_ADMIN', 'ROLE_PRODUCTS_READ'
            'ROLE_PRODUCTS_SAVE', 'SCOPE_openid'
        ])

    savePermissions = lambda f: admin_required(
        f, roles=['ROLE_ADMIN', 'ROLE_PRODUCTS_SAVE', 'SCOPE_openid'])

    deletePermissions = lambda f: admin_required(
        f, roles=['ROLE_ADMIN', 'ROLE_PRODUCTS_DELETE', 'SCOPE_openid'])
    """Update product"""
    @savePermissions
    @ns.doc(params={'id': 'An ID'},
            description='Update product',
            responses={
                200: 'Updated Successfully',
                400: 'Validation Error',
                401: 'Unauthorized',
                403: 'Forbidden',
                500: 'Unexpected Error'
            })
    @ns.expect(productModel)
    @tracing.trace()
    def put(self, id):
        user_id = get_jwt_identity()
        product = Product.objects.get(id=id)
        body = request.get_json()
        product.lastModifiedDate = datetime.datetime.utcnow()
        product.lastModifiedByUser = user_id
        product.update(**body)
        return Response(Product.objects.get(id=id).to_json(),
                        mimetype="application/json",
                        status=200)

    """Delete product"""

    @deletePermissions
    @ns.doc(description='Delete product',
            responses={
                200: 'Deleted Successfully',
                400: 'Validation Error',
                401: 'Unauthorized',
                403: 'Forbidden',
                500: 'Unexpected Error'
            })
    @tracing.trace()
    def delete(self, id):
        user_id = get_jwt_identity()
        movie = Product.objects.get(id=id)
        movie.delete()
        return make_response(jsonify(msg='Deleted product id: ' + id), 200)

    @findByIdPermissions
    @tracing.trace()
    def get(self, id):
        product = Product.objects.get(id=id).to_json()
        return Response(product, mimetype="application/json", status=200)
コード例 #2
0
class ProductsApi(Resource):
    findAllPermissions = lambda f: admin_required(
        f,
        roles=[
            'ROLE_ADMIN', 'ROLE_PRODUCTS_READ', 'ROLE_PRODUCTS_CREATE',
            'ROLE_PRODUCTS_SAVE', 'ROLE_PRODUCTS_DELETE'
        ])

    createPermissions = lambda f: admin_required(
        f, roles=['ROLE_ADMIN', 'ROLE_PRODUCTS_CREATE'])
    """Return list of products"""
    @findAllPermissions
    @ns.doc(description='List of products',
            responses={
                200: 'List of products',
                400: 'Validation Error',
                401: 'Unauthorized',
                403: 'Forbidden',
                500: 'Unexpected Error'
            })
    @tracing.trace()
    def get(self):
        log.debug('Get all products')
        products = Product.objects().to_json()
        return Response(products, mimetype="application/json", status=200)

    """Create new product"""

    @createPermissions
    @ns.doc(description='Create product',
            responses={
                201: 'Created',
                400: 'Validation Error',
                401: 'Unauthorized',
                403: 'Forbidden',
                500: 'Unexpected Error'
            })
    @ns.expect(productModel)
    @tracing.trace()
    def post(self):
        user_id = get_jwt_identity()
        body = request.get_json()
        product = Product(**body)
        product.createdByUser = user_id
        product.save()
        return Response(product.to_json(),
                        mimetype="application/json",
                        status=201)
コード例 #3
0
upload_parser.add_argument('file', location='files',
                           type=FileStorage, required=True)

# Create configuration object with enabled logging and sampling of all requests.
config = Config(config={'sampler': {'type': 'const', 'param': 1},
                        'logging': True,
                        'local_agent':
                        # Also, provide a hostname of Jaeger instance to send traces to.
                            {'reporting_host': app.config['JAEGER_HOST']}},
                # Service name can be arbitrary string describing this particular web service.
                service_name=app.config['APP_NAME'])
jaeger_tracer = config.initialize_tracer()
tracing = FlaskTracing(tracer=jaeger_tracer, app=app)


createPermissions = lambda f: admin_required(f, roles=['ROLE_ADMIN', 'ROLE_PRODUCTS_CREATE', 'SCOPE_openid'])


ALLOWED_EXTENSIONS = app.config['ALLOWED_EXTENSIONS']


def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@traced(log)
@logged(log)
@nsReceipt.route('')
class ReceiptsApi(Resource):