iagctl create decorator

Create a new decorator.

For detailed information on creating and using decorators, see Validate and limit service inputs with decorators.

The iagctl create decorator command creates a decorator in your gateway data store. Decorators use JSON Schema to validate the inputs passed to a service at runtime, letting you control exactly which inputs a service accepts.

Syntax

$iagctl create decorator <decorator-name> --schema <string> [flags]

JSON Schema overview

Decorators rely on a JSON Schema document to define and validate service inputs. Each service input corresponds to a property in the schema’s properties object.

The following fields are particularly relevant in IAG:

FieldDescription
typeThe data type for the input. Accepts one of the following values: string, number, integer, object, array, boolean, or null. For Python script services, properties defined as boolean use bare --set key syntax at runtime rather than --set key=value. For more information, see Boolean properties in Python script services.
enumA limited set of accepted values for the input.

For additional validation options, see the JSON Schema website.

For example, consider a gateway service that takes two inputs: interface and device_type. The following JSON Schema document validates those inputs:

1{
2 "$id": "root",
3 "$schema": "https://json-schema.org/draft/2020-12/schema",
4 "type": "object",
5 "properties": {
6 "interface": {
7 "type": "string",
8 "description": "The interface to update"
9 },
10 "device_type": {
11 "type": "string",
12 "description": "The type of device",
13 "enum": ["ios", "eos", "nxos"]
14 }
15 },
16 "required": [
17 "interface",
18 "device_type"
19 ],
20 "additionalProperties": false
21}

When you specify this decorator on a service, it validates that the interface and device_type inputs are passed correctly in the iagctl run service request:

$iagctl run pythonscript example-service-with-deco \
>--set interface=1/1/1 \
>--set device_type=eos

Examples

Create a decorator from a file

To create a decorator from a JSON Schema file called my_decorator.json, run the following command:

$iagctl create decorator my-decorator \
>--schema @my_decorator.json

You typically format schema files as JSON, but IAG also accepts YAML.

Create a decorator from inline JSON

You can also specify the JSON Schema content directly in the command. 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. Accepts inline JSON or a file reference prefixed with '@'.
$ --tag stringArray Metadata tag(s) to associate with the decorator

Options inherited from parent commands

$ --profile string Specify the client profile to use (case-insensitive, defaults to [client] section)
$ --config string Path to the configuration file
$ --raw Display the result of the command in raw format
$ --verbose Enable verbose output