Add initial support for capability policies

This commit is contained in:
codeking 2025-11-27 08:04:20 +01:00
parent a91cd88f3a
commit 8945ead9bd

View file

@ -2,6 +2,7 @@ from core.Constants import Constants
from core.Errors import MissingSubscriptionError, InvalidSubscriptionError, UnknownConnectionTypeError, ConnectionUnprotectedError, EndpointVerificationError, ProfileStateConflictError from core.Errors import MissingSubscriptionError, InvalidSubscriptionError, UnknownConnectionTypeError, ConnectionUnprotectedError, EndpointVerificationError, ProfileStateConflictError
from core.controllers.ApplicationController import ApplicationController from core.controllers.ApplicationController import ApplicationController
from core.controllers.ApplicationVersionController import ApplicationVersionController from core.controllers.ApplicationVersionController import ApplicationVersionController
from core.controllers.CapabilityPolicyController import CapabilityPolicyController
from core.controllers.ClientController import ClientController from core.controllers.ClientController import ClientController
from core.controllers.ClientVersionController import ClientVersionController from core.controllers.ClientVersionController import ClientVersionController
from core.controllers.ConfigurationController import ConfigurationController from core.controllers.ConfigurationController import ConfigurationController
@ -162,7 +163,7 @@ if __name__ == '__main__':
policy_subparsers = policy_parser.add_subparsers(title='subcommands', dest='subcommand') policy_subparsers = policy_parser.add_subparsers(title='subcommands', dest='subcommand')
policy_base_parser = argparse.ArgumentParser(add_help=False) policy_base_parser = argparse.ArgumentParser(add_help=False)
policy_base_parser.add_argument('--policy', '-p', choices=['privilege'], required=True) policy_base_parser.add_argument('--policy', '-p', choices=['capability', 'privilege'], required=True)
policy_preview_parser = policy_subparsers.add_parser('preview', parents=[policy_base_parser]) policy_preview_parser = policy_subparsers.add_parser('preview', parents=[policy_base_parser])
policy_instate_parser = policy_subparsers.add_parser('instate', parents=[policy_base_parser]) policy_instate_parser = policy_subparsers.add_parser('instate', parents=[policy_base_parser])
@ -402,26 +403,34 @@ if __name__ == '__main__':
elif arguments.command == 'policy': elif arguments.command == 'policy':
policy_controller = None
if arguments.subcommand is None: if arguments.subcommand is None:
policy_parser.print_help() policy_parser.print_help()
elif arguments.policy == 'capability':
policy_controller = CapabilityPolicyController
elif arguments.policy == 'privilege': elif arguments.policy == 'privilege':
policy_controller = PrivilegePolicyController
if policy_controller is not None:
if arguments.subcommand == 'preview': if arguments.subcommand == 'preview':
print(PrivilegePolicyController.preview()) print(policy_controller.preview())
elif arguments.subcommand == 'instate': elif arguments.subcommand == 'instate':
PrivilegePolicyController.instate() policy_controller.instate()
elif arguments.subcommand == 'inspect': elif arguments.subcommand == 'inspect':
if PrivilegePolicyController.is_instated(): if policy_controller.is_instated():
pprint.pp({'status': 'Active'}) pprint.pp({'status': 'Active'})
else: else:
pprint.pp({'status': 'Inactive'}) pprint.pp({'status': 'Inactive'})
elif arguments.subcommand == 'revoke': elif arguments.subcommand == 'revoke':
PrivilegePolicyController.revoke() policy_controller.revoke()
elif arguments.command == 'get': elif arguments.command == 'get':