Skip to content

Commit

Permalink
Improve the integration with Threatr
Browse files Browse the repository at this point in the history
  • Loading branch information
U039b committed Sep 21, 2024
1 parent 8d963ec commit f088063
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions colander/core/threatr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def is_correctly_configured(self):
response = requests.head(f'{self.url}/api/schema/', headers=self.__get_headers(), timeout=10)
return response.status_code == 200
except requests.exceptions.RequestException as e:
logger.error(e)
return False

def is_online(self):
Expand Down
5 changes: 3 additions & 2 deletions colander/core/views/investigate_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def investigate_search_view(request):
request_data = {}

if not threatr_client.is_correctly_configured():
messages.error(request, 'Threatr is not correctly configured.', extra_tags='danger')
messages.error(request, 'Threatr is not correctly configured. Unable to retrieve the API schema (<threatr domain>/api/schema/)', extra_tags='danger')
logger.error(f'Threatr is not correctly configured. {THREAT_BACKEND_IDENTIFIER}')
return render(
request,
Expand Down Expand Up @@ -64,6 +64,7 @@ def investigate_search_view(request):
"force": form.cleaned_data.get('force_update', False)
}
threatr_results, wait = threatr_client.send_request(request_data)
request_data.pop('force', False)
if not wait and type(threatr_results) is dict:
ordering = {'global':{
'total': len(threatr_results['entities']),
Expand Down Expand Up @@ -123,7 +124,7 @@ def investigate_search_view(request):
obj['entities'] = sorted(obj['entities'], key=lambda x: x.get('type').get('name'))
threatr_results['entities'] = entities
threatr_results['reports'] = external_doc_entities
request_data.pop('force', False)

return render(
request,
'pages/investigate/base.html',
Expand Down
4 changes: 1 addition & 3 deletions colander/templates/pages/investigate/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2>We are processing your request</h2>
<div class="col-md-12 text-small">
If you prefer to interact with Threatr from command line, execute:
<pre class="bg-dark text-white p-2 mt-2 rounded"><code>curl -X POST --location "{{ threatr_url }}/api/request/" -H "Content-Type: application/json" \
-H "Authorization: Token {{ user.get_auth_token }}" \
-H "Authorization: Token [your Threatr API key]" \
-d "{{ request_data|json_format }}"</code></pre>
</div>
{% endif %}
Expand Down Expand Up @@ -114,7 +114,6 @@ <h2>We are processing your request</h2>
</pre>
<div id="mermaid-output" class="text-center"></div>
</div>
{% if results.entities %}
{# Entities #}
{% for type, object in ordering.types.items %}
<div id="{{ type }}" class="col-md-12 tab-pane {% if forloop.first %}active{% endif %}" role="tabpanel" aria-labelledby="{{ type }}-tab">
Expand Down Expand Up @@ -144,7 +143,6 @@ <h2>We are processing your request</h2>
</div>
</div>
{% endfor %}
{% endif %}
{% if results.events %}
{# Events #}
<div id="events" class="col-md-12 tab-pane" role="tabpanel" aria-labelledby="events-tab">
Expand Down

0 comments on commit f088063

Please sign in to comment.