vorteil/direktiv

View on GitHub
pkg/mirror/mirror.go

Summary

Maintainability
A
0 mins
Test Coverage
// Package mirror implements the logic that interprets the contents of a directory into a namespace.
//
// TODO: This package also contains definitions used for database operations. This is logically separate from the main logic so this package should probably be split into two.
//
// The process is broken down into three logical steps: (1) acquire the source, (2) parse/interpret the contents of the source, and (3) apply necessary changes to Direktiv.
//
// (1) Acquire the source: the typical & classic source is a remote git repository. This package provides the methods needed to use it this way, but this is not the only way envisioned.
//
// TODO: This is an interface overrideable by caller so that the logic can be reused by the CLI. This is critical for maintainability in the future. The CLI use-case has a lot in common with this code, but also a lot of differences.
//
// (2) Parse/interpret the contents of the source: this is a read-only operation that has no impact on the server aside from logging. This is critical because the full sync logic may need to make many changes to a namespace and it is not trivial to implement a good revert if something goes wrong along the way. Substantial validation must be performed before ANY changes are made, to reduce the chance of the operation failing. Additionally, it is helpful to separate the read-only interpretation of the Source out from the application of that interpretation so that the logic can be used for UX features such as a Dry Run and local validation/linting in a CLI.
//
// (3) Apply necessary changes to Direktiv. This step uses the report generated by the previous step to make changes to Direktiv. This is the only step permitted to modify the contents / behaviour of a namespace. IT SHOULD NOT DO ANY interpretation of the source of its own. In a simple world, it will have no if statements nor switches. In practice it may want to compare the desired state of the namespace as determined by the parser against the actual state of the namespace and reuse anything it can.
package mirror