Пример #1
0
 def create_compute_service(attributes, provider_uri=None):
     service_endpoint = provider_uri or DataServiceProvider.get_url(
         ConfigProvider.get_config()
     )
     return ServiceDescriptor.compute_service_descriptor(
         attributes, service_endpoint
     )
Пример #2
0
def get_registered_ddo_with_compute_service(ocean_instance,
                                            wallet,
                                            provider_uri=None,
                                            trusted_algorithms=None):
    old_ddo = get_sample_ddo_with_compute_service()
    metadata = old_ddo.metadata
    metadata["main"]["files"][0]["checksum"] = str(uuid.uuid4())
    service = old_ddo.get_service(ServiceTypes.CLOUD_COMPUTE)
    compute_attributes = ocean_instance.compute.create_compute_service_attributes(
        service.attributes["main"]["timeout"],
        service.attributes["main"]["creator"],
        service.attributes["main"]["datePublished"],
        service.attributes["main"]["provider"],
        privacy_attributes=ocean_instance.compute.
        build_service_privacy_attributes(
            trusted_algorithms,
            allow_raw_algorithm=True,
            allow_all_published_algorithms=not bool(trusted_algorithms),
        ),
    )
    compute_service = ServiceDescriptor.compute_service_descriptor(
        compute_attributes, DataServiceProvider.get_url(ocean_instance.config))

    return get_registered_ddo(ocean_instance,
                              metadata,
                              wallet,
                              compute_service,
                              provider_uri=provider_uri)
Пример #3
0
    def create_compute_service_descriptor(self, attributes):
        """
        Return a service descriptor (tuple) for service of type ServiceTypes.CLOUD_COMPUTE
        and having the required attributes and service endpoint.

        :param attributes: dict as created in `create_compute_service_attributes`
        """
        compute_endpoint = self._data_provider.get_url(self._config)
        return ServiceDescriptor.compute_service_descriptor(
            attributes=attributes, service_endpoint=compute_endpoint
        )
Пример #4
0
def test_service_factory():
    """Tests ServiceFactory builds services."""
    ddo = get_sample_ddo("ddo_algorithm.json")
    type_to_service = {s.type: s for s in ddo.services}
    metadata = ddo.metadata

    md_descriptor = ServiceDescriptor.metadata_service_descriptor(
        metadata, type_to_service[ServiceTypes.METADATA].service_endpoint
    )
    services = ServiceFactory.build_services([md_descriptor])
    assert len(services) == 1
    assert services[0].type == ServiceTypes.METADATA
Пример #5
0
def create_asset(ocean, publisher):
    """Helper function for asset creation based on ddo_sa_sample.json."""
    sample_ddo_path = get_resource_path("ddo", "ddo_sa_sample.json")
    assert sample_ddo_path.exists(), "{} does not exist!".format(
        sample_ddo_path)

    asset = DDO(json_filename=sample_ddo_path)
    asset.metadata["main"]["files"][0]["checksum"] = str(uuid.uuid4())
    my_secret_store = "http://myownsecretstore.com"
    auth_service = ServiceDescriptor.authorization_service_descriptor(
        my_secret_store)
    return ocean.assets.create(asset.metadata, publisher, [auth_service])
Пример #6
0
def get_access_service_descriptor(ocean_instance,
                                  address,
                                  date_created,
                                  provider_uri=None,
                                  timeout=3600):
    if not provider_uri:
        provider_uri = DataServiceProvider.get_url(ocean_instance.config)

    return ServiceDescriptor.access_service_descriptor(
        ocean_instance.assets.build_access_service(date_created, 1.0, address,
                                                   timeout),
        DataServiceProvider.build_download_endpoint(provider_uri)[1],
    )
Пример #7
0
    def _process_service_descriptors(
        self,
        service_descriptors: list,
        metadata: dict,
        provider_uri: str,
        wallet: Wallet,
    ) -> list:
        ddo_service_endpoint = self._get_aquarius().get_service_endpoint()

        service_type_to_descriptor = {sd[0]: sd for sd in service_descriptors}
        _service_descriptors = []
        metadata_service_desc = service_type_to_descriptor.pop(
            ServiceTypes.METADATA,
            ServiceDescriptor.metadata_service_descriptor(
                metadata, ddo_service_endpoint),
        )
        _service_descriptors = [metadata_service_desc]

        # Always dafault to creating a ServiceTypes.ASSET_ACCESS service if no services are specified
        access_service_descriptor = service_type_to_descriptor.pop(
            ServiceTypes.ASSET_ACCESS, None)
        compute_service_descriptor = service_type_to_descriptor.pop(
            ServiceTypes.CLOUD_COMPUTE, None)
        # Make an access service only if no services are given by the user.
        if not access_service_descriptor and not compute_service_descriptor:
            access_service_descriptor = ServiceDescriptor.access_service_descriptor(
                self.build_access_service(metadata["main"]["dateCreated"], 1.0,
                                          wallet.address),
                self._data_provider.build_download_endpoint(provider_uri)[1],
            )

        if access_service_descriptor:
            _service_descriptors.append(access_service_descriptor)
        if compute_service_descriptor:
            _service_descriptors.append(compute_service_descriptor)

        _service_descriptors.extend(service_type_to_descriptor.values())
        return ServiceFactory.build_services(_service_descriptors)
Пример #8
0
    def create_access_service(attributes, provider_uri=None):
        """Publish an asset with an `Access` service according to the supplied attributes.

        :param attributes: attributes of the access service, dict
        :param provider_uri: str URL of service provider. This will be used as base to
            construct the serviceEndpoint for the `access` (download) service
        :return: Service instance or None
        """
        service_endpoint = provider_uri or DataServiceProvider.get_url(
            ConfigProvider.get_config()
        )
        service = ServiceDescriptor.access_service_descriptor(
            attributes, service_endpoint
        )
        return service
Пример #9
0
def test_create_asset_without_dt_address(publisher_ocean_instance):
    """Tests creation of the asset which has not the data token address."""
    ocn = publisher_ocean_instance
    alice = get_publisher_wallet()

    sample_ddo_path = get_resource_path("ddo", "ddo_sa_sample.json")
    asset = DDO(json_filename=sample_ddo_path)
    asset.metadata["main"]["files"][0]["checksum"] = str(uuid.uuid4())
    my_secret_store = "http://myownsecretstore.com"
    auth_service = ServiceDescriptor.authorization_service_descriptor(
        my_secret_store)

    assert ocn.assets.create(asset.metadata,
                             alice, [auth_service],
                             data_token_address=None)
Пример #10
0
def test_create_asset_with_address(publisher_ocean_instance):
    """Tests that an asset can be created with specific DT address."""
    ocn = publisher_ocean_instance
    alice = get_publisher_wallet()

    sample_ddo_path = get_resource_path("ddo", "ddo_sa_sample.json")
    asset = DDO(json_filename=sample_ddo_path)
    asset.metadata["main"]["files"][0]["checksum"] = str(uuid.uuid4())
    my_secret_store = "http://myownsecretstore.com"
    auth_service = ServiceDescriptor.authorization_service_descriptor(
        my_secret_store)

    token = ocn.create_data_token("DataToken1",
                                  "DT1",
                                  from_wallet=alice,
                                  blob="foo_blob")

    assert ocn.assets.create(asset.metadata,
                             alice, [auth_service],
                             data_token_address=token.address)