-
Notifications
You must be signed in to change notification settings - Fork 72
Database
Armory by default uses SQLite on the backend. It is using SQLAlchemy, so it should be able to use any supported SQL server. Only SQLite has been tested though.
The database is composed of several tables that store relevant information returned from tools and provide information to supply to tools.
The schema for the various tables is generated on the fly by SQLAlchemy. You can view the basic database models in the database/models folder.
The following functions are provided for all of the models.
find_or_create(only_tool, **kwargs)
This function is used to get a database object for an object being added to the database. This will return a boolean (of whether it is new or not) and the model object. The only_tool parameter will add an entry on the object for the tool calling the object. This is used to save that an object has been used by a tool already (for example a domain had Subfinder run on it). For example:
created, domain = Domain.find_or_create(only_tool=False, domain='blah.com')
all(tool=False, scope_type="", **kwargs)
This function is used to return a list of all of the records for a model. If tool is true, it will mark all of the objects as having had the tool used on them in the meta
field. Scope type can be 'active' (return all records with in_scope=True
), 'passive' (return all records with passive_scope=True
), or anything else will return all records.
There is basic search functionality, where you can pass a field name and a value. For example:
cidrs = CIDRs.all(scope_type="passive", org_name="Godaddy LLC")
get_query()
This function returns a SQLAlchemy query object and a SQLAlchemy model object. You can use these to do more advanced searches. For example:
qry, model = Users.get_query()
a_users = qry.filter(model.email.like('a%@domain.%'))
commit()
The database objects need to be told to explicitly save the database when they are done. Use commit() to save the changes. If the application errors out before commit
ting, the changes will be rolled back. For example:
created, user = Users.find_or_create(email='[email protected]')
user.first_name = 'John'
user.last_name = 'Doe'
user.update()
Users.commit()