Skip to content

Commit 1b999e7

Browse files
cipher setting update
1 parent aac1386 commit 1b999e7

File tree

3 files changed

+232
-6
lines changed

3 files changed

+232
-6
lines changed

ibm_cloud_networking_services/zones_settings_v1.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,3 +2321,82 @@ def update_web_application_firewall(self, *, accept: str = None, value: str = No
23212321
response = self.send(request)
23222322
return response
23232323

2324+
#########################
2325+
# Get Ciphers setting
2326+
#########################
2327+
2328+
2329+
def get_ciphers(self, *, accept: str = None, **kwargs) -> DetailedResponse:
2330+
"""
2331+
get ciphers setting.
2332+
2333+
Get ciphers setting for a zone.
2334+
2335+
:param str accept: (optional) The type of the response: *_/_* or
2336+
application/json.
2337+
:param dict headers: A `dict` containing the request headers
2338+
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
2339+
:rtype: DetailedResponse with `dict` result representing a `CiphersResp` object
2340+
"""
2341+
2342+
headers = {
2343+
'Accept': accept
2344+
}
2345+
sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_ciphers')
2346+
headers.update(sdk_headers)
2347+
2348+
if 'headers' in kwargs:
2349+
headers.update(kwargs.get('headers'))
2350+
2351+
url = '/v1/{0}/zones/{1}/settings/ciphers'.format(*self.encode_path_vars(self.crn, self.zone_identifier))
2352+
request = self.prepare_request(method='GET',
2353+
url=url,
2354+
headers=headers)
2355+
2356+
response = self.send(request)
2357+
return response
2358+
2359+
#########################
2360+
# Update Ciphers setting
2361+
#########################
2362+
2363+
2364+
def update_ciphers(self, *, accept: str = None, value: List[List[str]] = None, **kwargs) -> DetailedResponse:
2365+
"""
2366+
Update ciphers setting.
2367+
2368+
Update ciphers setting for a zone.
2369+
2370+
:param str accept: (optional) The type of the response: *_/_* or
2371+
application/json.
2372+
:param List[List[str]] value: (optional) Value.
2373+
:param dict headers: A `dict` containing the request headers
2374+
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
2375+
:rtype: DetailedResponse with `dict` result representing a `CiphersResp` object
2376+
"""
2377+
2378+
headers = {
2379+
'Accept': accept
2380+
}
2381+
sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='update_ciphers')
2382+
headers.update(sdk_headers)
2383+
2384+
data = {
2385+
'value': value
2386+
}
2387+
data = {k: v for (k, v) in data.items() if v is not None}
2388+
data = json.dumps(data)
2389+
headers['content-type'] = 'application/json'
2390+
2391+
if 'headers' in kwargs:
2392+
headers.update(kwargs.get('headers'))
2393+
2394+
url = '/v1/{0}/zones/{1}/settings/ciphers'.format(*self.encode_path_vars(self.crn, self.zone_identifier))
2395+
request = self.prepare_request(method='PATCH',
2396+
url=url,
2397+
headers=headers,
2398+
data=data)
2399+
2400+
response = self.send(request)
2401+
return response
2402+

test/integration/test_zone_settings_v1.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import unittest
88
from ibm_cloud_networking_services.zones_settings_v1 import ZonesSettingsV1
99

10+
1011
class TestZonesSettingsV1(unittest.TestCase):
1112
""" Sample function to call zones sdk functions """
1213

@@ -252,10 +253,10 @@ def test_1_mobile_redirect_setting(self):
252253
domain = self.url.split('.')[0]
253254
if result.get('value').get('status') == 'on':
254255
self.value = {
255-
"status": "off",
256-
"mobile_subdomain": domain,
257-
"strip_uri": False
258-
}
256+
"status": "off",
257+
"mobile_subdomain": domain,
258+
"strip_uri": False
259+
}
259260
else:
260261
self.value = {
261262
"status": "on",
@@ -463,5 +464,17 @@ def test_1_challenge_ttl_setting(self):
463464
value=self.value).get_result()
464465
assert response is not None and response.get('success') is True
465466

467+
def test_1_cipher_setting(self):
468+
""" Get cipher setting """
469+
response = self.zonesSettings.get_ciphers().get_result()
470+
assert response is not None and response.get('success') is True
471+
472+
""" Update cipher setting """
473+
response = self.zonesSettings.update_ciphers(
474+
value=["AES256-GCM-SHA384", "AES256-SHA256"]).get_result()
475+
print("update", response)
476+
assert response is not None and response.get('success') is True
477+
478+
466479
if __name__ == '__main__':
467480
unittest.main()

test/unit/test_zones_settings_v1.py

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import json
2020
import pytest
2121
import responses
22-
from ibm_cloud_networking_services.zones_settings_v1 import ZonesSettingsV1
22+
from ibm_cloud.zones_settings_v1 import *
2323

2424
crn = 'testString'
2525
zone_identifier = 'testString'
@@ -1475,7 +1475,6 @@ def test_update_minify_all_params(self):
14751475
html=html,
14761476
js=js,
14771477
)
1478-
print(response)
14791478
# Check for correct operation
14801479
assert len(responses.calls) == 1
14811480
assert response.status_code == 200
@@ -3818,3 +3817,138 @@ def test_update_web_application_firewall_required_params(self):
38183817
# End of Service: UpdateWebApplicationFirewallSetting
38193818
##############################################################################
38203819

