This quickstart describes how to use credentials in order to limit access to a dataset.
Ensure that you've already (a) installed Ocean, and (b) set up locally or remotely.
Here are the steps:
- Publish a dataset that can only be accessed by Alice and Bob. Everyone else will be denied.
- Update the dataset so only Bob will be denied, everyone else will have access.
Let's go through each step.
url = 'http://www.example.net'
name = "Restricted dataset"
credentials = {
"allow": [{"type": "address", "values": [alice.address, bob.address]}],
"deny": [],
}
#create asset
(data_nft, datatoken, ddo) = ocean.assets.create_url_asset(name, url, {"from": carlos}, credentials = credentials)
print(f"Just published asset, with did={ddo.did}")
That's it! You've created a data asset which is accesible only to Alice and Bob. Consume here is just like in consume-flow.
Using the ddo directly, or later using ddo=ocean.assets.resolve(<DID you wrote down previously>)
ddo.credentials = {
"allow": [],
"deny": [{"type": "address", "values": [bob.address]}],
}
ddo = ocean.assets.update(ddo, {"from": carlos})
That's it! Now everyone can access the dataset, except Bob. Consume here is just like in consume-flow.
For more information about credentials, you can refer to docs.