A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/sentinel/docs/extending/static-imports below:

Extending Sentinel: Static Imports | 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.

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;

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:

Loading the playground...

Press "Run" to get policy output

However, the data can also be accessed directly at import time:

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4