requestMessenger.py (8168B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\messengers\entitlements\corporation\structure\requestMessenger.py 2 import logging 3 import uuid 4 import blue 5 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER 6 from cosmetics.client.structures.license import create_structure_paintwork_license_from_proto_license 7 from cosmetics.common.structures.priceCatalogue import PriceCatalogue 8 from google.protobuf.duration_pb2 import Duration 9 import eveProto.generated.eve_public.cosmetic.structure.paintwork.license.api.api_pb2 as api 10 import eveProto.generated.eve_public.cosmetic.structure.paintwork.api.admin.admin_pb2 as admin_api 11 from eveProto.generated.eve_public.cosmetic.structure.paintwork.license.license_pb2 import Identifier as LicenseIdentifier 12 from eveProto.generated.eve_public.structure.structure_pb2 import Identifier as StructureIdentifier 13 from eveProto.generated.eve_public.corporation.corporation_pb2 import Identifier as CorporationIdentifier 14 from eveProto.generated.eve_public.corporation.loyalty_pb2 import Points 15 from cosmetics.common.structures.fitting import StructurePaintwork 16 from cosmetics.common.structures.exceptions import InsufficientBalanceError, InsufficientRolesError, InvalidDataError, LicenseNotFoundException, ForbiddenRequestError 17 from cosmetics.client.structures.fitting import create_proto_slot_config_from_structure_paintwork 18 import cosmetics.client.messengers.entitlements.corporation.structure.qaconst as qa 19 from appConst import corpHeraldry 20 from publicGateway.grpc.exceptions import GenericException 21 TIMEOUT_SECONDS = 10 22 logger = logging.getLogger(__name__) 23 24 class PublicRequestsMessenger(object): 25 public_gateway = None 26 27 def __init__(self, public_gateway): 28 self.public_gateway = public_gateway 29 30 def issue_request(self, structure_paintwork, duration, structures): 31 if session and session.role & ROLE_PROGRAMMER: 32 if qa.FORCE_STRUCTURE_ISSUE_LICENSE_DELAY > 0: 33 blue.synchro.Sleep(qa.FORCE_STRUCTURE_ISSUE_LICENSE_DELAY * 1000) 34 if qa.FORCE_STRUCTURE_ISSUE_LICENSE_ERRORS: 35 raise Exception 36 request = api.IssueRequest(paintwork=create_proto_slot_config_from_structure_paintwork(structure_paintwork), duration=Duration(seconds=duration), structures=[ StructureIdentifier(sequential=s) for s in structures ]) 37 response_primitive, response_payload = self.blocking_request(request, api.IssueResponse) 38 response_licenses = [] 39 for proto_license in response_payload.licenses: 40 response_licenses.append(create_structure_paintwork_license_from_proto_license(uuid.UUID(bytes=proto_license.id.uuid), proto_license.attributes)) 41 42 return response_licenses 43 44 def revoke_request(self, license_id): 45 if session and session.role & ROLE_PROGRAMMER: 46 if qa.FORCE_STRUCTURE_REVOKE_LICENSE_DELAY > 0: 47 blue.synchro.Sleep(qa.FORCE_STRUCTURE_REVOKE_LICENSE_DELAY * 1000) 48 if qa.FORCE_STRUCTURE_REVOKE_LICENSE_ERRORS: 49 raise Exception 50 request = api.RevokeRequest(license=LicenseIdentifier(uuid=license_id.get_bytes())) 51 self.blocking_request(request, api.RevokeResponse) 52 53 def get_catalogue_request(self): 54 if session and session.role & ROLE_PROGRAMMER: 55 if qa.FORCE_STRUCTURE_GET_LICENSE_CATALOGUE_DELAY > 0: 56 blue.synchro.Sleep(qa.FORCE_STRUCTURE_GET_LICENSE_CATALOGUE_DELAY * 1000) 57 if qa.FORCE_STRUCTURE_GET_LICENSE_CATALOGUE_ERRORS: 58 raise Exception 59 request = api.GetCatalogueRequest() 60 response_primitive, response_payload = self.blocking_request(request, api.GetCatalogueResponse) 61 price_catalogue = PriceCatalogue() 62 for pricing_info in response_payload.items: 63 price_catalogue.define_price(pricing_info.structure_type.sequential, pricing_info.duration.seconds, pricing_info.price.amount) 64 65 return price_catalogue 66 67 def get_request(self, structure_id, license_id): 68 if session and session.role & ROLE_PROGRAMMER: 69 if qa.FORCE_STRUCTURE_GET_LICENSE_DELAY > 0: 70 blue.synchro.Sleep(qa.FORCE_STRUCTURE_GET_LICENSE_DELAY * 1000) 71 if qa.FORCE_STRUCTURE_GET_LICENSE_RANDOM_ERRORS: 72 import random 73 if random.choice([False, True]): 74 raise Exception 75 if qa.FORCE_STRUCTURE_GET_LICENSE_ERRORS: 76 raise Exception 77 request = api.GetRequest(id=LicenseIdentifier(uuid=license_id.get_bytes())) 78 response_primitive, response_payload = self.blocking_request(request, api.GetResponse) 79 response_license = create_structure_paintwork_license_from_proto_license(license_id, response_payload.attributes) 80 return response_license 81 82 def get_for_corporation(self): 83 if session and session.role & ROLE_PROGRAMMER: 84 if qa.FORCE_STRUCTURE_GET_LICENSE_DELAY > 0: 85 blue.synchro.Sleep(qa.FORCE_STRUCTURE_GET_LICENSE_DELAY * 1000) 86 if qa.FORCE_STRUCTURE_GET_LICENSE_RANDOM_ERRORS: 87 import random 88 if random.choice([False, True]): 89 raise Exception 90 if qa.FORCE_STRUCTURE_GET_LICENSE_ERRORS: 91 raise Exception 92 request = api.GetAllOwnedByCorporationRequest() 93 response_primitive, response_payload = self.blocking_request(request, api.GetAllOwnedByCorporationResponse) 94 response_licenses = {} 95 for proto_license in response_payload.licenses: 96 structure_id = proto_license.attributes.structure.sequential 97 response_licenses[structure_id] = create_structure_paintwork_license_from_proto_license(uuid.UUID(bytes=proto_license.identifier.uuid), proto_license.attributes) 98 99 return response_licenses 100 101 def admin_issue_request(self, structure_paintwork, duration, structures, lp_cost = -1): 102 use_catalogue = lp_cost == -1 103 if session.role & ROLE_PROGRAMMER: 104 if qa.FORCE_STRUCTURE_ISSUE_LICENSE_DELAY > 0: 105 blue.synchro.Sleep(qa.FORCE_STRUCTURE_ISSUE_LICENSE_DELAY * 1000) 106 if qa.FORCE_STRUCTURE_ISSUE_LICENSE_ERRORS: 107 raise Exception 108 if use_catalogue: 109 request = admin_api.IssueRequest(paintwork=create_proto_slot_config_from_structure_paintwork(structure_paintwork), duration=Duration(seconds=duration), structures=[ StructureIdentifier(sequential=s) for s in structures ], use_catalogue=True) 110 else: 111 request = admin_api.IssueRequest(paintwork=create_proto_slot_config_from_structure_paintwork(structure_paintwork), duration=Duration(seconds=duration), structures=[ StructureIdentifier(sequential=s) for s in structures ], price=Points(amount=lp_cost, associated_corporation=CorporationIdentifier(sequential=corpHeraldry))) 112 response_primitive, response_payload = self.blocking_request(request, admin_api.IssueResponse) 113 response_licenses = [] 114 for proto_license in response_payload.licenses: 115 response_licenses.append(create_structure_paintwork_license_from_proto_license(uuid.UUID(bytes=proto_license.id.uuid), proto_license.attributes)) 116 117 return response_licenses 118 119 def blocking_request(self, request, response_class): 120 request_primitive, response_channel = self.public_gateway.send_character_request(request, response_class, TIMEOUT_SECONDS) 121 response_primitive, payload = response_channel.receive() 122 if response_primitive.status_code == 400: 123 raise InvalidDataError 124 if response_primitive.status_code == 401: 125 raise InsufficientRolesError 126 if response_primitive.status_code == 402: 127 raise InsufficientBalanceError 128 if response_primitive.status_code == 403: 129 raise ForbiddenRequestError 130 if response_primitive.status_code == 404: 131 raise LicenseNotFoundException 132 elif response_primitive.status_code != 200: 133 raise GenericException(request_primitive, response_primitive) 134 return (response_primitive, payload)