Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add value validation for iocs #130

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions source/app/alembic/versions/ad4e0cd17597_add_ioctype_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Add IocType validation

Revision ID: ad4e0cd17597
Revises: cd519d2d24df
Create Date: 2022-08-04 15:37:44.484997

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
from sqlalchemy import engine_from_config
from sqlalchemy.engine import reflection

revision = 'ad4e0cd17597'
down_revision = 'cd519d2d24df'
branch_labels = None
depends_on = None


def upgrade():
if not _table_has_column('ioc_type', 'type_validation_regex'):
op.add_column('ioc_type',
sa.Column('type_validation_regex', sa.String(255))
)

if not _table_has_column('ioc_type', 'type_validation_expect'):
op.add_column('ioc_type',
sa.Column('type_validation_expect', sa.String(255))
)


def downgrade():
op.drop_column('ioc_type', 'type_validation_regex')


def _table_has_column(table, column):
config = op.get_context().config
engine = engine_from_config(
config.get_section(config.config_ini_section), prefix='sqlalchemy.')
insp = reflection.Inspector.from_engine(engine)
has_column = False

for col in insp.get_columns(table):
if column != col['name']:
continue
has_column = True
return has_column
2 changes: 2 additions & 0 deletions source/app/blueprints/manage/manage_ioc_types_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def view_ioc_modal(cur_id, caseid, url_redir):
form.type_name.render_kw = {'value': ioct.type_name}
form.type_description.render_kw = {'value': ioct.type_description}
form.type_taxonomy.data = ioct.type_taxonomy
form.type_validation_regex.data = ioct.type_validation_regex
form.type_validation_expect.data = ioct.type_validation_expect

return render_template("modal_add_ioc_type.html", form=form, ioc_type=ioct)

Expand Down
2 changes: 2 additions & 0 deletions source/app/blueprints/manage/templates/manage_objects.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@
<th>Name</th>
<th>Description</th>
<th>Taxonomy</th>
<th>Validation regex</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Description</th>
<th>Taxonomy</th>
<th>Validation regex</th>
</tr>
</tfoot>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ <h4>Add IOC Type</h4>
<label for="type_taxonomy" class="placeholder">Type taxonomy</label>
{{ form.type_taxonomy(class='form-control', autocomplete="off") }}
</div>
<div class="form-group mt-3">
<label for="type_description" class="placeholder">Type validation regex</label>
{{ form.type_validation_regex(class='form-control', autocomplete="off") }}
</div>
<div class="form-group mt-3">
<label for="type_description" class="placeholder">Type validation expect explanation</label>
{{ form.type_validation_expect(class='form-control', autocomplete="off") }}
</div>

{% if ioc_type.type_id %}
<button type="button" class="btn btn-outline-danger mt-5"
Expand Down
2 changes: 2 additions & 0 deletions source/app/datamgmt/case/case_iocs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def get_ioc_types_list():
IocType.type_name,
IocType.type_description,
IocType.type_taxonomy,
IocType.type_validation_regex,
IocType.type_validation_expect,
).all()

l_types = [row._asdict() for row in ioc_types]
Expand Down
2 changes: 2 additions & 0 deletions source/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class AddIocTypeForm(FlaskForm):
type_name = StringField(u'Type name', validators=[DataRequired()])
type_description = StringField(u'Type description', validators=[DataRequired()])
type_taxonomy = TextAreaField(u'Type taxonomy')
type_validation_regex = StringField(u'Type validation regex')
type_validation_expect = StringField(u'Type validation expectation')


class AddCustomerForm(FlaskForm):
Expand Down
4 changes: 3 additions & 1 deletion source/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ class IocType(db.Model):
type_name = Column(Text)
type_description = Column(Text)
type_taxonomy = Column(Text)
type_validation_regex = Column(Text)
type_validation_expect = Column(Text)


class IocLink(db.Model):
Expand Down Expand Up @@ -647,7 +649,7 @@ class IrisModuleHook(db.Model):
class IrisReport(db.Model):
__tablename__ = 'iris_reports'

report_id = Column(db.Integer,Sequence("iris_reports_id_seq"), primary_key=True)
report_id = Column(db.Integer, Sequence("iris_reports_id_seq"), primary_key=True)
case_id = Column(ForeignKey('cases.case_id'), nullable=False)
report_title = Column(String(155))
report_date = Column(DateTime)
Expand Down
Loading