Hi all,
The admin code needs a refactor so that we can extract stuff required by the admin and the agent commands. It is also a mess that needs to be cleaned up. I was thinking of using an approach loosly inspired by MVC.
Currently we have the core repo which contains relatively simple and mostly independant packages like x509, document, crypto, entity and fs etc. There are relationships within core, for example entity to document and entity to x509.
The admin repo (and tool) "implements" documents etc and ties everything together through the file system. So an actual CA is basically a serialised (json) CA encrypted in document container somewhere on the file system. Exactly where on the filesystem it is comes through from the admin tool with the filesystem itself managed using the core "fs" package.
As a breakdown of the current components in the admin repo, we have
cli
- different files handle different commands, e.g. runNode.go for
pki.io node <command> [...]
- pki.io.go handles logging setup
concept of a nodeApp and adminApp
- both use logging and can exit/panic the app
nodeApp
- Sees the world like a node (agent running on a server) eventually will
- node specific config file inside the "org" directory
- a single server can be a node for different orgs
- tries to implement common operations
adminApp
- Sees the world as an admin
- admin specific config
I was thinking of something like this for after a refactor
$
pki.io ca update test-ca ...
* set up system-wide environment such as loggin etc in pki.io.go
* route to ca/update (controller/action)
* update() in ca controller creates a new CA "model" using filesystem setup and calls caModel.Update()
* update() in ca controller writes to log or perhaps to standard out (view)
* errors in update() write to log or perhaps panic() (view)
Some of the controllers would need to be used by both the admin and agent tool, so I thought perhaps we could have a "controllers" package in core. Or perhaps it would make more sense to have a controllers repo with a package for each controller. We would also need to have something similar for "models".
What is the difference between a CA "model" and whats in ca.go in core/x509? Good question. Either the CA model is another layer of abstraction that takes some sort of storage api object and implements the usual CRUD operations. Or, perhaps we shouldn't have separate models and that x509/ca.go should be updated to take the api object and implement CRUD along with all the other operations (e.g Generate, Sign etc)
In summmary, some stuff needs to be written to the admin filesystem in various places, some stuff needs to be written to the node filesystems in various places, and some stuff is either written to the filesystem or eventually to a web API.
Desparetely need your thoughts because now is the time to get this right. A major refactor again later will be an even bigger PITA.
Cheers :)