Package: m360-middleware
m360.mw.pythonThe M360 Python Middleware is a dependency that gets consumed by a Python Web Server built using one of these frameworksDjangoandFlask.The middleware is developed using native Python and includes interfaces that facilitate using it with the above mentioned frameworks.Installationpip install m360-middlewareUsageDjangoIn your settings.py file, include the middleware and its configuration:importos# ...MIDDLEWARE=[# ...# -------------------- M360 Middleware Setup --------------------'m360.frameworks.django.middleware.DjangoMiddleware',# ...]# ...M360={"contract":os.path.join(os.path.dirname(__file__),"./contract.json"),"ip":os.environ.get('APP_IP')or"127.0.0.1","type":"django","platform":"manual"}In yourviews, import and use the middleware:fromdjango.httpimportJsonResponse# the sdk is initialized using the middleware when Django startsfromm360importsdkM360=sdk.instance()defget_settings(request):returnJsonResponse(M360.registry.get(),status=200,safe=False)FlaskIn your settings.py file, include the middleware and its configuration:importos# ...app=Flask(__name__)fromm360.frameworks.flask.middlewareimportFlaskMiddlewareapp.wsgi_app=FlaskMiddleware(app.wsgi_app,{"contract":os.path.join(os.path.dirname(__file__),"./contract.json"),"ip":os.environ.get('APP_IP')or"127.0.0.1","type":"flask","platform":"manual"})In yourviews, import and use the middleware:# the sdk is initialized using the middleware when Flask startsimportjsonfromm360importsdkM360=sdk.instance()@app.route('/m360/settings',methods=['GET','POST'])defm360_settings():returnjson.dumps(M360.registry.get())Containerized DeploymentDeploying on DockerWhen deploying on Docker, please provide the extra options below.
Without these options, the handshake between the middleware and the gateway will fail,
along with any maintenance operation that gets triggered from the console onto this microservice.Replace theplatform:manualwithplatform:dockerand add the below.OptionData TypeMandatoryDescriptionplatformStringYESvalue equals 'docker'networkStringYESvalue equals the docker network attached to this docker serviceserviceStringYESvalue equals the name of the docker servicecontainerIPStringNOvalue is the internal IP address of the docker container in the docker serviceExample'platform':'docker','platformOptions':{'network':'mike','service':'service-express','containerIP':'127.0.0.1'}Deploying on KubernetesWhen deploying on Kubernetes, please provide the extra options below.
Without these options, the handshake between the middleware and the gateway will fail,
along with any maintenance operation that gets triggered from the console onto this microservice.Replace theplatform:manualwithplatform:kubernetesand add the below.OptionData TypeMandatoryDescriptionplatformStringYESvalue equals 'kubernetes'namespaceStringYESvalue equals the kubernetes namespace where your deployment will runserviceStringYESvalue equals the name of the kubernetes service that is attached to the your deploymentexposedPortStringYESvalue equals the exposed port kubernetes service'platform':'kubernetes','platformOptions": {'namespace': 'mike','service': 'service-express','exposedPort':30402}NotesThe Middleware includes samples on how you can consume it with both Django and Flask.These sample apps are located inside theexamplesfolder in this repository.Reference:M360 Middleware Official Documentation