Skip to content

Dependency injection

Common

connect.eaas.core.inject.common.get_config

Function to inject the environment variables dictionary in a Web Application endpoint method. Usage:

from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.common import get_config
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   def my_endpoint(self, config: dict = Depends(get_config)):
       my_variable = config['MY_VARIABLE']
       ...

connect.eaas.core.inject.common.get_logger

Function to inject a preconfigured logger that, when run in cloud mode, it will send log messages to logz.io.

Usage:

from logging import LoggerAdapter

from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.common import get_logger
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   def my_endpoint(self, logger: LoggerAdapter = Depends(get_logger)):
       logger.info('This is a log message at level INFO!')
       ...

connect.eaas.core.inject.common.get_call_context

Function to inject a Context object with information about the call.

Usage:

from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.common import get_call_context
from connect.eaas.core.inject.models import Context
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   def my_endpoint(self, context: Context = Depends(get_call_context)):
       installation_id = context.installation_id
       ...

Synchronous Web Application

connect.eaas.core.inject.synchronous.get_extension_client

Function to inject a pre-instantiated ConnectClient with an API key that will authenticate as the same account that owns the extension.

Usage:

from connect.client import ConnectClient
from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.synchronous import get_extension_client
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   def my_endpoint(self, client: ConnectClient = Depends(get_extension_client)):
       pass

connect.eaas.core.inject.synchronous.get_installation_client

Function to inject a pre-instantiated ConnectClient with an API key that will authenticate as the same account as the one that is invoking the endpoint, i.e. the owner of the installation.

Usage:

from connect.client import ConnectClient
from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.synchronous import get_installation_client
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   def my_endpoint(self, client: ConnectClient = Depends(get_installation_client)):
       pass

connect.eaas.core.inject.synchronous.get_installation

Function to inject the installation object owner by the current caller.

Usage:

from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.synchronous import get_installation
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   def my_endpoint(self, installation: dict = Depends(get_installation)):
       pass

Asynchronous Web Application

connect.eaas.core.inject.asynchronous.get_extension_client

Function to inject a pre-instantiated AsyncConnectClient with an API key that will authenticate as the same account that owns the extension.

Usage:

from connect.client import AsyncConnectClient
from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.asynchronous import get_extension_client
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   async def my_endpoint(self, client: AsyncConnectClient = Depends(get_extension_client)):
       pass

connect.eaas.core.inject.asynchronous.get_installation_client

Function to inject a pre-instantiated AsyncConnectClient with an API key that will authenticate as the same account as the one that is invoking the endpoint, i.e. the owner of the installation.

Usage:

from connect.client import AsyncConnectClient
from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.asynchronous import get_installation_client
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   async def my_endpoint(self, client: AsyncConnectClient = Depends(get_installation_client)):
       pass

connect.eaas.core.inject.asynchronous.get_installation

Function to inject the installation object owner by the current caller.

Usage:

from connect.eaas.core.decorators import router, web_app
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.inject.asynchronous import get_installation
from fastapi import Depends


@web_app(router)
class MyWebApp(WebApplicationBase):
   @router.get('/my_endpoint')
   async def my_endpoint(self, installation: dict = Depends(get_installation)):
       pass

Call Context model

Represent the context of the current web call.

Attributes:

  • extension_id - id of this extension.
  • environment_id - id of the environment into which this extension is running.
  • environment_type - type of the environment into which this extension is running.
  • installation_id - id of the installation object owned by the current caller.
  • tier_account_id - id of the tier account of the current caller.
  • user_id - id of the user or service user that is doing the call.
  • account_id - id of the account that is doing the call.
  • account_role - role of the account that is doing the call.
  • call_source - it can be ui if the call came from the user interface or api if it is an API call.
  • call_type - it can be admin if the call came from the same account that own the extension otherwise user.