Exemple #1
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))
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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)