Update and refactor policy-related logic

This commit is contained in:
codeking 2025-11-27 08:46:59 +01:00
parent 8945ead9bd
commit 219a4d4dc1

View file

@ -2,13 +2,12 @@ from core.Constants import Constants
from core.Errors import MissingSubscriptionError, InvalidSubscriptionError, UnknownConnectionTypeError, ConnectionUnprotectedError, EndpointVerificationError, ProfileStateConflictError
from core.controllers.ApplicationController import ApplicationController
from core.controllers.ApplicationVersionController import ApplicationVersionController
from core.controllers.CapabilityPolicyController import CapabilityPolicyController
from core.controllers.ClientController import ClientController
from core.controllers.ClientVersionController import ClientVersionController
from core.controllers.ConfigurationController import ConfigurationController
from core.controllers.InvoiceController import InvoiceController
from core.controllers.LocationController import LocationController
from core.controllers.PrivilegePolicyController import PrivilegePolicyController
from core.controllers.PolicyController import PolicyController
from core.controllers.ProfileController import ProfileController
from core.controllers.SubscriptionController import SubscriptionController
from core.controllers.SubscriptionPlanController import SubscriptionPlanController
@ -403,34 +402,32 @@ if __name__ == '__main__':
elif arguments.command == 'policy':
policy_controller = None
if arguments.subcommand is None:
policy_parser.print_help()
elif arguments.policy == 'capability':
policy_controller = CapabilityPolicyController
policy = PolicyController.get(arguments.policy)
elif arguments.policy == 'privilege':
policy_controller = PrivilegePolicyController
if policy_controller is not None:
if policy is not None:
if arguments.subcommand == 'preview':
print(policy_controller.preview())
print(PolicyController.preview(policy))
elif arguments.subcommand == 'instate':
policy_controller.instate()
PolicyController.instate(policy)
elif arguments.subcommand == 'inspect':
if policy_controller.is_instated():
pprint.pp({'status': 'Active'})
if PolicyController.is_instated(policy):
pprint.pp({'status': 'Instated'})
elif PolicyController.is_suggestible(policy):
pprint.pp({'status': 'Suggested'})
else:
pprint.pp({'status': 'Inactive'})
pprint.pp({'status': 'Uninstated'})
elif arguments.subcommand == 'revoke':
policy_controller.revoke()
PolicyController.revoke(policy)
elif arguments.command == 'get':