3820+
##############################################################################
3821+
# Start of Service: GetCiphersSetting
3822+
##############################################################################
3823+
# region
3824+
3825+
#-----------------------------------------------------------------------------
3826+
# Test Class for get_ciphers
3827+
#-----------------------------------------------------------------------------
3828+
class TestGetCiphers():
3829+
3830+
#--------------------------------------------------------
3831+
# get_ciphers()
3832+
#--------------------------------------------------------
3833+
@responses.activate
3834+
def test_get_ciphers_all_params(self):
3835+
# Set up mock
3836+
url = base_url + '/v1/testString/zones/testString/settings/ciphers'
3837+
mock_response = '{"result": {"id": "ciphers", "value": [["value"]], "editable": true, "modified_on": "2019-01-01T12:00:00"}, "success": true, "errors": [["errors"]], "messages": [["messages"]]}'
3838+
responses.add(responses.GET,
3839+
url,
3840+
body=mock_response,
3841+
content_type='*/*',
3842+
status=200)
3843+
3844+
# Set up parameter values
3845+
accept = 'testString'
3846+
3847+
# Invoke method
3848+
response = service.get_ciphers(
3849+
accept=accept
3850+
)
3851+
3852+
# Check for correct operation
3853+
assert len(responses.calls) == 1
3854+
assert response.status_code == 200
3855+
3856+
3857+
#--------------------------------------------------------
3858+
# test_get_ciphers_required_params()
3859+
#--------------------------------------------------------
3860+
@responses.activate
3861+
def test_get_ciphers_required_params(self):
3862+
# Set up mock
3863+
url = base_url + '/v1/testString/zones/testString/settings/ciphers'
3864+
mock_response = '{"result": {"id": "ciphers", "value": [["value"]], "editable": true, "modified_on": "2019-01-01T12:00:00"}, "success": true, "errors": [["errors"]], "messages": [["messages"]]}'
3865+
responses.add(responses.GET,
3866+
url,
3867+
body=mock_response,
3868+
content_type='*/*',
3869+
status=200)
3870+
3871+
# Invoke method
3872+
response = service.get_ciphers()
3873+
3874+
3875+
# Check for correct operation
3876+
assert len(responses.calls) == 1
3877+
assert response.status_code == 200
3878+
3879+
3880+
# endregion
3881+
##############################################################################
3882+
# End of Service: GetCiphersSetting
3883+
##############################################################################
3884+
3885+
##############################################################################
3886+
# Start of Service: UpdateCiphersSetting
3887+
##############################################################################
3888+
# region
3889+
3890+
#-----------------------------------------------------------------------------
3891+
# Test Class for update_ciphers
3892+
#-----------------------------------------------------------------------------
3893+
class TestUpdateCiphers():
3894+
3895+
#--------------------------------------------------------
3896+
# update_ciphers()
3897+
#--------------------------------------------------------
3898+
@responses.activate
3899+
def test_update_ciphers_all_params(self):
3900+
# Set up mock
3901+
url = base_url + '/v1/testString/zones/testString/settings/ciphers'
3902+
mock_response = '{"result": {"id": "ciphers", "value": [["value"]], "editable": true, "modified_on": "2019-01-01T12:00:00"}, "success": true, "errors": [["errors"]], "messages": [["messages"]]}'
3903+
responses.add(responses.PATCH,
3904+
url,
3905+
body=mock_response,
3906+
content_type='*/*',
3907+
status=200)
3908+
3909+
# Set up parameter values
3910+
accept = 'testString'
3911+
value = [['ECDHE-ECDSA-AES128-GCM-SHA256']]
3912+
3913+
# Invoke method
3914+
response = service.update_ciphers(
3915+
accept=accept,
3916+
value=value,
3917+
)
3918+
3919+
# Check for correct operation
3920+
assert len(responses.calls) == 1
3921+
assert response.status_code == 200
3922+
# Validate body params
3923+
req_body = json.loads(str(responses.calls[0].request.body, 'utf-8'))
3924+
assert req_body['value'] == value
3925+
3926+
3927+
#--------------------------------------------------------
3928+
# test_update_ciphers_required_params()
3929+
#--------------------------------------------------------
3930+
@responses.activate
3931+
def test_update_ciphers_required_params(self):
3932+
# Set up mock
3933+
url = base_url + '/v1/testString/zones/testString/settings/ciphers'
3934+
mock_response = '{"result": {"id": "ciphers", "value": [["value"]], "editable": true, "modified_on": "2019-01-01T12:00:00"}, "success": true, "errors": [["errors"]], "messages": [["messages"]]}'
3935+
responses.add(responses.PATCH,
3936+
url,
3937+
body=mock_response,
3938+
content_type='*/*',
3939+
status=200)
3940+
3941+
# Invoke method
3942+
response = service.update_ciphers()
3943+
3944+
3945+
# Check for correct operation
3946+
assert len(responses.calls) == 1
3947+
assert response.status_code == 200
3948+
3949+
3950+
# endregion
3951+
##############################################################################
3952+
# End of Service: UpdateCiphersSetting
3953+
##############################################################################
3954+

0 commit comments

Comments
 (0)