Esempio n. 1
0
 def save_service(self, payload):
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     service.service_id = payload["service_id"]
     service.proto = payload.get("proto", {})
     service.short_description = payload.get("short_description", "")
     service.description = payload.get("description", "")
     service.project_url = payload.get("project_url", "")
     service.contributors = ServicePublisherService. \
         _get_valid_service_contributors(contributors=payload.get("contributors", []))
     service.tags = payload.get("tags", [])
     service.mpe_address = payload.get("mpe_address", "")
     groups = []
     for group in payload["groups"]:
         service_group = ServiceFactory.create_service_group_entity_model(
             self._org_uuid, self._service_uuid, group)
         groups.append(service_group)
     service.groups = groups
     service.service_state.transaction_hash = payload.get(
         "transaction_hash", None)
     service = ServicePublisherRepository().save_service(
         self._username, service, ServiceStatus.APPROVED.value)
     comment = payload.get("comments",
                           {}).get(UserType.SERVICE_PROVIDER.value, "")
     if len(comment) > 0:
         self._save_service_comment(support_type="SERVICE_APPROVAL",
                                    user_type="SERVICE_PROVIDER",
                                    comment=comment)
     return service.to_dict()
 def publish_service_data_to_ipfs(self):
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(self._org_uuid,
                                          self._service_uuid)
     if service.service_state.state == ServiceStatus.APPROVED.value:
         proto_url = service.assets.get("proto_files", {}).get("url", None)
         if proto_url is None:
             raise ServiceProtoNotFoundException
         filename = download_file_from_url(
             file_url=proto_url,
             file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}")
         logger.info(f"proto file Name Retrieved  = '{filename}` ")
         asset_ipfs_hash = publish_zip_file_in_ipfs(
             filename=filename,
             file_dir=f"{ASSET_DIR}/{service.org_uuid}/{service.uuid}",
             ipfs_client=IPFSUtil(IPFS_URL['url'], IPFS_URL['port']))
         service.proto = {
             "model_ipfs_hash": asset_ipfs_hash,
             "encoding": "proto",
             "service_type": "grpc"
         }
         service.assets["proto_files"]["ipfs_hash"] = asset_ipfs_hash
         ServicePublisherDomainService.publish_assets(service)
         service = ServicePublisherRepository().save_service(
             self._username, service, service.service_state.state)
         return service
     logger.info(
         f"Service status needs to be {ServiceStatus.APPROVED.value} to be eligible for publishing."
     )
     raise InvalidServiceStateException()