manheim / manheim-c7n-tools

Manheim's Cloud Custodian (c7n) wrapper package, policy generator, runner, and supporting tools.
https://manheim-c7n-tools.readthedocs.io/
Apache License 2.0
45 stars 25 forks source link

policygen - add support for layering mailer-templates/ directory #26

Closed jantman closed 4 years ago

jantman commented 4 years ago

Description

This pull request implements layering of the ./mailer-templates/ directory using similar logic to how policies are layered, to allow sourcing c7n-mailer custom templates from multiple policy repositories with overrides. This is implemented in policygen.

The algorithm is as follows:

  1. Walk through the configured policy_source_paths directories in order.
  2. For each one that has a mailer-templates subdirectory, add the names of all regular files in it to a dictionary of filename to path. This ensures that, for a given filename, it comes from the last directory in policy_source_paths order where it exists.
  3. Each file in the resulting dict will be copied from its source location to ./mailer-templates/. Any files that already exist there will not be overwritten.

Testing Done

  1. Unit tests.
  2. Set up a few different example directory layouts, ran policygen, and manually verified that the generated files were correct.