Esempio n. 1
0
 def publish_proto_metadata_update(self):
     """ Publish protobuf model in ipfs and update existing metadata file """
     metadata = load_mpe_service_metadata(self.args.metadata_file)
     ipfs_hash_base58 = ipfs_utils.publish_proto_in_ipfs(
         self._get_ipfs_client(), self.args.protodir)
     metadata.set_simple_field("model_ipfs_hash", ipfs_hash_base58)
     metadata.save_pretty(self.args.metadata_file)
Esempio n. 2
0
    def publish_proto_metadata_init(self):
        model_ipfs_hash_base58 = ipfs_utils.publish_proto_in_ipfs(
            self._get_ipfs_client(), self.args.protodir)

        metadata = MPEServiceMetadata()
        mpe_address = self.get_mpe_address()
        metadata.set_simple_field("model_ipfs_hash",
                                  model_ipfs_hash_base58)
        metadata.set_simple_field("mpe_address", mpe_address)
        metadata.set_simple_field("display_name",
                                  self.args.display_name)
        metadata.set_simple_field("encoding",
                                  self.args.encoding)
        metadata.set_simple_field("service_type",
                                  self.args.service_type)

        if self.args.group_name:
            metadata.add_group(self.args.group_name)
            if self.args.endpoints:
                for endpoint in self.args.endpoints:
                    metadata.add_endpoint_to_group(
                        self.args.group_name, endpoint)
            if self.args.fixed_price is not None:
                metadata.set_fixed_price_in_cogs(
                    self.args.group_name, self.args.fixed_price)
        elif self.args.group_name or self.args.fixed_price:
            raise Exception(
                "endpoints / fixed price can be attached to a group please pass group_name")
        metadata.save_pretty(self.args.metadata_file)
Esempio n. 3
0
 def publish_proto_in_ipfs(self):
     """ Publish proto files in ipfs and print hash """
     ipfs_hash_base58 = ipfs_utils.publish_proto_in_ipfs(
         self._get_ipfs_client(), self.args.protodir)
     self._printout(ipfs_hash_base58)
Esempio n. 4
0
    def service_metadata_init(self):
        """Utility for creating a service metadata file.

        CLI questionnaire for service metadata creation. Creates a `service_metadata.json`
        (if file name is not set) with values entered by the user in the questionnaire utility.

        Mandatory args:
            display_name: Display name of the service.
            org_id: Organization ID the service would be assosciated with.
            protodir_path: Directory containing protobuf files.
            groups: Payment groups supported by the organization (default: `default_group`). If multiple
                payment groups, ask user for entry.
            endpoints: Storage end points for the clients to connect.
            daemon_addresses: Ethereum public addresses of daemon in given payment group of service.

        Optional args:
            url: Service user guide resource.
            long_description: Long description of service.
            short_description: Service overview.
            contributors: Contributor name and email-id.
            file_name: Service metdadata filename.
        """
        print(
            "This utility will walk you through creating the service metadata file.",
            "It only covers the most common items and tries to guess sensible defaults.",
            "",
            "See `snet service metadata-init-utility -h` on how to use this utility.",
            "",
            "Press ^C at any time to quit.",
            sep='\n')
        try:
            metadata = MPEServiceMetadata()
            while True:
                display_name = input("display name: ").strip()
                if display_name == "":
                    print("display name is required.")
                else:
                    break
            # Find number of payment groups available for organization
            # If only 1, set `default_group` as payment group
            while True:
                org_id = input(
                    f"organization id `{display_name}` service would be linked to: "
                ).strip()
                while org_id == "":
                    org_id = input(f"organization id required: ").strip()
                try:
                    org_metadata = self._get_organization_metadata_from_registry(
                        org_id)
                    no_of_groups = len(org_metadata.groups)
                    break
                except Exception:
                    print(f"`{org_id}` is invalid.")
            while True:
                try:
                    protodir_path = input("protodir path: ")
                    model_ipfs_hash_base58 = ipfs_utils.publish_proto_in_ipfs(
                        self._get_ipfs_client(), protodir_path)
                    break
                except Exception:
                    print(f'Invalid path: "{protodir_path}"')
            if no_of_groups == 1:
                metadata.group_init('default_group')
            else:
                while input("Add group? [y/n] ") == 'y':
                    metadata.group_init(input('group name: '))
            metadata.add_description()
            metadata.add_contributor(input('Enter contributor name: '),
                                     input('Enter contributor email: '))
            while input('Add another contributor? [y/n] ').lower() == 'y':
                metadata.add_contributor(input('Enter contributor name '),
                                         input('Enter contributor email: '))
            mpe_address = self.get_mpe_address()

            metadata.set_simple_field('model_ipfs_hash',
                                      model_ipfs_hash_base58)
            metadata.set_simple_field('mpe_address', mpe_address)
            metadata.set_simple_field('display_name', display_name)
            print('', '', json.dumps(metadata.m, indent=2), sep='\n')
            print("Are you sure you want to create? [y/n] ", end='')
            if input() == 'y':
                file_name = input(f"Choose file name: (service_metadata) "
                                  ) or 'service_metadata'
                file_name += '.json'
                metadata.save_pretty(file_name)
                print(f"{file_name} created.")
            else:
                exit("ABORTED.")
        except KeyboardInterrupt:
            exit("\n`snet service metadata-init-utility` CANCELLED.")