bunker/bunker/backends/component.py

46 lines
1.3 KiB
Python

from abc import abstractmethod, abstractclassmethod, ABCMeta
class AbstractComponent(metaclass=ABCMeta):
component_type = "DO NOT INSTANTIATE abstract component"
def __init__(self, bunker, name, password):
self._bunker = bunker
self._name = name
self._password = password
@abstractclassmethod
def new(cls, bunker, name, password):
"""
Create a new component in the given bunker
using the given name and password.
NOTE that this might not be the most handy
classmethod to instatiate a component,
there might be other classmethods that
make use of this method.
NOTE: this classmethod HAS to call ``bunker._add_component``.
"""
pass
@abstractmethod
def close(self, notify_bunker=True):
"""
This method should "close" the given component,
meaning it should write back the changes and bring
it in a state where it cannot be used anymore.
Such a state needs two important protections:
- It is protected against accidental usage, such that
a regular user that forgets that the component is already
closed cannot damage the data
- All sensitive data (i.e. the password) is destroyed.
If notify_bunker is True the parenting bunker will be
notified that the current component is already closed.
"""
pass
@abstractmethod
def write_back(self):
pass