Skip to main content

Creating instances

To populate the database with some data from a JSON file, make sure topaz is running and then use the topaz directory import command:

topaz directory import -i -d <directory containing JSON file>

The two JSON files should contain

  1. An array of objects, each of which represents a single instance of the types defined in the manifest.
  2. An array of relations, each specifying the subject, object and relation type.

For example, the following sample JSON files contain

  1. three instances of the user type (which is built-in), and three instances of the document type (defined in the manifest.yaml).
  2. three relations between the users and the documents.

Copy this block into ./objects.json:

{
"objects": [
{
"type": "user",
"id": "CiRmZDA2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"display_name": "Rick Sanchez",
"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",
"id": "CiRmZDE2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"display_name": "Morty Smith",
"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",
"id": "CiRmZDQ2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
"display_name": "Jerry Smith",
"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": "document",
"id": "doc1",
"display_name": "Document 1",
"properties": {
"path": "/docs/doc1"
}
},
{
"type": "document",
"id": "doc2",
"display_name": "Document 2",
"properties": {
"path": "/docs/doc2"
}
},
{
"type": "document",
"id": "doc3",
"display_name": "Document 3",
"properties": {
"path": "/docs/doc3"
}
}
]
}

Copy this block into ./relations.json:

{
"relations": [
{
"object_type": "document",
"object_id": "doc1",
"relation": "owner",
"subject_type": "user",
"subject_id": "CiRmZDA2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs"
},
{
"object_type": "document",
"object_id": "doc2",
"relation": "editor",
"subject_type": "user",
"subject_id": "CiRmZDE2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs"
},
{
"object_type": "document",
"object_id": "doc3",
"relation": "viewer",
"subject_type": "user",
"subject_id": "CiRmZDQ2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs"
}
]
}

Now run the following command to import the data:

topaz directory import -i -d .

Topaz directory CLI

For a full list of CLI commands for interacting with the directory, including listing, getting, setting, and deleting objects and relations, refer to the directory CLI documentation.