Creating instances
To populate the database with some data from a JSON file, make sure topaz
is running and then use the topaz import
command:
topaz import -i -d <directory containing JSON file>
The two JSON files should contain
- An array of objects, each of which represents a single instance of the types defined in the manifest.
- An array of relations, each specifying the subject, object and relation type.
For example, the following sample JSON files contain
- three instances of the
user
type (which is built-in), and three instances of thedocument
type (defined in themanifest.yaml
). - three relations between the users and the documents.
Copy this block into ./objects.json
:
{
"objects": [
{
"display_name": "Rick Sanchez",
"key": "CiRmZDA2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"properties": {
"email": "rick@the-citadel.com",
"picture": "https://github.com/aserto-demo/contoso-ad-sample/raw/main/UserImages/Rick%20Sanchez.jpg",
"status": "USER_STATUS_ACTIVE"
},
"type": "user"
},
{
"display_name": "Morty Smith",
"key": "CiRmZDE2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"properties": {
"email": "morty@the-citadel.com",
"picture": "https://github.com/aserto-demo/contoso-ad-sample/raw/main/UserImages/Morty%20Smith.jpg",
"status": "USER_STATUS_ACTIVE"
},
"type": "user"
},
{
"display_name": "Jerry Smith",
"key": "CiRmZDQ2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"properties": {
"email": "jerry@the-smiths.com",
"picture": "https://github.com/aserto-demo/contoso-ad-sample/raw/main/UserImages/Jerry%20Smith.jpg",
"status": "USER_STATUS_ACTIVE"
},
"type": "user"
},
{
"display_name": "Document 1",
"key": "doc1",
"properties": {
"path": "/docs/doc1"
},
"type": "document"
},
{
"display_name": "Document 2",
"key": "doc2",
"properties": {
"path": "/docs/doc2"
},
"type": "document"
},
{
"display_name": "Document 3",
"key": "doc3",
"properties": {
"path": "/docs/doc3"
},
"type": "document"
}
]
}
Copy this block into ./relations.json
:
{
"relations": [
{
"object": {
"key": "doc1",
"type": "document"
},
"relation": {
"object_type": "document",
"name": "owner"
},
"subject": {
"key": "CiRmZDA2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"type": "user"
}
},
{
"object": {
"key": "doc2",
"type": "document"
},
"relation": {
"object_type": "document",
"name": "editor"
},
"subject": {
"key": "CiRmZDE2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"type": "user"
}
},
{
"object": {
"key": "doc3",
"type": "document"
},
"relation": {
"object_type": "document",
"name": "viewer"
},
"subject": {
"key": "CiRmZDQ2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"type": "user"
}
}
]
}
Now run the following command to import the data:
topaz import -i -d .