Skip to content

Decorators

Common

connect.eaas.core.decorators.variables(variables)

Class decorator to declare variables needed by your application. The declared variables will be created on the first run with the specified initial_value if they don't exist.

Usage:

from connect.eaas.core.decorators import variables
from connect.eaas.core.extension import EventsApplicationBase


@variables(
    [
        {
        "name": "ASSET_REQUEST_APPROVE_TEMPLATE_ID",
        "initial_value": "<change_with_purchase_request_approve_template_id>"
        },
        {
        "name": "ASSET_REQUEST_CHANGE_TEMPLATE_ID",
        "initial_value": "<change_with_change_request_approve_template_id>"
        },
        {
        "name": "TIER_REQUEST_APPROVE_TEMPLATE_ID",
        "initial_value": "<change_with_tier_request_approve_template_id>"
        },
    ],
)
class MyEventsApplication(EventsApplicationBase):
    pass

Parameters:

Name Type Description Default
variables List[Dict]

The list of environment variables you want to initialize.

required

Events Application

connect.eaas.core.decorators.event(event_type, statuses=None)

Mark a method of an Events Application as the handler for a given event_type eventually filtering the event by status.

Usage:

from connect.eaas.core.decorators import event
from connect.eaas.core.extension import EventsApplicationBase


class MyEventsApplication(EventsApplicationBase):

    @event(
        'asset_purchase_request_processing',
        statuses=[
            'pending', 'approved', 'failed',
            'inquiring', 'scheduled', 'revoking',
            'revoked',
        ],
    )
    def handle_purchase_request(self, request):
        pass

Parameters:

Name Type Description Default
event_type str

The type of event this handler is for.

required
statuses List[str]

List of statuses of the event that this handler want to receive.

None

Note

The list of statuses is required for background event types only and must not be set for interactive events.

connect.eaas.core.decorators.schedulable(name, description)

Mark a method of an Events Application as that can be invoked on a scheduled basis.

Usage:

from connect.eaas.core.decorators import schedulable
from connect.eaas.core.extension import EventsApplicationBase

class MyEventsApplication(EventsApplicationBase):

    @schedulable(
        'Schedulable method mock',
        'It can be used to test DevOps scheduler.',
    )
    def execute_scheduled_processing(self, schedule):
        pass

Parameters:

Name Type Description Default
name str

The name of this schedulable method.

required
description str

Description of what this schedulable method do.

required

Note

The name and description arguments are used by the create new schedule wizard of the Connect DevOps module to allow to identify the method when creating schedules for it.

Web Application

connect.eaas.core.decorators.web_app

This function returns a decorator that converts the decorated into a class-based view for the provided router.

Any methods of the decorated class that are decorated as endpoints using the router provided to this function will become endpoints in the router. The first positional argument to the methods (typically self) will be populated with an instance created using FastAPI's dependency-injection.

For more detail, review the documentation at https://fastapi-utils.davidmontague.xyz/user-guide/class-based-views/#the-cbv-decorator

This decorator is required to be used if you want to declare any endpoint.

Usage:

