runtheops / ssm-diff

A human-friendly way of managing parameters in AWS SSM
MIT License
46 stars 26 forks source link

Enhanced Storage Classes #19

Open ambsw-technology opened 5 years ago

ambsw-technology commented 5 years ago

This PR is built on #18 (for easy merging) but is mostly unrelated. It introduces a variety of improvements to the storage engines (i.e. YAMLFile and ParamterStore) with related changes to the CLI experience:

However, the more significant improvement is the introduction of metadata in the YAML files. YAML files now store the root_path, paths and no_secure settings used to generate them. If a subsequent command attempts to use the file with incompatible configurations, it will throw an exception.

This is a more general solution to my concerns in #15. It can be extended to cover all relevant parameters, whether used through the CLI or programmatically. For example, it prevents the following sequence of events:

> set SSM_PATHS=/my/deep/path
> ssh-diff init
# close the command prompt and reopen, implicitly resetting the PATHS env variable:
> set SSM_PATHS=/
# anything outside /my/deep/path would be deleted
> ssh-diff apply
ValueError: Path / was not included in this file when it was created.

However, it's smart enough to permit subsets of the original scope:

> set PATHS=/
> ssh-diff init
# because this path is contained in our original scope, it's "safe" to update that branch
> set PATHS=/test
# change /other/key and /test/child/key
# PATHS continues to limit updates to the relevant branch 
> ssh-diff plan
~/test/child/key:
        < original
        > changed

P.S. This PR may contain small fixes to previous PRs.

EDIT: Encapsulated the type checking and coercion in ParameterStore. I had originally implemented it in the DiffResolver, but realized that ParameterStore is really the limiting factor here. In theory, you could use the DiffResolver with a less restrictive endpoint (Azure? Vault? AWS Secrets?) and might want different coercion and type checking.