The Function Context

The FunctionContext object represents the entry point to everything your Cloud Function needs at runtime.

The Function Context is used as the single entry point to everything your function needs at runtime: which user is calling, the active company and resources, configuration, and clients for IXON's APIs and storage.

IXON Cloud verifies the caller's credentials before the function runs and ensures the correct resources are set on the context.

When a Cloud Function is called, it receives an instance of the FunctionContext class as its first argument:

from ixoncdkingress.function.context import FunctionContext

@FunctionContext.expose
def hello_world(context: FunctionContext, **kwargs: dict[str, str]):
    return {
        'message': 'Hello World'
    }

Exposing a function

Only functions decorated with @FunctionContext.expose are callable from outside the workspace and can use the FunctionContext. Helper functions can stay private.

@FunctionContext.expose
def hello_user(context: FunctionContext, **kwargs: dict[str, str]):
    username = context.user.name if context.user else 'there'
    return {
        'message': f'Hello {name}!'
    }

Reading context data

The context is able to read the values of the connected user and a company and some of their parameters, like a name:

@FunctionContext.expose
def get_names(context: FunctionContext) -> dict:
    return {
        'user': context.user.name if context.user else None,
        'company': context.company.name if context.company else None,
    }

Check the Resources article for a full list of resources and their available fields.

Retrieving a configuration

The values placed in context_values.yaml or those set up in the encrypted configuration in Admin > Apps > More options > Settings, can be retrieved using context.config. See the Configuration for full details.

Making API calls via Cloud Functions

The FunctionContext provides a client that can perform API calls. See Using the API client for full details.

Using Document Store

The Document Store is made available thanks to the DocumentDBClient found in the FunctionContext. See Document Store for full details.