Skip to content

Commit

Permalink
Merge pull request #49 from Rahulbhatvedekar/migrate-cerberus-to-json…
Browse files Browse the repository at this point in the history
…schema

Migrate cerberus to jsonschema
  • Loading branch information
pwongcha authored Sep 9, 2024
2 parents 43069d9 + 135c00b commit c21eaf3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@

- appsec-create fail on brand new group without any config
- appsec-create version/activation note is empty

## 2.3.7

#### ENHANCEMENTS:

- Replaced `cerberus` with `jsonschema`
- Upgraded `pandas` to version `2.2.2`
4 changes: 2 additions & 2 deletions bin/akamai-onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from model.single_host import SingleHost
from tabulate import tabulate

PACKAGE_VERSION = '2.3.6'
PACKAGE_VERSION = '2.3.7'
logger = setup_logger()
root = get_cli_root_directory()

Expand Down Expand Up @@ -112,7 +112,7 @@ def init_config(config):
@pass_config
def cli(config, edgerc, section, account_key):
'''
Akamai CLI for onboarding properties v2.3.4
Akamai CLI for onboarding properties v2.3.7
'''
config.edgerc = edgerc
config.section = section
Expand Down
44 changes: 19 additions & 25 deletions bin/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from urllib import parse

import pandas as pd
from cerberus import Validator
from jsonschema import validate, ValidationError
from distutils.dir_util import copy_tree
from exceptions import get_cli_root_directory
from exceptions import setup_logger
Expand Down Expand Up @@ -1025,19 +1025,16 @@ def csv_validator(self, onboard_object, csv_file_loc: str):
'regex': (r'(.*\.edgekey\.net$|.*\.edgesuite\.net$)')}
}

v = Validator(schema)
logger.warning(f'Reading customer property name input: {csv_file_loc}')

with open(csv_file_loc, encoding='utf-8-sig', newline='') as f:
for i, row in enumerate(csv.DictReader(f), 1):
csv_dict.append(row)
valid = v.validate(row)
validation_errors = v.errors
if validation_errors:
try:
validate(instance=row, schema=schema)
except ValidationError as e:
onboard_object.valid_csv = False
logger.warning(f'CSV Validation Error in row: {i}...')
for error in validation_errors:
logger.warning(f'{error} {validation_errors[error]}')
logger.warning(f'CSV Validation Error in row: {i} - {e}')

onboard_object.csv_dict = csv_dict
return onboard_object.valid_csv
Expand All @@ -1056,19 +1053,16 @@ def csv_validator_appsec(self, onboard_object, csv_file_loc: str):
}
}

v = Validator(schema)
logger.warning(f'Reading csv input: {csv_file_loc}')

with open(csv_file_loc, encoding='utf-8-sig', newline='') as f:
for i, row in enumerate(csv.DictReader(f), 1):
csv_dict.append(row)
valid = v.validate(row)
validation_errors = v.errors
if validation_errors:
try:
validate(instance=row, schema=schema)
except ValidationError as e:
onboard_object.valid_csv = False
logger.warning(f'CSV Validation Error in row: {i}...')
for error in validation_errors:
logger.warning(f'{error} {validation_errors[error]}')
logger.warning(f'CSV Validation Error in row: {i} - {e}')

onboard_object.csv_dict = csv_dict
return onboard_object.valid_csv
Expand Down Expand Up @@ -1344,18 +1338,18 @@ def csv_2_appsec_create_by_hostname(self, csv_file_loc: str):
'required': False},
}

v = Validator(schema)
logger.warning(f'Reading customer security configuration input: {csv_file_loc}')
valid = True
with open(csv_file_loc, encoding='utf-8-sig', newline='') as f:
data = []
for i, row in enumerate(csv.DictReader(f), 1):
data.append(row)
v.validate(row)
if v.errors:
try:
validate(instance=row, schema=schema)
except ValidationError as e:
valid = False
for error in v.errors:
logger.error(f'CSV Validation Error in row: {i} {error}')
logger.error(f'CSV Validation Error in row: {i} - {e}')

return valid, data

def csv_2_appsec_create_by_propertyname(self, csv_file_loc: str):
Expand All @@ -1373,18 +1367,18 @@ def csv_2_appsec_create_by_propertyname(self, csv_file_loc: str):
'required': False}
}

v = Validator(schema)
logger.warning(f'Reading customer security configuration input: {csv_file_loc}')
valid = True
with open(csv_file_loc, encoding='utf-8-sig', newline='') as f:
data = []
for i, row in enumerate(csv.DictReader(f), 1):
data.append(row)
v.validate(row)
if v.errors:
try:
validate(instance=row, schema=schema)
except ValidationError as e:
valid = False
for error in v.errors:
logger.error(f'CSV Validation Error in row: {i} {error}')
logger.error(f'CSV Validation Error in row: {i} - {e}')

return valid, data

def populate_waf_data(self, by: str, input: dict) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"aliases": [
"onboard"
],
"version": "2.3.6",
"version": "2.3.7 ",
"description": "Onboard Akamai delivery and WAF configuration"
}
]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cerberus==1.3.4
chardet==3.0.4
click==7.1.1
coloredlogs==15.0.1
edgegrid-python==1.3.1
pandas==2.1.2
jsonschema==4.23.0
pandas==2.2.2
pyIsEmail==2.0.1
requests>=2.25.1,<3.0
rich==13.3.2
Expand Down

0 comments on commit c21eaf3

Please sign in to comment.