Beispiel #1
0
    def metadata_add_asset_to_ipfs(self):
        metadata = load_mpe_service_metadata(self.args.metadata_file)
        asset_file_ipfs_hash_base58 = ipfs_utils.publish_file_in_ipfs(self._get_ipfs_client(),
                                                                      self.args.asset_file_path)

        metadata.add_asset(asset_file_ipfs_hash_base58, self.args.asset_type)
        metadata.save_pretty(self.args.metadata_file)
Beispiel #2
0
    def update_metadata(self):
        metadata_file = self.args.metadata_file

        try:
            with open(metadata_file, 'r') as f:
                org_metadata = OrganizationMetadata.from_json(json.load(f))
        except Exception as e:
            print(
                "Organization metadata json file not found ,Please check --metadata-file path ")
            raise e
        # validate the metadata before updating

        org_id = self.args.org_id
        existing_registry_org_metadata = self._get_organization_metadata_from_registry(
            org_id)
        org_metadata.validate(existing_registry_org_metadata)

        # Check if Organization already exists
        found = self._get_organization_by_id(org_id)[0]
        if not found:
            raise Exception(
                "\nOrganization with id={} does not  exists!\n".format(org_id))

        ipfs_metadata_uri = publish_file_in_ipfs(
            self._get_ipfs_client(), metadata_file, False)
        params = [type_converter("bytes32")(
            org_id), hash_to_bytesuri(ipfs_metadata_uri)]
        self._printout(
            "Creating transaction to create organization name={} id={}\n".format(org_metadata.org_name, org_id))
        self.transact_contract_command(
            "Registry", "changeOrganizationMetadataURI", params)
        self._printout("id:\n%s" % org_id)
Beispiel #3
0
    def metadata_add_asset_to_ipfs(self):
        metadata_file = self.args.metadata_file
        org_metadata = OrganizationMetadata.from_file(metadata_file)
        asset_file_ipfs_hash_base58 = publish_file_in_ipfs(self._get_ipfs_client(),
                                                                      self.args.asset_file_path)

        org_metadata.add_asset(asset_file_ipfs_hash_base58, self.args.asset_type)
        org_metadata.save_pretty(self.args.metadata_file)
Beispiel #4
0
    def metadata_add_media(self):
        """Metadata: Add new individual media

        Detects media type for files to be added on IPFS, explict declaration for external resources.
        """
        metadata = load_mpe_service_metadata(self.args.metadata_file)
        # Support endpoints only with SSL Certificate
        url_validator = r'https?:\/\/(www\.)?([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b[-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
        # Automatic media type identification
        if search(r'^.+\.(jpg|jpeg|png|gif)$', self.args.media_url):
            media_type = 'image'
        elif search(r'^.+\.(mp4)$', self.args.media_url):
            media_type = 'video'
        elif search(url_validator, self.args.media_url):
            while True:
                try:
                    media_type = input(
                        f"Enter the media type (image, video) present at {self.args.media_url}: "
                    )
                except ValueError:
                    print("Choose only between (image, video).")
                else:
                    if media_type not in ('image', 'video'):
                        print("Choose only between (image, video).")
                    else:
                        break
        else:
            if search(
                    r'(https:\/\/)?(www\.)+([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b[-a-zA-Z0-9()@:%_\+.~#?&//=]*)',
                    self.args.media_url):
                raise ValueError(
                    "Media endpoint supported only for secure sites.")
            else:
                raise ValueError(
                    f"Entered url '{self.args.media_url}' is invalid.")
        file_extension_validator = r'^.+\.(jpg|jpeg|JPG|png|gif|GIF|mp4)$'
        # Detect whether to add asset on IPFS or if external resource
        if search(file_extension_validator, self.args.media_url):
            asset_file_ipfs_hash_base58 = ipfs_utils.publish_file_in_ipfs(
                self._get_ipfs_client(), self.args.media_url)
            metadata.add_media(asset_file_ipfs_hash_base58, media_type,
                               self.args.hero_image)
        else:
            metadata.add_media(self.args.media_url, media_type,
                               self.args.hero_image)
        metadata.save_pretty(self.args.metadata_file)