- 20 Dec 2024
-
DarkLight
-
PDF
create decorator
- Updated on 20 Dec 2024
-
DarkLight
-
PDF
iagctl create decorator
Create a new decorator
Synopsis
The command will create a decorator in the gateway data store. Decorators can be attached to services when they are created, and they allow you to validate any data that is passed into a service when executed via the run
command.
Decorators utilize JSON Schema to actually perform input validation. Consider a gateway service that takes in two inputs: interface
and device_type
. You can create the following JSON schema document to validate those inputs:
{
"$id": "root",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"interface": {
"type": "string",
"description": "The interface to update"
},
"device_type": {
"type": "string",
"description": "The type of device",
"enum": ["ios", "eos", "nxos"]
}
},
"required": [
"interface",
"device_type"
],
"additionalProperties": false
}
Later, when you create a new service, the decorator can be specified. The decorator can then validate that both interface
and device_type
were correctly passed in using the --set
flag at runtime as shown below.
>_ iagctl run pythonscript example-service-with-deco \
--set interface=1/1/1 \
--set device_type=eos
If any issues are found with the incoming data, they will be reported back to the user as an error.
Specifying Properties
Each input to your service will exist within the properties
object of the JSON Schema document. Pay special attention to the following fields and how they are used within gateway.
Field | Description |
---|---|
type |
The type of data you are passing into the service. Can be one of the following options: string, number, integer, object, array, boolean, null |
enum |
Denotes a limited set of values that will be accepted. |
Many other validations can be performed and are available on the JSON Schema JSON Schema website.
iagctl create decorator <decorator-name> --schema <string> [flags]
Examples
Create Decorator via JSON Schema File
Consider a JSON Schema document called my_decorator.json
. In this case, you will need to have access to this file via the command line. You can create a decorator from this file using the syntax shown below.
>_ iagctl create decorator my-decorator \
--schema @my_decorator.json
A schema file formatted in JSON would be typical, but YAML formatting is also accepted.
Create Decorator via Direct JSON
You can also create a decorator by specifying the contents of a JSON Schema document directly into the CLI. Only JSON is accepted here. Be sure to wrap your JSON in single quotes.
>_ iagctl create decorator my-decorator \
--schema '{"$id":"root","$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"interface":{"type":"string"}}}'
Options
--description string A brief description of the decorator
-h, --help Help for decorator
--schema string The schema of the decorator. This can be inline json or can reference a file by prefixing '@'.
--tag stringArray Metadata tag(s) to associate with the decorator
Options Inherited from Parent Commands
--config string Path to the configuration file
--raw Displays the result of the command in its raw format
--verbose Enable verbose output
CLI References
See related create
commands:
- create
- create repository
- create secret
- create service
- create service ansible playbook
- create service opentofu plan
- create service python script
- create user
For all CLI commands see → Command References Index