Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions framework/python/src/common/risk_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def get_file_path(self):
self.name + '.json')

def _validate(self, profile_json, profile_format):
if self._valid(profile_json, profile_format):
if self._expired():
self.status = 'Expired'
if self._expired():
self.status = 'Expired'
elif self._valid(profile_json, profile_format):
# User only wants to save a draft
elif 'status' in profile_json and profile_json['status'] == 'Draft':
if 'status' in profile_json and profile_json['status'] == 'Draft':
self.status = 'Draft'
else:
self.status = 'Valid'
Expand Down
26 changes: 10 additions & 16 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
MAX_DEVICE_REPORTS_KEY = 'max_device_reports'
CERTS_PATH = 'local/root_certs'
CONFIG_FILE_PATH = 'local/system.json'
SECONDS_IN_YEAR = 31536000

PROFILE_FORMAT_PATH = 'resources/risk_assessment.json'
PROFILES_DIR = 'local/risk_profiles'
Expand Down Expand Up @@ -402,17 +401,26 @@ def _load_profiles(self):
try:
for risk_profile_file in os.listdir(
os.path.join(self._root_dir, PROFILES_DIR)):

LOGGER.debug(f'Discovered profile {risk_profile_file}')

# Open the risk profile file
with open(os.path.join(self._root_dir, PROFILES_DIR, risk_profile_file),
encoding='utf-8') as f:

# Parse risk profile json
json_data = json.load(f)

# Instantiate a new risk profile
risk_profile = RiskProfile()

# Pass JSON to populate risk profile
risk_profile.load(
profile_json=json_data,
profile_format=self._profile_format
)
risk_profile.status = self.check_profile_status(risk_profile)

# Add risk profile to session
self._profiles.append(risk_profile)

except Exception as e:
Expand Down Expand Up @@ -527,20 +535,6 @@ def update_profile(self, profile_json):

return risk_profile

def check_profile_status(self, profile):

if profile.status == 'Valid':

# Check expiry
created_date = profile.created.timestamp()

today = datetime.datetime.now().timestamp()

if created_date < (today - SECONDS_IN_YEAR):
profile.status = 'Expired'

return profile.status

def delete_profile(self, profile):

try:
Expand Down
6 changes: 0 additions & 6 deletions testing/unit/services/output/services.log

This file was deleted.