def setup_module(module): current_file_path = os.path.dirname(os.path.realpath(__file__)) print('\nModule: >> {} at {}'.format(module, current_file_path)) kernel = AppKernelEngine('test_app', app=flask_app, cfg_dir='{}/../'.format(current_file_path), development=True) kernel.register(User, methods=['GET', 'PUT', 'POST', 'PATCH', 'DELETE'])
def setup_module(module): current_file_path = os.path.dirname(os.path.realpath(__file__)) print('\nModule: >> {} at {}'.format(module, current_file_path)) kernel = AppKernelEngine('test_app', app=flask_app, cfg_dir='{}/../'.format(current_file_path), development=True) kernel.register(payment_service) payment_service.sink = MagicMock(name='sink') list_flask_routes(flask_app)
def setup_function(function): """ executed before each method call """ print('\n\nSETUP ==> ') global flask_app global kernel flask_app = Flask(__name__) flask_app.config['SECRET_KEY'] = 'S0m3S3cr3tC0nt3nt!' flask_app.testing = True kernel = AppKernelEngine('test_app', app=flask_app, cfg_dir='{}/../'.format(current_file_path()), development=True) kernel.enable_security() User.delete_all()
def setup_function(function): """ executed before each method call """ print('\n\nSETUP ==> ') global flask_app global kernel flask_app = Flask(__name__) flask_app.config['SECRET_KEY'] = 'S0m3S3cr3tC0nt3nt!' flask_app.testing = True kernel = AppKernelEngine('test_app', app=flask_app, cfg_dir='{}/../'.format(current_file_path()), development=True) kernel.enable_security() kernel.register(payment_service).require(Role('admin'), methods=['GET', 'PUT', 'POST', 'PATCH', 'DELETE']) User.delete_all()
from appkernel import Model, Service, Property, NotEmpty, content_hasher, AppKernelEngine from appkernel.repository import MongoRepository, AuditableRepository from appkernel.validators import Email from various.server import uuid_generator class User(Model, AuditableRepository, Service): id = Property(str, required=True, generator=uuid_generator('U')) name = Property(str, required=True, validators=[NotEmpty]) email = Property(str, required=True, validators=[Email, NotEmpty]) password = Property(str, required=True, validators=[NotEmpty], converter=content_hasher(rounds=10), omit=True) roles = Property(list, sub_type=str, default_value=['Login']) application_id = 'task_management_app' app = Flask(__name__) kernel = AppKernelEngine(application_id, app=app) if __name__ == '__main__': kernel.register(User) user = User(name='Test User', email='*****@*****.**', password='******') user.save() kernel.run()
from appkernel import AppKernelEngine from checkout import PaymentService app_id = f"{PaymentService.__name__}" kernel = AppKernelEngine(app_id) if __name__ == '__main__': kernel.register(PaymentService()) kernel.run()
#!/usr/bin/env python3 from appkernel import AppKernelEngine from flask import Flask from checkout import InventoryService from checkout import Order from checkout import PaymentService from checkout import ShippingService if __name__ == '__main__': # starts all 4 services to make the running of this tutorial simpler app_id = "{} Service".format(Order.__name__) kernel = AppKernelEngine(app_id, app=Flask(app_id), development=True, enable_defaults=True) kernel.register(Order, methods=['GET', 'POST', 'DELETE']) # o = Order(products=[Product(code='BTX', name='t-shirt', size=ProductSize.M, price=Money(10, 'EUR'))]) # o.delivery_address = Address(first_name='John', last_name='Doe', city='Big City', street='some address 8', # country='Country', postal_code='1234') # o.payment_method = Payment(method=PaymentMethod.PAYPAL, customer_id='1234567', customer_secret='120') # print(o.dumps(pretty_print=True)) inventory_service = InventoryService(kernel) kernel.register(PaymentService()) kernel.register(ShippingService()) kernel.run()
#!/usr/bin/python import uuid from flask import Flask from appkernel import AppKernelEngine, Model, Repository, Service, Property, NotEmpty, Regexp, Past from datetime import datetime from appkernel.repository import MongoRepository print('Initialising under {}'.format(__name__)) application_id = 'test_app' app = Flask(__name__) app.config['SECRET_KEY'] = 'S0m3S3cr3tC0nt3nt!' kernel = AppKernelEngine(application_id, app=app) def uuid_generator(prefix=None): def generate_id(): return '{}{}'.format(prefix, str(uuid.uuid4())) return generate_id def date_now_generator(): return datetime.now() class User(Model, MongoRepository, Service): id = Property(str, required=True, generator=uuid_generator('U')) name = Property(str, required=True, validators=[NotEmpty, Regexp('[A-Za-z0-9-_]')])
from appkernel import AppKernelEngine from checkout import Order app_id = f"{Order.__name__} Service" kernel = AppKernelEngine(app_id) if __name__ == '__main__': kernel.register(Order, methods=['GET', 'POST', 'DELETE']) kernel.run()
name = Property(str, required=True, index=UniqueIndex) email = Property(str, validators=[Email], index=UniqueIndex) password = Property(str, validators=[Regexp('(?=.{8,})')], converter=content_hasher(), omit=True) roles = Property(list, sub_type=str, default_value=['Login']) @link(http_method='POST', require=[CurrentSubject(), Role('admin')]) def change_password(self, current_password, new_password): if not pbkdf2_sha256.verify(current_password, self.password): raise ServiceException(403, _('Current password is not correct')) else: self.password = new_password self.save() return _('Password changed') @link(require=Anonymous()) def get_description(self): return self.description app = Flask('demo') kernel = AppKernelEngine('demo', app=app, enable_defaults=True) kernel.register(User) # let's create a sample user user = User(name='Test User', email='*****@*****.**', password='******') user.save() kernel.run()
from appkernel import AppKernelEngine from checkout import InventoryService app_id = f"{InventoryService.__name__}" kernel = AppKernelEngine(app_id) if __name__ == '__main__': inventory_service = InventoryService(kernel) kernel.run()
from appkernel import AppKernelEngine from checkout import ShippingService app_id = f"{ShippingService.__name__}" kernel = AppKernelEngine(app_id) if __name__ == '__main__': kernel.register(ShippingService()) kernel.run()