Skip to navigation

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 Gateway:

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.
x-itential-payload-typeFor Python script services, set to file to have Gateway write a large property value to a temporary file instead of passing it as a CLI argument. Requires x-itential-payload-target. For more information, see Pass large values as files in Python script services.
x-itential-payload-targetThe name of the environment variable Gateway uses to pass the temporary file path to your script when x-itential-payload-type is set to file.

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:

{
"$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
}

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 Gateway 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