Skip to content

Commit 3e2ca6b

Browse files
authored
Merge pull request #19 from ByteInternet/add-get-block-attack-descriptions-to-client
add get block attack description to client
2 parents 9f5d9dc + 66021f7 commit 3e2ca6b

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

hypernode_api_python/client.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
HYPERNODE_API_APP_EAV_DESCRIPTION_ENDPOINT = "/v2/app/eav_descriptions/"
1111
HYPERNODE_API_APP_FLAVOR_ENDPOINT = "/v2/app/{}/flavor/"
1212
HYPERNODE_API_APP_FLOWS_ENDPOINT = "/logbook/v1/logbooks/{}/flows"
13-
HYPERNODE_API_BRANCHER_APP_ENDPOINT = "/v2/brancher/app/{}/"
14-
HYPERNODE_API_BRANCHER_ENDPOINT = "/v2/brancher/{}/"
1513
HYPERNODE_API_APP_NEXT_BEST_PLAN_ENDPOINT = "/v2/app/{}/next_best_plan/"
14+
HYPERNODE_API_APP_ORDER_ENDPOINT = "/v2/app/order/"
1615
HYPERNODE_API_APP_PRODUCT_LIST_ENDPOINT = "/v2/product/app/{}/"
1716
HYPERNODE_API_APP_XGRADE_CHECK_ENDPOINT = "/v2/app/xgrade/{}/check/{}/"
1817
HYPERNODE_API_APP_XGRADE_ENDPOINT = "/v2/app/xgrade/{}/"
1918
HYPERNODE_API_BACKUPS_ENDPOINT = "/v2/app/{}/backup/"
19+
HYPERNODE_API_BLOCK_ATTACK_DESCRIPTION_ENDPOINT = "/v2/app/block_attack_descriptions/"
20+
HYPERNODE_API_BRANCHER_APP_ENDPOINT = "/v2/brancher/app/{}/"
21+
HYPERNODE_API_BRANCHER_ENDPOINT = "/v2/brancher/{}/"
2022
HYPERNODE_API_PRODUCT_APP_DETAIL_ENDPOINT = "/v2/product/app/{}/current/"
2123
HYPERNODE_API_PRODUCT_LIST_ENDPOINT = "/v2/product/"
2224
HYPERNODE_API_PRODUCT_PRICE_DETAIL_ENDPOINT = "/v2/product/{}/with_price/"
2325
HYPERNODE_API_VALIDATE_APP_NAME_ENDPOINT = "/v2/app/name/validate/"
2426
HYPERNODE_API_WHITELIST_ENDPOINT = "/v2/whitelist/{}/"
25-
HYPERNODE_API_APP_ORDER_ENDPOINT = "/v2/app/order/"
2627

2728

2829
class HypernodeAPIPython:
@@ -404,6 +405,22 @@ def get_product_info_with_price(self, product_code, error_to_raise=None):
404405
raise error_to_raise
405406
return response
406407

408+
def get_block_attack_descriptions(self):
409+
"""
410+
Get the block attack descriptions. These can be used to block attacks
411+
by automatically placing an NGINX snippet in /data/web/nginx if the
412+
specified block is compatible with the current NGINX configuration.
413+
Example:
414+
> client.requests("GET", "/v2/app/block_attack_descriptions/").json()
415+
> {
416+
> 'BlockSqliBruteForce': 'Attempts to deploy NGINX rules to block suspected (blind) SQL injection attack',
417+
> ...
418+
> }
419+
420+
:return obj response: The request response object
421+
"""
422+
return self.requests("GET", HYPERNODE_API_BLOCK_ATTACK_DESCRIPTION_ENDPOINT)
423+
407424
def get_whitelist_options(self, app_name):
408425
"""
409426
Get whitelist options for app. Retrieve the options for specifying
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from unittest.mock import Mock
2+
3+
from tests.testcase import TestCase
4+
from hypernode_api_python.client import (
5+
HypernodeAPIPython,
6+
HYPERNODE_API_BLOCK_ATTACK_DESCRIPTION_ENDPOINT,
7+
)
8+
9+
10+
class TestGetBlockAttackDescriptions(TestCase):
11+
def setUp(self):
12+
self.client = HypernodeAPIPython(token="mytoken")
13+
self.mock_request = Mock()
14+
self.client.requests = self.mock_request
15+
16+
def test_block_attack_descriptions_endpoint_is_correct(self):
17+
self.assertEqual(
18+
"/v2/app/block_attack_descriptions/",
19+
HYPERNODE_API_BLOCK_ATTACK_DESCRIPTION_ENDPOINT,
20+
)
21+
22+
def test_calls_block_attack_descriptions_detail_endpoint_properly(self):
23+
self.client.get_block_attack_descriptions()
24+
25+
self.mock_request.assert_called_once_with(
26+
"GET", "/v2/app/block_attack_descriptions/"
27+
)
28+
29+
def test_returns_block_attack_descriptions(self):
30+
response = Mock()
31+
response.status_code = 200
32+
self.mock_request.return_value = response
33+
34+
self.assertEqual(
35+
self.client.get_block_attack_descriptions(),
36+
self.mock_request.return_value,
37+
)

0 commit comments

Comments
 (0)