Sentinel
Extending Sentinel: Static Imports
Static imports allow you to write imports that use static data files. This can provide methods of consuming data in ways that are not available via modules or plugins.
Configuring a Static Import
The configuration page details how to configure static imports.
Usage
Using a static import is not that different to using a plugin or module. The import must first be introduced to the policy via an import statement.
import "people"
From here, the static data can be used throughout the policy as you would any normal Sentinel value.
admins = filter people as person {
person.role is "Admin"
}
One differentiator for static imports is that you can directly reference the import without the use of selectors. For example, to print the value;
print(people)
This is due to the static data being directly loaded and converted into a Sentinel value, ready for use. Static imports, like modules and plugins, cannot be assigned a new value.
Namespaces
One advantage of static imports over other import types, is the ability to access nested data directly via a namespaced import. For instance, let us consider a static import with the following nested data structure:
{
"dogs": [
"Labrador",
"Golden Retriever"
],
"cats": [
"Birman",
"Korat"
]
}
The list of dogs would normally be accessed through a selector expression, such as:
Sentinel Playground
Loading the playground...
Press "Run" to get policy output
However, the data can also be accessed directly at import time:
Sentinel Playground
Loading the playground...
Press "Run" to get policy output
Although the above example is simple in nature, any nested map structure can be accessed this way. Note, lists cannot be indexed from the import path.