Skip to content

Commit

Permalink
Merge pull request #9 from ministryofjustice/tweeks
Browse files Browse the repository at this point in the history
Last few tweeks
  • Loading branch information
jamesgreen-moj authored Dec 13, 2023
2 parents c093467 + 941d3ad commit 43e09f8
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 8 deletions.
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
;MIST_API_TOKEN=
;SITE_GROUP_IDS={"moj_wifi": "foo","gov_wifi": "bar"}
;RF_TEMPLATE_ID=
;NETWORK_TEMPLATE_ID=
55 changes: 52 additions & 3 deletions src/juniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ 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,
mist_api_token=None,
org_id=None,
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
Expand All @@ -116,7 +118,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)
Expand All @@ -130,6 +134,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', ''),
Expand All @@ -141,6 +146,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', ''),
Expand Down
3 changes: 2 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
70 changes: 66 additions & 4 deletions test/test_juniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -65,10 +112,25 @@ def test_juniper_script_missing_rf_template_id(self):
mist_api_token='token',
site_group_ids={
'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904',
'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'
})
'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
Expand Down

0 comments on commit 43e09f8

Please sign in to comment.