Fix AppArmor name-related exceptions (#4078)

- 'Too many' is misleading if there are no profiles.
- profiles just returns set() -- using profile_file should be more correct.
This commit is contained in:
n0toose 2023-01-18 21:04:27 +01:00 committed by GitHub
parent 99e0eab958
commit 47fd849319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,9 +25,15 @@ def get_profile_name(profile_file):
f"Can't read AppArmor profile: {err}", _LOGGER.error
) from err
if len(profiles) == 0:
raise AppArmorInvalidError(
f"Missing AppArmor profile inside file: {profile_file.name}", _LOGGER.error
)
if len(profiles) != 1:
raise AppArmorInvalidError(
f"To many profiles inside file: {profiles}", _LOGGER.error
f"Too many AppArmor profiles inside file: {profile_file.name}",
_LOGGER.error,
)
return profiles.pop()