from connect.eaas.core.decorators import (
    router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
class MyWebApp(WebApplicationBase):
    pass

connect.eaas.core.decorators.unauthorized()

Mark an endpoint of a Web Application as not subject to the Connect authentication.

Usage:

from connect.eaas.core.decorators import unauthorized, router, web_app
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
class MyWebApp(WebApplicationBase):

    @unauthorized()
    @router.get('/my_endpoint')
    def my_endpoint(self):
        pass

Note

In releases prior to 27, unauthenticated endpoints required authorization by CloudBlue. Although this feature is now enabled by default, if your extension was created using a version earlier than release 27, you must still contact CloudBlue support to enable unauthenticated endpoints for your extension.

connect.eaas.core.decorators.guest()

Warning

The guest() decorator is deprecated and will be removed in future releases. Use the unauthorized() decorator instead.

connect.eaas.core.decorators.account_settings_page(label, url)

Class decorator for Web Application that declare which html page must be rendererd within the Account Settings module of Connect UI to handle the extension installation settings.

Usage:

from connect.eaas.core.decorators import (
    account_settings_page, router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
@account_settings_page('My settings', '/static/settings.html')
class MyWebApp(WebApplicationBase):
    pass

Parameters:

Name Type Description Default
label str

The label to use for such page.

required
url str

The url path to the html page including /static.

required
icon str

The image path to the icon including /static.

None

connect.eaas.core.decorators.module_pages(label, url, children=None)

Class decorator for Web Application that declare the main page for a web application and optionally a list of children pages.

Usage:

from connect.eaas.core.decorators import (
    module_pages, router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
@module_pages(
    'Home',
    '/static/home.html',
    '/static/icon.png',
    children=[
        {
            'label': 'Child page 1',
            'url': '/static/child1.html',
            'icon': '/static/c1icon.png',
        },
    ],
)
class MyWebApp(WebApplicationBase):
    pass

Parameters:

Name Type Description Default
label str

The label to use for such page.

required
url str

The url path to the html page including /static.

required
url str

Optional icon url path including /static.

required
children List[Dict]

Optional list of children pages.

None

Note

Your extension pages will be rendered using a Tabs component of the Connect UI. The main page will be the first tab and the label will be the tab label. For each child in children a tab will be added to the Tabs component using its label as the tab label.

connect.eaas.core.decorators.admin_pages(pages)

Class decorator for Web Application that declare a list of admin pages. Admin pages are shown in the detail view of a specific installation of the Web Application inside your extension details view.

Usage:

from connect.eaas.core.decorators import (
    admin_pages, router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
@admin_pages(
    [
        {
            'label': 'My Admin 1',
            'url': '/static/admin1.html',
            'icon': '/static/icon.png',
        },
    ],
)
class MyWebApp(WebApplicationBase):
    pass

Parameters:

Name Type Description Default
pages List[Dict]

Optional list of admin pages.

required

connect.eaas.core.decorators.devops_pages(pages)

Class decorator for Web Application that declare a list of devops pages that will be displayed. These pages are shown as additional tabs in the main devops page.

Usage:

from connect.eaas.core.decorators import (
    devops_pages, router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
@devops_pages(
    [
        {
            'label': 'My tab 1',
            'url': '/static/tab1.html',
            'icon': '/static/icon.png',
        },
    ],
)
class MyWebApp(WebApplicationBase):
    pass

Parameters:

Name Type Description Default
pages List[Dict]

List of devops pages including the label, the url and the icon.

required

connect.eaas.core.decorators.proxied_connect_api(endpoints)

Class decorator for Web Application that declares a list (or dict) of Connect Public API endpoints, accessible on the hosts of the extension and its installations. Each item shall start with a / and contain a full API path of the endpoint. Nested API endpoints with dynamic IDs are not supported at the moment.

Usage:

from connect.eaas.core.decorators import (
    proxied_connect_api, router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
@proxied_connect_api(
    [
        '/public/v1/marketplaces',
        '/public/v1/auth/context',
    ],
)
class MyWebApp(WebApplicationBase):
    pass


@web_app(router)
@proxied_connect_api(
    {
        '/public/v1/marketplaces': 'edit',
        '/public/v1/auth/context': 'view',
    },
)
class MyWebApp2(WebApplicationBase):
    pass

Parameters:

Name Type Description Default
endpoints Union[List[str], Dict]

List of endpoints.

required

connect.eaas.core.decorators.customer_pages(pages)

Class decorator for Web Application that declare the customer home pages (each includes label, url and icon). These pages will be used as customer home pages.

Usage:

from connect.eaas.core.decorators import (
    customer_pages, router, web_app,
)
from connect.eaas.core.extension import WebApplicationBase


@web_app(router)
@customer_pages(
    [
        {
            'label': 'My page 1',
            'url': '/static/page1.html',
            'icon': '/static/pageIcon.png',
        },
    ],
)
class MyWebApp(WebApplicationBase):
    pass

Parameters:

Name Type Description Default
pages List[Dict]

List of customer home pages including the label, the url and the icon.

required

Anvil Application

connect.eaas.core.decorators.anvil_key_variable(name)

Class decorator for an Anvil Application that declare the name of the environment variable that stores the Anvil Server Uplink key.

Usage:

from connect.eaas.core.decorators import anvil_key_variable
from connect.eaas.core.extension import AnvilApplicationBase


@anvil_key_variable('ANVIL_SERVER_UPLINK_KEY')
class MyAnvilApplication(AnvilApplicationBase):
    pass

Parameters:

Name Type Description Default
name str

Name of the environment variable.

required

Note

This environment variable does not need to be declared using the @variables decorator it will be automatically declared as a secure variable with the initial_value set to changeme!.

connect.eaas.core.decorators.anvil_callable(summary=None, description=None)

Mark a method of an Anvil Application class as a method that can be called from an Anvil frontend application.

Usage:

from connect.eaas.core.decorators import anvil_callable, anvil_key_variable
from connect.eaas.core.extension import AnvilApplicationBase


@anvil_key_variable('ANVIL_SERVER_UPLINK_KEY')
class MyAnvilApplication(AnvilApplicationBase):

    @anvil_callable(
        summary='This function say hello',
        decription='Description of what this function do',
    )
    def say_hello(self, name):
        return f'Hello {name}'

Parameters:

Name Type Description Default
summary str

Summary of the callable.

None
description str

Description of the callable.

None