<commit_before>#!/usr/bin/env python



__author__ = '<NAME>'
__license__ = 'Apache 2.0'

from interface.services.coi.ipolicy_management_service import BasePolicyManagementService
from pyon.core.exception import NotFound, BadRequest
from pyon.public import PRED, RT, Container
from pyon.util.containers import is_basic_identifier
from pyon.util.log import log

MANAGER_ROLE = 'ORG_MANAGER'
MEMBER_ROLE = 'ORG_MEMBER'


class PolicyManagementService(BasePolicyManagementService):

    """
    Provides the interface to define and manage policy and a repository to store and retrieve policy and templates for
    policy definitions, aka attribute authority.
    """
    def create_policy(self, policy=None):
        """Persists the provided Policy object for the specified Org id. The id string returned
        is the internal id by which Policy will be identified in the data store.

        @param policy    Policy
        @retval policy_id    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """
        if not is_basic_identifier(policy.name):
            raise BadRequest("The policy name '%s' can only contain alphanumeric and underscore characters" % user_role.name)

        policy.rule = policy.rule % (policy.name, policy.description)
        policy_id, version = self.clients.resource_registry.create(policy)
        return policy_id

    def update_policy(self, policy=None):
        """Updates the provided Policy object.  Throws NotFound exception if
        an existing version of Policy is not found.  Throws Conflict if
        the provided Policy object is not based on the latest persisted
        version of the object.

        @param policy    Policy<commit_msg>Added ION Manager as Super User Role<commit_after>#!/usr/bin/env python



__author__ = '<NAME>'
__license__ = 'Apache 2.0'

from interface.services.coi.ipolicy_management_service import BasePolicyManagementService
from pyon.core.exception import NotFound, BadRequest
from pyon.public import PRED, RT, Container
from pyon.util.containers import is_basic_identifier
from pyon.util.log import log

MANAGER_ROLE = 'ORG_MANAGER'  # Can only act upon resource within the specific Org
MEMBER_ROLE = 'ORG_MEMBER'    # Can only access resources within the specific Org
ION_MANAGER = 'ION_MANAGER'   # Can act upon resources across all Orgs - like a Super User access


class PolicyManagementService(BasePolicyManagementService):

    """
    Provides the interface to define and manage policy and a repository to store and retrieve policy and templates for
    policy definitions, aka attribute authority.
    """
    def create_policy(self, policy=None):
        """Persists the provided Policy object for the specified Org id. The id string returned
        is the internal id by which Policy will be identified in the data store.

        @param policy    Policy
        @retval policy_id    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """
        if not is_basic_identifier(policy.name):
            raise BadRequest("The policy name '%s' can only contain alphanumeric and underscore characters" % user_role.name)

        policy.rule = policy.rule % (policy.name, policy.description)
        policy_id, version = self.clients.resource_registry.create(policy)
        return policy_id

    def update_policy(self, policy=None):
        """Updates the provided Policy object.  Throws NotFound exception if
        an existing version of Policy is not found.  Throws Conflict if
        the provided Policy object is not based on the latest persisted
        version of the object.

        @param policy    Policy
{'fraction_non_alphanumeric': 0.05861504907306434, 'fraction_numerical': 0.0010905125408942203, 'mean_word_length': 3.3782816229116945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '646227', 'n_tokens_mistral': 967, 'n_tokens_neox': 942, 'n_words': 382}