Example #1
0
def override_eventsrule_notification_rule(hook):
    """
    Add a hook to obtain the Notification Service's arn.

    .. code-block:: python

        def override_codestar_notification_rule(snstopics, alarm):
            "Override normal alarm actions with the SNS Topic ARN for the custom Notification Lambda"
            return ["paco.ref service.notify...snstopic.arn"]

        paco.extend.add_codestart_notification_rule_hook(override_codestar_notification_rule)

    """
    if paco.models.registry.EVENTSRULE_NOTIFICATION_RULE_HOOK != None:
        raise LoaderRegistrationError(
            f"Only one Service can override EventsRule Notification Rules.")
    paco.models.registry.EVENTSRULE_NOTIFICATION_RULE_HOOK = hook
Example #2
0
def override_codestar_notification_rule(hook):
    """
    Add a hook to change CodeStar Notification Rule's to your own custom list of SNS Topics.
    This can be used to send notifications to notify your own custom Lambda function instead of
    sending directly to the SNS Topics that Alarms are subscribed too.

    .. code-block:: python

        def override_codestar_notification_rule(snstopics, alarm):
            "Override normal alarm actions with the SNS Topic ARN for the custom Notification Lambda"
            return ["paco.ref service.notify...snstopic.arn"]

        paco.extend.add_codestart_notification_rule_hook(override_codestar_notification_rule)

    """
    if paco.models.registry.CODESTAR_NOTIFICATION_RULE_HOOK != None:
        raise LoaderRegistrationError(
            f"Only one Service can override CodeStar Notification Rules.")
    paco.models.registry.CODESTAR_NOTIFICATION_RULE_HOOK = hook
Example #3
0
def override_cw_alarm_actions(hook):
    """
    Add a hook to change CloudWatch Alarm AlarmAction's to your own custom list of SNS Topics.
    This can be used to send AlarmActions to notify your own custom Lambda function instead of
    sending Alarm messages directly to the SNS Topics that Alarms are subscribed too.

    The hook is a function that accepts an ``alarm`` arguments and must return a List of paco.refs to SNS Topic ARNs.

    .. code-block:: python

        def override_alarm_actions_hook(snstopics, alarm):
            "Override normal alarm actions with the SNS Topic ARN for the custom Notification Lambda"
            return ["paco.ref service.notify...snstopic.arn"]

        paco.extend.override_cw_alarm_actions(override_alarm_actions_hook)

    """
    if paco.models.registry.CW_ALARM_ACTIONS_HOOK != None:
        raise LoaderRegistrationError(
            f"Only one Service can override CloudWatch Alarm Actions.")
    paco.models.registry.CW_ALARM_ACTIONS_HOOK = hook
Example #4
0
def override_cw_alarm_description(hook):
    """
    Add a hook to modify the CloudWatch Alarm Description.

    The description is sent as a dictionary of fields that will be stored in
    the AlarmDescription as json.

    The hook is a function that accepts an ``alarm`` and ``description`` arguments
    and must return the description when done.

    .. code-block:: python

        def override_cw_alarm_description(alarm, description):
            "Override alarm description"
            return description

        paco.extend.override_cw_alarm_description(override_alarm_description_hook)

    """
    if paco.models.registry.CW_ALARM_DESCRIPTION_HOOK != None:
        raise LoaderRegistrationError(
            f"Only one Service can override CloudWatch Alarm Description.")
    paco.models.registry.CW_ALARM_DESCRIPTION_HOOK = hook
Example #5
0
def register_model_loader(obj, fields_dict, force=False):
    """
    Register a new object to the model loader registry.

    The ``obj`` is the object to register loadable fields for.

    The ``fields_dict`` is a dictionary in the form:

    .. code-block:: python

        { '<fieldname>': ('loader_type', loader_args) }

    If an object is already registered, an error will be raised unless
    ``force=True`` is passed. Then the new registry will override any
    existing one.

    For example, to register a new ``Notification`` object with
    ``slack_channels`` and ``admins`` fields:

    .. code-block:: python

        paco.extend.register_model_loader(
            Notification, {
                'slack_channels': ('container', (SlackChannels, SlackChannel))
                'admins': ('obj_list', Administrator)
            }
        )

    """
    if force == False:
        if obj in SUB_TYPES_CLASS_MAP:
            raise LoaderRegistrationError(
                f"Object {obj} has already been registered with the model loader."
            )

    # ToDo: validate fields_dict
    SUB_TYPES_CLASS_MAP[obj] = fields_dict