Exemplo n.º 1
0
    def build_nft_access_service(attributes, service_endpoint):
        """
        Build a nft sales service.

        :param attributes: attributes of nft sales service, dict
        :param service_endpoint: identifier of the service inside the asset DDO, str
        :return: Service
        """
        return Service(service_endpoint,
                       ServiceTypes.NFT_ACCESS,
                       values={'attributes': attributes},
                       index=ServiceTypesIndices.DEFAULT_NFT_ACCESS_INDEX)
Exemplo n.º 2
0
    def build_did_sales_service(attributes, service_endpoint):
        """
        Build a did sales service.

        :param attributes: attributes of did sales service, dict
        :param service_endpoint: identifier of the service inside the asset DDO, str
        :return: Service
        """
        return Service(service_endpoint,
                       ServiceTypes.DID_SALES,
                       values={'attributes': attributes},
                       index=ServiceTypesIndices.DEFAULT_DID_SALES_INDEX)
Exemplo n.º 3
0
    def build_compute_service(attributes, service_endpoint):
        """
        Build a compute service.

        :param attributes: attributes of compute service, dict
        :param service_endpoint: identifier of the service inside the asset DDO, str
        :return: Service
        """
        return Service(service_endpoint,
                       ServiceTypes.CLOUD_COMPUTE,
                       values={'attributes': attributes},
                       index=ServiceTypesIndices.DEFAULT_COMPUTING_INDEX)
Exemplo n.º 4
0
    def build_access_proof_service(attributes, service_endpoint):
        """
        Build an access service.

        :param attributes: attributes of access service, dict
        :param service_endpoint: identifier of the service inside the asset DDO, str
        :return: Service
        """
        return Service(service_endpoint,
                       ServiceTypes.ASSET_ACCESS_PROOF,
                       values={'attributes': attributes},
                       index=ServiceTypesIndices.DEFAULT_ACCESS_PROOF_INDEX)
Exemplo n.º 5
0
    def build_authorization_service(attributes, service_endpoint):
        """
        Build an authorization service.

        :param attributes: attributes of authorization service, dict
        :param service_endpoint: identifier of the service inside the asset DDO, str
        :return: Service
        """
        return Service(service_endpoint,
                       ServiceTypes.AUTHORIZATION,
                       values={'attributes': attributes},
                       index=ServiceTypesIndices.DEFAULT_AUTHORIZATION_INDEX)
Exemplo n.º 6
0
    def build_metadata_service(metadata, service_endpoint):
        """
        Build a metadata service.

        :param metadata: conforming to the Metadata accepted by Nevermined, dict
        :param service_endpoint: identifier of the service inside the asset DDO, str
        :return: Service
        """
        return Service(service_endpoint,
                       ServiceTypes.METADATA,
                       values={'attributes': metadata},
                       index=ServiceTypesIndices.DEFAULT_METADATA_INDEX)
Exemplo n.º 7
0
def test_store_and_retrieve_service(metadata_instance, json_service):
    agreement_id = ServiceAgreement.create_new_agreement_id()
    service = Service.from_json(json_service)

    # store the service agreement
    result = metadata_instance.store_service_agreement(agreement_id, service)
    assert result is True

    result = metadata_instance.get_service_agreement(agreement_id)
    assert result.type == service.type
    assert result.index == service.index
    assert result.service_endpoint == service.service_endpoint
    assert result.attributes == service.attributes
Exemplo n.º 8
0
    def get_service_agreement(self, agreement_id):
        """
        Retrieve a service agreement for a given agreemend id.

        :param agreement_id: Service agreement id string
        :return: Service
        """
        response = self.requests_session.get(f'{self._base_url}/service/{agreement_id}')
        if response.status_code == 404:
            return None

        if response.status_code == 500:
            raise ValueError(response.content)

        parsed_response = json.loads(response.content)
        return Service.from_json(parsed_response)
Exemplo n.º 9
0
    def __init__(self,
                 attributes,
                 service_agreement_template,
                 service_endpoint=None,
                 service_type=None):
        """

        :param attributes: attributes
        :param service_agreement_template: ServiceAgreementTemplate instance
        :param service_endpoint: str URL to use for requesting service defined in this agreement
        :param service_type: str like ServiceTypes.ASSET_ACCESS
        """
        self.service_agreement_template = service_agreement_template
        values = dict()
        values[ServiceAgreementTemplate.TEMPLATE_ID_KEY] = self.template_id
        values['attributes'] = dict()
        values['attributes'] = attributes
        values['attributes'][
            'serviceAgreementTemplate'] = service_agreement_template.__dict__[
                'template']
        if service_type == ServiceTypes.ASSET_ACCESS:
            values['index'] = ServiceTypesIndices.DEFAULT_ACCESS_INDEX
            Service.__init__(self, service_endpoint, ServiceTypes.ASSET_ACCESS,
                             values, ServiceTypesIndices.DEFAULT_ACCESS_INDEX)

        elif service_type == ServiceTypes.CLOUD_COMPUTE:
            values['index'] = ServiceTypesIndices.DEFAULT_COMPUTING_INDEX
            Service.__init__(self, service_endpoint,
                             ServiceTypes.CLOUD_COMPUTE, values,
                             ServiceTypesIndices.DEFAULT_COMPUTING_INDEX)

        elif service_type == ServiceTypes.DID_SALES:
            values['index'] = ServiceTypesIndices.DEFAULT_DID_SALES_INDEX
            Service.__init__(self, service_endpoint, ServiceTypes.DID_SALES,
                             values,
                             ServiceTypesIndices.DEFAULT_DID_SALES_INDEX)

        elif service_type == ServiceTypes.NFT_SALES:
            values['index'] = ServiceTypesIndices.DEFAULT_NFT_SALES_INDEX
            Service.__init__(self, service_endpoint, ServiceTypes.NFT_SALES,
                             values,
                             ServiceTypesIndices.DEFAULT_NFT_SALES_INDEX)

        elif service_type == ServiceTypes.NFT_ACCESS:
            values['index'] = ServiceTypesIndices.DEFAULT_NFT_ACCESS_INDEX
            Service.__init__(self, service_endpoint, ServiceTypes.NFT_ACCESS,
                             values,
                             ServiceTypesIndices.DEFAULT_NFT_ACCESS_INDEX)

        elif service_type == ServiceTypes.NFT721_ACCESS:
            values['index'] = ServiceTypesIndices.DEFAULT_NFT721_ACCESS_INDEX
            Service.__init__(self, service_endpoint, ServiceTypes.NFT_ACCESS,
                             values,
                             ServiceTypesIndices.DEFAULT_NFT721_ACCESS_INDEX)

        elif service_type == ServiceTypes.ASSET_ACCESS_PROOF:
            values['index'] = ServiceTypesIndices.DEFAULT_ACCESS_PROOF_INDEX
            Service.__init__(self, service_endpoint,
                             ServiceTypes.ASSET_ACCESS_PROOF, values,
                             ServiceTypesIndices.DEFAULT_ACCESS_PROOF_INDEX)

        else:
            raise ValueError(
                f'The service_type {service_type} is not currently supported.')