Exemplo n.º 1
0
    def initialize_metadata(self):
        org_id = self.args.org_id
        metadata_file_name = self.args.metadata_file

        # Check if Organization already exists
        found = self._getorganizationbyid(org_id)[0]
        if found:
            raise Exception(
                "\nOrganization with id={} already exists!\n".format(org_id))
        org_metadata = OrganizationMetadata(self.args.org_name, org_id)
        org_metadata.save_pretty(metadata_file_name)
Exemplo n.º 2
0
 def _read_metadata_for_org(self, org_id):
     sdir = self.get_org_spec_dir(org_id)
     if (not os.path.exists(sdir)):
         raise Exception("Service with org_id=%s is not initialized" %
                         (org_id))
     return OrganizationMetadata.from_file(
         sdir.joinpath("organization_metadata.json"))
Exemplo n.º 3
0
 def _get_organization_metadata_from_registry(self, org_id):
     rez = self._get_organization_registration(org_id)
     metadata_hash = bytesuri_to_hash(rez["orgMetadataURI"])
     metadata = get_from_ipfs_and_checkhash(
         self._get_ipfs_client(), metadata_hash)
     metadata = metadata.decode("utf-8")
     return OrganizationMetadata.from_json(json.loads(metadata))
Exemplo n.º 4
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 = utils_ipfs.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)
Exemplo n.º 5
0
 def metadata_add_contact(self):
     args = self.args.__dict__
     metadata_file = args["metadata_file"]
     contact_type = args.get("contact_type", None)
     phone = args.get("phone", None)
     email = args.get("email", None)
     if phone is None and email is None:
         self._printout("email and phone both can not be empty")
     else:
         org_metadata = OrganizationMetadata.from_file(metadata_file)
         org_metadata.add_contact(contact_type, phone, email)
         org_metadata.save_pretty(metadata_file)
Exemplo n.º 6
0
 def metadata_add_description(self):
     description = self.args.description
     url = self.args.url
     short_description = self.args.short_description
     metadata_file = self.args.metadata_file
     org_metadata = OrganizationMetadata.from_file(metadata_file)
     if description:
         org_metadata.add_description(description)
     if short_description:
         org_metadata.add_short_description(short_description)
     if url:
         org_metadata.add_url(url)
     if description is None and url is None and short_description is None:
         raise Exception("No attributes are given")
     org_metadata.save_pretty(metadata_file)
Exemplo n.º 7
0
    def update_group(self):
        group_id = self.args.group_id
        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
        existing_groups = org_metadata.groups
        for group in existing_groups:
            if group_id == group.group_id:
                self.set_changed_values_for_group(group)

        org_metadata.save_pretty(metadata_file)
Exemplo n.º 8
0
    def remove_group(self):
        group_id = self.args.group_id
        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

        existing_groups = org_metadata.groups
        updated_groups = [
            group for group in existing_groups
            if not group_id == group.group_id
        ]
        org_metadata.groups = updated_groups
        org_metadata.save_pretty(metadata_file)
Exemplo n.º 9
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._getorganizationbyid(org_id)[0]
        if not found:
            raise Exception(
                "\nOrganization with id={} does not  exists!\n".format(org_id))

        ipfs_metatdata_uri = publish_file_in_ipfs(self._get_ipfs_client(),
                                                  metadata_file, False)
        params = [
            type_converter("bytes32")(org_id),
            hash_to_bytesuri(ipfs_metatdata_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)
Exemplo n.º 10
0
    def add_group(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

        payment_storage_client = PaymentStorageClient(
            self.args.payment_channel_connection_timeout,
            self.args.payment_channel_request_timeout, self.args.endpoints)
        payment = Payment(self.args.payment_address,
                          self.args.payment_expiration_threshold,
                          self.args.payment_channel_storage_type,
                          payment_storage_client)
        group_id = base64.b64encode(secrets.token_bytes(32))

        group = Group(self.args.group_name, group_id.decode("ascii"), payment)
        org_metadata.add_group(group)
        org_metadata.save_pretty(metadata_file)
Exemplo n.º 11
0
 def open_init_channel_from_metadata(self):
     metadata = OrganizationMetadata.from_file(self.args.metadata_file)
     self._open_init_channel_from_metadata(metadata, {})
Exemplo n.º 12
0
 def metadata_remove_all_contacts(self):
     metadata_file = self.args.metadata_file
     org_metadata = OrganizationMetadata.from_file(metadata_file)
     org_metadata.remove_all_contacts()
     org_metadata.save_pretty(metadata_file)
Exemplo n.º 13
0
 def metadata_remove_contact_by_type(self):
     metadata_file = self.args.metadata_file
     contact_type = self.args.contact_type
     org_metadata = OrganizationMetadata.from_file(metadata_file)
     org_metadata.remove_contact_by_type(contact_type)
     org_metadata.save_pretty(metadata_file)
Exemplo n.º 14
0
 def metadata_remove_assets_of_a_given_type(self):
     metadata_file = self.args.metadata_file
     org_metadata = OrganizationMetadata.from_file(metadata_file)
     org_metadata.remove_assets(self.args.asset_type)
     org_metadata.save_pretty(self.args.metadata_file)