本文整理匯總了Python中interface.services.coi.iorg_management_service.OrgManagementServiceProcessClient類的典型用法代碼示例。如果您正苦於以下問題:Python OrgManagementServiceProcessClient類的具體用法?Python OrgManagementServiceProcessClient怎麽用?Python OrgManagementServiceProcessClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了OrgManagementServiceProcessClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_user_info_extension
def get_user_info_extension(self, user_info_id=''):
"""Returns an UserInfoExtension object containing additional related information
@param user_info_id str
@retval user_info UserInfoExtension
@throws BadRequest A parameter is missing
@throws NotFound An object with the specified user_id does not exist
"""
if not user_info_id:
raise BadRequest("The user_id parameter is empty")
extended_resource_handler = ExtendedResourceContainer(self)
extended_user = extended_resource_handler.create_extended_resource_container(OT.UserInfoExtension, user_info_id)
#If the org_id is not provided then skip looking for Org related roles.
if extended_user:
#Did not setup a dependency to org_management service to avoid a potential circular bootstrap issue
# since this method should never be called until the system is fully running
try:
org_client = OrgManagementServiceProcessClient(process=self)
roles = org_client.find_all_roles_by_user(extended_user.actor_identity._id)
extended_user.roles = list()
for org_name in roles:
for role in roles[org_name]:
flattened_role = copy.copy(role.__dict__)
del flattened_role['type_'] #Have to do this to appease the message validators for ION objects
flattened_role['org_name'] = org_name #Nothing like forcing a value into the dict to appease the UI code
extended_user.roles.append(flattened_role)
except Exception, e:
raise NotFound('Could not retrieve UserRoles for User Info id: %s - %s' % (user_info_id, e.message))
示例2: get_user_info_extension
def get_user_info_extension(self, user_info_id='', org_id=''):
"""Returns an UserInfoExtension object containing additional related information
@param user_info_id str
@param org_id str - An optional org id that the user is interested in filtering against.
@retval user_info UserInfoExtension
@throws BadRequest A parameter is missing
@throws NotFound An object with the specified actor_id does not exist
"""
if not user_info_id:
raise BadRequest("The user_info_id parameter is empty")
#THis is a hack to get the UI going. It would be preferable to get the actor id from the extended resource
#container below, but their would need to be a guarantee of order of field processing in order
#to ensure that the actor identity has been found BEFORE the negotiation methods are called - and probably
#some elegant way to indicate the field and sub field; ie actor_identity._id
actors, _ = self.clients.resource_registry.find_subjects(subject_type=RT.ActorIdentity, predicate=PRED.hasInfo, object=user_info_id, id_only=True)
actor_id = actors[0] if len(actors) > 0 else ''
extended_resource_handler = ExtendedResourceContainer(self)
extended_user = extended_resource_handler.create_extended_resource_container(
extended_resource_type=OT.UserInfoExtension,
resource_id=user_info_id,
computed_resource_type=OT.ComputedAttributes,
user_id=user_info_id,
org_id=org_id,
actor_id=actor_id)
#If the org_id is not provided then skip looking for Org related roles.
if extended_user:
#Did not setup a dependency to org_management service to avoid a potential circular bootstrap issue
# since this method should never be called until the system is fully running
try:
org_client = OrgManagementServiceProcessClient(process=self)
roles = org_client.find_all_roles_by_user(extended_user.actor_identity._id)
extended_user.roles = list()
for org_name in roles:
for role in roles[org_name]:
flattened_role = copy.copy(role.__dict__)
del flattened_role['type_'] #Have to do this to appease the message validators for ION objects
flattened_role['org_name'] = org_name #Nothing like forcing a value into the dict to appease the UI code
extended_user.roles.append(flattened_role)
except Exception, e:
raise NotFound('Could not retrieve UserRoles for User Info id: %s - %s' % (user_info_id, e.message))
#filter notification requests that are retired
extended_user.subscriptions = [nr for nr in extended_user.subscriptions if nr.temporal_bounds.end_datetime == '']
#filter owned resources that are retired
nr_removed = []
for rsrc in extended_user.owned_resources:
#remove all the Notifications
if rsrc.type_ != OT.NotificationRequest:
nr_removed.append(rsrc)
extended_user.owned_resources = [rsrc for rsrc in nr_removed if rsrc.lcstate != 'DELETED']
#now append the active NotificationRequests
extended_user.owned_resources.extend(extended_user.subscriptions)
示例3: get_actor_identity_extension
def get_actor_identity_extension(self, user_id="", org_id="", ext_associations=None, ext_exclude=None):
"""Returns an ActorIdentityExtension object containing additional related information
@param user_id str
@param org_id str
@param ext_associations dict
@param ext_exclude list
@retval actor_identity ActorIdentityExtension
@throws BadRequest A parameter is missing
@throws NotFound An object with the specified user_id does not exist
"""
if not user_id:
raise BadRequest("The user_id parameter is empty")
extended_resource_handler = ExtendedResourceContainer(self)
extended_user = extended_resource_handler.create_extended_resource_container(
OT.ActorIdentityExtension, user_id, None, ext_associations, ext_exclude
)
# If the org_id is not provided then skip looking for Org related roles.
if org_id:
# Did not setup a dependency to org_management service to avoid a potential circular bootstrap issue
# since this method should never be called until the system is fully running
try:
org_client = OrgManagementServiceProcessClient(process=self)
roles = org_client.find_org_roles_by_user(org_id, user_id)
extended_user.roles = roles
except Exception, e:
# If this information is not available yet, them just move on and caller can retry later
pass
示例4: build_message_headers
def build_message_headers( ion_actor_id, expiry):
headers = dict()
headers['ion-actor-id'] = ion_actor_id
headers['expiry'] = expiry
#If this is an anonymous requester then there are no roles associated with the request
if ion_actor_id == DEFAULT_ACTOR_ID:
headers['ion-actor-roles'] = dict()
return headers
try:
#Check to see if the user's roles are cached already - keyed by user id
if service_gateway_instance.user_data_cache.has_key(ion_actor_id):
role_header = service_gateway_instance.user_data_cache.get(ion_actor_id)
if role_header is not None:
headers['ion-actor-roles'] = role_header
return headers
#The user's roles were not cached so hit the datastore to find it.
org_client = OrgManagementServiceProcessClient(node=Container.instance.node, process=service_gateway_instance)
org_roles = org_client.find_all_roles_by_user(ion_actor_id, headers={"ion-actor-id": service_gateway_instance.name, 'expiry': DEFAULT_EXPIRY })
role_header = service_gateway_instance.container.governance_controller.get_role_message_headers(org_roles)
#Cache the roles by user id
service_gateway_instance.user_data_cache.put(ion_actor_id, role_header)
except Exception, e:
role_header = dict() # Default to empty dict if there is a problem finding roles for the user
示例5: seed_gov
def seed_gov(container, process=FakeProcess()):
id_client = IdentityManagementServiceProcessClient(node=container.node, process=process)
org_client = OrgManagementServiceProcessClient(node=container.node, process=process)
ion_org = org_client.find_org()
try:
myorg = org_client.read_org()
except Exception, e:
log.info("This should fail")
log.info(e.message)
示例6: test_policy
def test_policy(container, process=FakeProcess()):
org_client = OrgManagementServiceProcessClient(node=container.node, process=process)
ion_org = org_client.find_org()
id_client = IdentityManagementServiceProcessClient(node=container.node, process=process)
system_actor = id_client.find_actor_identity_by_name(name=CFG.system.system_actor)
log.info('system actor:' + system_actor._id)
policy_client = PolicyManagementServiceProcessClient(node=container.node, process=process)
header_roles = get_role_message_headers(org_client.find_all_roles_by_user(system_actor._id))
users = org_client.find_enrolled_users(ion_org._id, headers={'ion-actor-id': system_actor._id, 'ion-actor-roles': header_roles })
for u in users:
log.info( str(u))
user = id_client.find_actor_identity_by_name('/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Roger Unwin A254')
log.debug('user_id: ' + user._id)
roles = org_client.find_roles_by_user(ion_org._id, user._id)
for r in roles:
log.info('User UserRole: ' +str(r))
header_roles = get_role_message_headers(org_client.find_all_roles_by_user(user._id))
try:
org_client.grant_role(ion_org._id, user._id, 'INSTRUMENT_OPERATOR', headers={'ion-actor-id': user._id, 'ion-actor-roles': header_roles })
except Exception, e:
log.info('This grant role should be denied:' + e.message)
示例7: on_initial_bootstrap
def on_initial_bootstrap(self, process, config, **kwargs):
org_ms_client = OrgManagementServiceProcessClient(process=process)
ex_ms_client = ExchangeManagementServiceProcessClient(process=process)
system_actor, _ = process.container.resource_registry.find_resources(
restype=RT.ActorIdentity, name=config.system.system_actor, id_only=True
)
if not system_actor:
raise AbortBootstrap("Cannot find system actor")
system_actor_id = system_actor[0]
# Create root Org: ION
root_orgname = config.system.root_org
org = Org(name=root_orgname, description="ION Root Org")
self.org_id = org_ms_client.create_org(org)
# Instantiate initial set of User Roles for this Org
ion_manager = UserRole(governance_name=ION_MANAGER, name="ION Manager", description="ION Manager")
org_ms_client.add_user_role(self.org_id, ion_manager)
org_ms_client.grant_role(self.org_id, system_actor_id, ION_MANAGER)
# Make the ION system agent a manager for the ION Org
org_ms_client.grant_role(self.org_id, system_actor_id, ORG_MANAGER_ROLE)
# Create root ExchangeSpace
xs = ExchangeSpace(name=ION_ROOT_XS, description="ION service XS")
self.xs_id = ex_ms_client.create_exchange_space(xs, self.org_id)
示例8: find_user_open_requests
def find_user_open_requests(self, user_info_id='', actor_id='', org_id=''):
"""
Local function to be called by extended resource framework from get_user_info_extension operation. The first
parameter MUST be the same user_info_id from that operation even though it is not used.
@param user_info_id:
@param actor_id:
@param org_id:
@return:
"""
org_client = OrgManagementServiceProcessClient(process=self)
neg_list = org_client.find_user_negotiations(actor_id=actor_id, org_id=org_id, negotiation_status=NegotiationStatusEnum.OPEN)
return self._convert_negotiations_to_requests(neg_list, user_info_id, org_id)
示例9: start
def start(self):
log.debug("GovernanceController starting ...")
config = CFG.interceptor.interceptors.governance.config
if config is None:
config['enabled'] = False
if "enabled" in config:
self.enabled = config["enabled"]
log.debug("GovernanceInterceptor enabled: %s" % str(self.enabled))
self.resource_policy_event_subscriber = None
if self.enabled:
self.initialize_from_config(config)
self.resource_policy_event_subscriber = EventSubscriber(event_type="ResourcePolicyEvent", callback=self.policy_event_callback)
self.resource_policy_event_subscriber.activate()
self.rr_client = ResourceRegistryServiceProcessClient(node=self.container.node, process=self.container)
self.policy_client = PolicyManagementServiceProcessClient(node=self.container.node, process=self.container)
self.org_client = OrgManagementServiceProcessClient(node=self.container.node, process=self.container)
示例10: setUp
def setUp(self):
# Start container
self._start_container()
#Load a deploy file that also loads basic policy.
self.container.start_rel_from_url('res/deploy/r2gov.yml')
process=FakeProcess()
self.rr_client = ResourceRegistryServiceProcessClient(node=self.container.node, process=process)
self.id_client = IdentityManagementServiceProcessClient(node=self.container.node, process=process)
self.org_client = OrgManagementServiceProcessClient(node=self.container.node, process=process)
self.ims_client = InstrumentManagementServiceProcessClient(node=self.container.node, process=process)
self.ion_org = self.org_client.find_org()
self.system_actor = self.id_client.find_actor_identity_by_name(name=CFG.system.system_actor)
log.debug('system actor:' + self.system_actor._id)
sa_header_roles = get_role_message_headers(self.org_client.find_all_roles_by_user(self.system_actor._id))
self.sa_user_header = {'ion-actor-id': self.system_actor._id, 'ion-actor-roles': sa_header_roles }
示例11: resolve_org_negotiation
def resolve_org_negotiation():
try:
payload = request.form['payload']
json_params = json_loads(str(payload))
ion_actor_id, expiry = get_governance_info_from_request('serviceRequest', json_params)
ion_actor_id, expiry = validate_request(ion_actor_id, expiry)
headers = build_message_headers(ion_actor_id, expiry)
# extract negotiation-specific data (convert from unicode just in case - these are machine generated and unicode specific
# chars are unexpected)
verb = str(json_params['verb'])
originator = str(json_params['originator'])
negotiation_id = str(json_params['negotiation_id'])
reason = str(json_params.get('reason', ''))
proposal_status = None
if verb.lower() == "accept":
proposal_status = ProposalStatusEnum.ACCEPTED
elif verb.lower() == "reject":
proposal_status = ProposalStatusEnum.REJECTED
proposal_originator = None
if originator.lower() == "consumer":
proposal_originator = ProposalOriginatorEnum.CONSUMER
elif originator.lower() == "provider":
proposal_originator = ProposalOriginatorEnum.PROVIDER
rr_client = ResourceRegistryServiceProcessClient(process=service_gateway_instance)
negotiation = rr_client.read(negotiation_id, headers=headers)
new_negotiation_sap = Negotiation.create_counter_proposal(negotiation, proposal_status, proposal_originator)
org_client = OrgManagementServiceProcessClient(process=service_gateway_instance)
resp = org_client.negotiate(new_negotiation_sap, headers=headers)
# update reason if it exists
if reason:
# reload negotiation because it has changed
negotiation = rr_client.read(negotiation_id, headers=headers)
negotiation.reason = reason
rr_client.update(negotiation)
return gateway_json_response(resp)
except Exception as e:
return build_error_response(e)
示例12: test_requests
def test_requests(container, process=FakeProcess()):
org_client = OrgManagementServiceProcessClient(node=container.node, process=process)
ion_org = org_client.find_org()
id_client = IdentityManagementServiceProcessClient(node=container.node, process=process)
rr_client = ResourceRegistryServiceProcessClient(node=container.node, process=process)
system_actor = id_client.find_actor_identity_by_name(name=CFG.system.system_actor)
log.info('system actor:' + system_actor._id)
sa_header_roles = get_role_message_headers(org_client.find_all_roles_by_user(system_actor._id))
try:
user = id_client.find_actor_identity_by_name('/DC=org/DC=cilogon/C=US/O=ProtectNetwork/CN=Roger Unwin A254')
except:
raise Inconsistent("The test user is not found; did you seed the data?")
log.debug('user_id: ' + user._id)
user_header_roles = get_role_message_headers(org_client.find_all_roles_by_user(user._id))
try:
org2 = org_client.find_org('Org2')
org2_id = org2._id
except NotFound, e:
org2 = IonObject(RT.Org, name='Org2', description='A second Org')
org2_id = org_client.create_org(org2, headers={'ion-actor-id': system_actor._id, 'ion-actor-roles': sa_header_roles })
示例13: on_initial_bootstrap
def on_initial_bootstrap(self, process, config, **kwargs):
org_ms_client = OrgManagementServiceProcessClient(process=process)
ex_ms_client = ExchangeManagementServiceProcessClient(process=process)
system_actor, _ = process.container.resource_registry.find_resources(
restype=RT.ActorIdentity, name=config.system.system_actor, id_only=True)
if not system_actor:
raise AbortBootstrap("Cannot find system actor")
system_actor_id = system_actor[0]
# Create root Org: ION
root_orgname = config.system.root_org
org = Org(name=root_orgname, description="ION Root Org")
self.org_id = org_ms_client.create_org(org, headers={'ion-actor-id': system_actor_id})
# Instantiate initial set of User Roles for this Org
ion_manager = UserRole(name=ION_MANAGER,label='ION Manager', description='ION Manager')
org_ms_client.add_user_role(self.org_id, ion_manager)
org_ms_client.grant_role(self.org_id, system_actor_id, ION_MANAGER, headers={'ion-actor-id': system_actor_id} )
# Make the ION system agent a manager for the ION Org
org_ms_client.grant_role(self.org_id, system_actor_id, MANAGER_ROLE, headers={'ion-actor-id': system_actor_id} )
# Create root ExchangeSpace
xs = ExchangeSpace(name=ION_ROOT_XS, description="ION service XS")
self.xs_id = ex_ms_client.create_exchange_space(xs, self.org_id, headers={'ion-actor-id': system_actor_id})
# Now load the base set of negotiation definitions used by the request operations (enroll/role/resource, etc)
neg_def = NegotiationDefinition(name=RT.EnrollmentRequest,
description='Definition of Enrollment Request Negotiation',
pre_condition = ['is_registered(user_id)', 'is_not_enrolled(org_id,user_id)', 'enroll_req_not_exist(org_id,user_id)'],
accept_action = 'enroll_member(org_id,user_id)'
)
process.container.resource_registry.create(neg_def)
neg_def = NegotiationDefinition(name=RT.RoleRequest,
description='Definition of Role Request Negotiation',
pre_condition = ['is_enrolled(org_id,user_id)'],
accept_action = 'grant_role(org_id,user_id,role_name)'
)
process.container.resource_registry.create(neg_def)
neg_def = NegotiationDefinition(name=RT.ResourceRequest,
description='Definition of Role Request Negotiation',
pre_condition = ['is_enrolled(org_id,user_id)'],
accept_action = 'acquire_resource(org_id,user_id,resource_id)'
)
process.container.resource_registry.create(neg_def)
示例14: seed_gov
def seed_gov(container, process=FakeProcess()):
dp_client = DataProductManagementServiceProcessClient(node=container.node, process=process)
dp_obj = IonObject(RT.DataProduct, name='DataProd1', description='some new dp')
dp_client.create_data_product(dp_obj)
dp_obj = IonObject(RT.DataProduct,
name='DataProd2',
description='and of course another new dp')
dp_client.create_data_product(dp_obj,)
dp_obj = IonObject(RT.DataProduct,
name='DataProd3',
description='yet another new dp')
dp_client.create_data_product(dp_obj,)
log.debug('Data Products')
dp_list = dp_client.find_data_products()
for dp_obj in dp_list:
log.debug( str(dp_obj))
ims_client = InstrumentManagementServiceProcessClient(node=container.node, process=process)
ia_obj = IonObject(RT.InstrumentAgent, name='Instrument Agent1', description='The first Instrument Agent')
ims_client.create_instrument_agent(ia_obj)
ia_obj = IonObject(RT.InstrumentAgent, name='Instrument Agent2', description='The second Instrument Agent')
ims_client.create_instrument_agent(ia_obj)
log.debug( 'Instrument Agents')
ia_list = ims_client.find_instrument_agents()
for ia_obj in ia_list:
log.debug( str(ia_obj))
org_client = OrgManagementServiceProcessClient(node=container.node, process=process)
ion_org = org_client.find_org()
policy_client = PolicyManagementServiceProcessClient(node=container.node, process=process)
role_obj = IonObject(RT.UserRole, name='Instrument Operator', description='Users assigned to this role are instrument operators')
role_id = policy_client.create_role(role_obj)
org_client.add_user_role(ion_org._id, role_id)
try:
role_id = policy_client.create_role(role_obj)
org_client.add_user_role(ion_org._id, role_id)
except Exception, e:
log.info("This should fail")
log.info(e.message)
示例15: __init__
def __init__(self, pa):
"""
Called by platform agent upon its initialization so there is a driver
already created and configured.
@param pa The associated platform agent object to access the
elements handled by this helper.
"""
self._agent = pa
self._platform_id = pa._platform_id
# mission_id -> MissionScheduler mapping:
self._running_missions = {}
log.debug('%r: [mm] MissionManager created', self._platform_id)
self._provider_id = self._agent._provider_id
self._actor_id = self._agent._actor_id
log.debug('%r: [xa] provider_id=%r actor_id=%r', self._platform_id, self._provider_id, self._actor_id)
# ctx = self._agent.get_context()
# self._actor_id = ctx.get('ion-actor-id', None) if ctx else None
# log.debug('[xa] actor_id=%r', self._actor_id)
if self._actor_id is None:
log.warn('%r: [xa] actor_id is None', self._platform_id)
# _exaccess: resource_id -> {'commitment_id': id, 'mission_ids': [mission_id, ...]}:
# the agents we have acquired exclusive access to. We remove the actual exclusive
# access when there are no more associated mission_id's for a given resource_id.
self._exaccess = {}
self.ORG = OrgManagementServiceProcessClient(process=self._agent)
self.RR = ResourceRegistryServiceClient()
# TODO what's the correct way to obtain the actor header? the following is
# working but likely because the same call is done in
# base_test_platform_agent_with_rsn for the IMS.start_platform_agent_instance call
self._actor_header = get_system_actor_header()
log.debug('%r: [xa] actor_header=%s', self._platform_id, self._actor_header)