Architecture
We are using cement for the CLI, click for the colorful outputs, and jinja2 for templates.
deployfish.mainOur
deployfish.main.DeployfishAppclass is a subclass of cement.App and is responsible for setting up the application. You’ll find configurations for extensions, templates, handlers, hooks, etc.
deployfish.config
deployfish.config.set_appsaves thedeployfish.main.DeployfishAppinstance in theMAIN_APP.
deployfish.config.get_configreturnsdeployfish.config.DeployfishConfig.deployfish_config, which returns thedeployfish.config.Configobject. It’s usually used to access thedeployfish.ymlconfigurations.
deployfish.config.Configis provides access to the raw data fromdeployfish.ymland the interpolated data as dict.
deployfish.controllers
In cement, the controllers are responsible for running the commands. They call the appropriate methods in the models, which create the appropriate models. They are registered as handlers in
deployfish.main.DeployfishApp.handlers. Whenapp.run()is called,DeployfishAppwill forward the controls to the first controller listed inhandlers. All controllers will have access toDeployfishAppthrough its ownappattribute. To expose commands using@exdecorator for the controller’s methods. The commands will render results using theapp.rendermethod and will need context data and template paths.Note
For rendering templates, our models will have
rendermethods toAdditional info can be found at cement controllers overview and cement controllers.
Note
We subclass
cement.ext.ext_arparse.ArgparseController, which is the defaultControllerclass in cement, so that we can override the help messages for sub commands for controllers.Besides commands, controllers will contain settings for
model,loader, and template rendering settings.The commands in controllers are what calls their repective loaders to get their models. These models can be built based on the data from the
deployfish.ymlfile or from AWS.
deployfish.core.loaders
Loaders are responsible for creating models from AWS or from a
deployfish.ymlfile. They are registered with a controller and called within commands. Loader will create the model and return it to the controller.
deployfish.core.loaders.ObjectLoader.get_object_from_awsis the method that creates the model from AWS.
deployfish.core.loaders.ObjectLoader.get_object_from_deployfishis the method that creates the model from thedeployfish.ymlfile. It specifically usesModel.newto pass data fromdeployfish.ymlto the model.
deployfish.core.loaders.ObjectLoader.factoryreturns the model needed forget_object_from_deployfish. If model does not get passed in, it will use the model set in the associated controller. Thefactorywill extract the specific data fromdeployfish_configand pass it toModel.newand return it.
deployfish.core.models
Models will contain the data and methods needed to interact with AWS. On creation, loaders will pass in data either from AWS or from the
deployfish.ymlfile.Model.newwill pass that data to its adapter through theadaptclass method, which will return the data needed to create the model. Thenewmethod will then return the model by providingModel.__init__with the data from the adapter. Usually this means thatdatagets stored in the model’s owndataattribute.When models are created, the
Model.objectsattribute is assigned a subclass ofdeployfish.core.models.abstract.Managerclass, that will help with managing the model instance. Managers will have methods likesaveanddeletethat will interact with AWS, and they will also have methods likelistthat will return the model instances.Note
Check if there are overrides to the
savemethod for individual models that change how they save.Models will also have various
rendermethods to organize and curate data for template display purposes or saving to AWS.
deployfish.core.adapters
Adapters are responsible for creating the data needed to create models. They are used in the
Model.newmethod. The meat of the adapter can be found in subclasses ofAdapter.convertmethod (which should always be overrided).Please read the Adapters and Models documentation to get an idea of how
deployfish.ymlgets translated to models. Examples are also given in the documentation.
deployfish.renderers
Renderers are responsible for rendering the data from models in a certain way.
A common renderer we use is the
deployfish.renderers.table.TableRendererclass, which will render the data in a table format. We pass therenderoutput toself.app.printin the controller.