center-for-threat-informed-defense / tram

TRAM is an open-source platform designed to advance research into automating the mapping of cyber threat intelligence reports to MITRE ATT&CK®.
https://ctid.mitre-engenuity.org/our-work/tram/
Apache License 2.0
423 stars 90 forks source link

Add an API route to trigger [re-]training of models (#124) #178

Closed mehaase closed 2 years ago

mehaase commented 2 years ago

Add an API route to trigger training of a model. This runs synchronously and the current implementation is a stop gap until a point in time where we could have training run asynchronously (e.g. background workers reading a message queue).

Adapted from @bsnyder70's PR #129. Unlike the PR, this implementation does not have a GUI component because the synchronous aspect of the API call would lead to high latency in the GUI (e.g. click the button and it freezes for 10-15 seconds while it trains the model). For now training can only be triggered from an API call (or from the command line, which has not changed in this PR).

TRAM doesn't really have an API authentication scheme. The "API" routes use the cookie-based authentication and the Django views require CSRF tokens, which is inconvenient for API calls. So this PR also adds JWT tokens (described in the README) so that API calls can be made with a bearer token and no CSRF token. This is still backwards compatible with session/CSRF auth, so it shouldn't break any existing API clients out there.

codecov[bot] commented 2 years ago

Codecov Report

Merging #178 (5e07e7d) into main (7d5e334) will increase coverage by 0.07%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
+ Coverage   95.68%   95.76%   +0.07%     
==========================================
  Files           9        9              
  Lines         858      874      +16     
==========================================
+ Hits          821      837      +16     
  Misses         37       37              
Impacted Files Coverage Δ
src/tram/urls.py 100.00% <100.00%> (ø)
src/tram/views.py 95.48% <100.00%> (+0.48%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0fabc1a...5e07e7d. Read the comment docs.

nschwane commented 2 years ago

@mehaase Are there any plans to have test coverage on the new view?

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

mehaase commented 2 years ago

Added tests for the new view.