def publish_demo_component(self, demo_file_url):
        # download zip component file
        root_directory = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
        if not Path.exists(Path(root_directory)):
            os.mkdir(root_directory)
        component_name = download_file_from_url(demo_file_url, root_directory)

        # extract the zip file
        extracted_file = os.path.join(
            root_directory,
            component_name.split(".")[0].split("_")[1])
        extract_zip_file(os.path.join(root_directory, component_name),
                         extracted_file)
        # prepare tar file
        output_path = os.path.join(
            root_directory,
            component_name.split(".")[0].split("_")[1] + '.tar.gz')
        make_tarfile(source_dir=extracted_file, output_filename=output_path)

        # upload demo file to s3 and demo attributes
        key = f"assets/{self.org_id}/{self.service_id}/component.tar.gz"
        boto_utils.s3_upload_file(filename=output_path,
                                  bucket=ASSETS_COMPONENT_BUCKET_NAME,
                                  key=key)
        new_demo_url = f"https://{ASSETS_COMPONENT_BUCKET_NAME}.s3.amazonaws.com/{key}"
        return new_demo_url
 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()
    def _extract_zip_and_and_tar(self, org_id, service_id, s3_url):
        root_directory = ASSET_TEMP_EXTRACT_DIRECTORY
        zip_directory = root_directory + org_id + "/" + service_id
        extracted_zip_directory = root_directory + "extracted/" + org_id + "/" + service_id

        zip_file_name = download_file_from_url(s3_url, zip_directory)
        zip_file_path = zip_directory + "/" + zip_file_name
        extracted_file_path = extracted_zip_directory + "/" + zip_file_name.split(".")[0].split("_")[1]
        extract_zip_file(zip_file_path, extracted_file_path)

        tar_file_path = extracted_file_path + ".tar.gz"
        make_tarfile(tar_file_path, extracted_file_path)

        return tar_file_path