runtheops / ssm-diff

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

Plugin system for `Diff*` engine #18

Open ambsw-technology opened 5 years ago

ambsw-technology commented 5 years ago

This PR builds on refactor, adding a plugin system for Diff* engines. To make the plugin system work, I needed to simplify the interface between ParameterStore (formerly RemoteState) and DiffResolver (formerly FlatDictDiffer). My proposed interface is:

By consolidating all API operations in a plan dict, the Diff* plugin can support an arbitrary amount of complexity. For example, a concurrency-sensitive plugin (like the one proposed in #16) could use additional methods to change the behavior of plans:

> diff = ImaginaryDiff(remote, local)
> diff.plan
Exception:  Conflicts Detected:
`/a/b/c/` has changed on both the remote and local storage
> diff.resolve('/a/b/c', use=ImaginaryDiff.REMOTE)
> diff.plan
{'add': {}, 'change': {}, 'delete': {}}
> diff.resolve('/a/b/c', use=ImaginaryDiff.LOCAL)
> diff.plan
{'add': {}, 'change': {'/a/b/c': {'old': '<remote>', 'new': '<local>'}}, 'delete': {}}

ImaginaryDiff would need local_changes() and remote_changes() instead of simply changed(). The result of these methods would be unchanged by resolve() but the plan would be updated accordingly.

I'm not married to the API if you can think of a situation that isn't addressed by it. I needed to get something working and this has been adequate so-far.