From 755e9729e1a554b19a6b3dd0efdf7b1aafee4b9b Mon Sep 17 00:00:00 2001 From: James Green Date: Wed, 13 Dec 2023 10:56:51 +0000 Subject: [PATCH 1/2] Last few tweeks Added NETWORK_TEMPLATE_ID argument Added more static config required by the mist API --- example.env | 1 + src/juniper.py | 53 ++++++++++++++++++++++++++++++-- src/main.py | 3 +- test/test_juniper.py | 72 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 120 insertions(+), 9 deletions(-) diff --git a/example.env b/example.env index 45963f3..ea8306b 100644 --- a/example.env +++ b/example.env @@ -5,3 +5,4 @@ ;MIST_API_TOKEN= ;SITE_GROUP_IDS={"moj_wifi": "foo","gov_wifi": "bar"} ;RF_TEMPLATE_ID= +;NETWORK_TEMPLATE_ID= diff --git a/src/juniper.py b/src/juniper.py index 5a67f1c..4cb6b0c 100644 --- a/src/juniper.py +++ b/src/juniper.py @@ -93,7 +93,6 @@ def check_if_we_need_to_append_gov_wifi_or_moj_wifi_site_groups(gov_wifi, moj_wi result.append(site_group_ids['gov_wifi']) return result - # Main function def juniper_script( data, @@ -102,7 +101,8 @@ def juniper_script( mist_username=None, mist_password=None, site_group_ids=None, - rf_template_id=None + rf_template_id=None, + network_template_id=None ): # Configure True/False to enable/disable additional logging of the API response objects @@ -116,7 +116,9 @@ def juniper_script( if site_group_ids is None: raise ValueError('Must provide site_group_ids for GovWifi & MoJWifi') if rf_template_id is None: - raise ValueError('Must rf_template_id') + raise ValueError('Must define rf_template_id') + if network_template_id is None: + raise ValueError('Must define network_template_id') # Establish Mist session admin = Admin(mist_api_token, mist_username, mist_password) @@ -130,6 +132,7 @@ def juniper_script( "latlng": {"lat": d.get('gps', '')[0], "lng": d.get('gps', '')[1]}, "country_code": d.get('country_code', ''), "rftemplate_id": rf_template_id, + "networktemplate_id": network_template_id, "timezone": d.get('time_zone', ''), "sitegroup_ids": check_if_we_need_to_append_gov_wifi_or_moj_wifi_site_groups( gov_wifi=d.get('Enable GovWifi', ''), @@ -141,6 +144,50 @@ def juniper_script( # MOJ specific attributes site_setting = { + "auto_upgrade": { + "enabled": True, + "version": "custom", + "time_of_day": "02:00", + "custom_versions": { + "AP45": "0.12.27066", + "AP32": "0.12.27066" + }, + "day_of_week": "" + }, + + "rogue": { + "min_rssi": -80, + "min_duration": 20, + "enabled": True, + "honeypot_enabled": True, + "whitelisted_bssids": [ + "" + ], + "whitelisted_ssids": [ + "GovWifi" + ] + }, + + "persist_config_on_device": True, + + "engagement": { + "dwell_tags": { + "passerby": "1-300", + "bounce": "3600-14400", + "engaged": "25200-36000", + "stationed": "50400-86400" + }, + "dwell_tag_names": { + "passerby": "Below 5 Min (Passerby)", + "bounce": "1-4 Hours", + "engaged": "7-10 Hours", + "stationed": "14-24 Hours" + } + }, + "analytic": { + "enabled": True + }, + "vars": { "site_specific_radius_wired_nacs_secret": d.get('Wired NACS Radius Key', ''), "site_specific_radius_govwifi_secret": d.get('GovWifi Radius Key', ''), diff --git a/src/main.py b/src/main.py index 2b152d6..489211f 100644 --- a/src/main.py +++ b/src/main.py @@ -56,5 +56,6 @@ def add_geocoding_to_json(data): site_group_ids=os.environ.get('SITE_GROUP_IDS'), org_id=os.environ.get('ORG_ID'), rf_template_id=os.environ.get('RF_TEMPLATE_ID'), - data=json_data_with_geocoding + data=json_data_with_geocoding, + network_template_id=os.environ.get('NETWORK_TEMPLATE_ID') ) diff --git a/test/test_juniper.py b/test/test_juniper.py index 4897079..1b98a6b 100644 --- a/test/test_juniper.py +++ b/test/test_juniper.py @@ -27,7 +27,8 @@ def test_juniper_script(self, mock_put, mock_post, mock_successful_login): mist_api_token='your_token', org_id='your_org_id', site_group_ids='{"moj_wifi": "foo","gov_wifi": "bar"}', - rf_template_id='8542a5fa-51e4-41be-83b9-acb416362cc0' + rf_template_id='8542a5fa-51e4-41be-83b9-acb416362cc0', + network_template_id='46b87163-abd2-4b08-a67f-1ccecfcfd061' ) # Assertions @@ -37,11 +38,57 @@ def test_juniper_script(self, mock_put, mock_post, mock_successful_login): 'latlng': {'lat': 1.23, 'lng': 4.56}, 'country_code': 'US', 'rftemplate_id': '8542a5fa-51e4-41be-83b9-acb416362cc0', + 'networktemplate_id': '46b87163-abd2-4b08-a67f-1ccecfcfd061', 'timezone': 'UTC', 'sitegroup_ids': [] }) mock_put.assert_called_once_with('/api/v1/sites/123/setting', { + + "auto_upgrade": { + "enabled": True, + "version": "custom", + "time_of_day": "02:00", + "custom_versions": { + "AP45": "0.12.27066", + "AP32": "0.12.27066" + }, + "day_of_week": "" + }, + + "rogue": { + "min_rssi": -80, + "min_duration": 20, + "enabled": True, + "honeypot_enabled": True, + "whitelisted_bssids": [ + "" + ], + "whitelisted_ssids": [ + "GovWifi" + ] + }, + + "persist_config_on_device": True, + + "engagement": { + "dwell_tags": { + "passerby": "1-300", + "bounce": "3600-14400", + "engaged": "25200-36000", + "stationed": "50400-86400" + }, + "dwell_tag_names": { + "passerby": "Below 5 Min (Passerby)", + "bounce": "1-4 Hours", + "engaged": "7-10 Hours", + "stationed": "14-24 Hours" + } + }, + "analytic": { + "enabled": True + }, + 'vars': { 'site_specific_radius_wired_nacs_secret': 'key1', 'site_specific_radius_govwifi_secret': 'key2', @@ -64,11 +111,26 @@ def test_juniper_script_missing_rf_template_id(self): org_id='your_org_id', mist_api_token='token', site_group_ids={ - 'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904', - 'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb' - }) + 'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904', + 'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'}, + network_template_id='46b87163-abd2-4b08-a67f-1ccecfcfd061' + ) + + self.assertEqual(str(cm.exception), 'Must define rf_template_id') + + def test_juniper_script_missing_network_template_id(self): + # Test when network_template_id is missing + with self.assertRaises(ValueError) as cm: + juniper_script([], + org_id='your_org_id', + mist_api_token='token', + site_group_ids={ + 'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904', + 'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'}, + rf_template_id='46b87163-abd2-4b08-a67f-1ccecfcfd061' + ) - self.assertEqual(str(cm.exception), 'Must rf_template_id') + self.assertEqual(str(cm.exception), 'Must define network_template_id') def test_juniper_script_missing_api_token(self): # Test when mist_api_token is missing From 941d3adf1eea2b80b36154239a4e86dcec348866 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 13 Dec 2023 10:58:42 +0000 Subject: [PATCH 2/2] Commit changes made by code formatters --- src/juniper.py | 2 ++ test/test_juniper.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/juniper.py b/src/juniper.py index 4cb6b0c..3bfb507 100644 --- a/src/juniper.py +++ b/src/juniper.py @@ -94,6 +94,8 @@ def check_if_we_need_to_append_gov_wifi_or_moj_wifi_site_groups(gov_wifi, moj_wi return result # Main function + + def juniper_script( data, mist_api_token=None, diff --git a/test/test_juniper.py b/test/test_juniper.py index 1b98a6b..8ce7836 100644 --- a/test/test_juniper.py +++ b/test/test_juniper.py @@ -111,10 +111,10 @@ def test_juniper_script_missing_rf_template_id(self): org_id='your_org_id', mist_api_token='token', site_group_ids={ - 'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904', + 'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904', 'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'}, - network_template_id='46b87163-abd2-4b08-a67f-1ccecfcfd061' - ) + network_template_id='46b87163-abd2-4b08-a67f-1ccecfcfd061' + ) self.assertEqual(str(cm.exception), 'Must define rf_template_id')