Skip to main content

Add a Notification Config Rule (to CI)

What are Notification Configs

Notification configs are YAML files used to organize information necessary for sending notifications via the Notifications Service. This includes things like an associated preference, enabled channels, and required attributes. A full breakdown of configurable options can be found in /notification_configs/sample.yml. Every notification that sends via the Notifications Service must have a valid notification config file.

Notification Config Ruleset

This ruleset runs against every notification config in the Notifications repo. If a rule in the ruleset is a match for a config, the rule is executed. Any rule failures are reported and will fail CI to prevent malformed notification configs from reaching production. You can run these checks locally with:

go run notification_configs_test/ruleset/main.go

The current rule set can be found in notification_configs_test/ruleset/rules/rule.go.

Notification Config Rules

All rules must implement two methods:

type Rule interface {
IsMatch(config notification_config.NotificationConfiguration) bool
Execute(path string, config notification_config.NotificationConfiguration, validations Validations) error
}

To add a new rule to the rule set, define a new rule and write corresponding tests in /notification_configs_test/ruleset/rules using the existing rules as examples. Once the new rule struct exists, add it to the slice returned by NewRuleSet() here, and you should be good to go!

You'll see that some rules make use of enums to test that provided data matches our expectations. Once example of this is NotificationPreferenceNameRule which checks that the provided notification preference name can be found in our list of known notification preferences. If you need to add a new enum, that can be done by updating /notification_configs/config_validation.yml. In the NotificationPreferenceNameRule example, we are checking the notification_preference_name field value in the notificaiton config against the list of notification_preference_names in config_validation.yml.

Please note, that if you add new keys to /notification_configs/config_validation.yml, you'll need to update the Validations struct in the ruleset so that they can be accessed.