Chain Source

A chain source defines how a Chain gets its value. It populates the source field of a chain. There are multiple source types, and the type is specified using YAML's tag syntax.

Examples

See the Chain docs for more complete examples.

!request
recipe: login
trigger: !expire 12h
---
!command
command: ["echo", "-n", "hello"]
---
!env
variable: USERNAME
---
!file
path: ./username.txt
---
!prompt
message: Enter Password

Variants

VariantTypeDescription
!requestChainSource::RequestBody of the most recent response for a specific request recipe.
!commandChainSource::CommandStdout of the executed command
!envChainSource::EnvironmentValue of an envionrment variable, or empty string if undefined
!fileChainSource::FileContents of the file
!promptChainSource::PromptValue entered by the user
!selectChainSource::SelectUser selects a value from a list

Request

Chain a value from the body of another response. This can reference either

FieldTypeDescriptionDefault
recipestringRecipe to load value fromRequired
triggerChainRequestTriggerWhen the upstream recipe should be executed, as opposed to loaded from memory!never
sectionChainRequestSectionThe section (header or body) of the request from which to chain a valueBody

Chain Request Trigger

This defines when a chained request should be triggered (i.e. when to execute a new request) versus when to use the most recent from history.

VariantTypeDescription
neverNoneNever trigger. The most recent response in history for the upstream recipe will always be used; error out if there is none
no_historyNoneTrigger only if there is no response in history for the upstream recipe
expireDurationTrigger if the most recent response for the upstream recipe is older than some duration, or there is none
alwaysNoneAlways execute the upstream request

Duration is specified as an integer followed by a unit (with no space). Supported units are:

  • s (seconds)
  • m (minutes)
  • h (hours)
  • d (days)

Examples

!request
recipe: login
trigger: !never # This is the default, so the same as omitting
---
!request
recipe: login
trigger: !no_history
---
!request
recipe: login
trigger: !expire 12h
---
!request
recipe: login
trigger: !expire 30s
---
!request
recipe: login
trigger: !always

Chain Request Section

This defines which section of the response (headers or body) should be used to load the value from.

VariantTypeDescription
bodyNoneThe body of the response
headerTemplateA specific header from the response. If the header appears multiple times in the response, only the first value will be used

Examples

!request
recipe: login
section: !header Token # This will take the value of the 'Token' header

Command

Execute a command and use its stdout as the rendered value.

FieldTypeDescriptionDefault
commandTemplate[]Command to execute, in the format [program, ...arguments]Required
stdinTemplateStandard input which will be piped into the commandNone
username:
  source: !command
    command: [whoami]

Environment Variable

Load a value from an environment variable.

FieldTypeDescriptionDefault
variableTemplateVariable to loadRequired

Examples

current_dir:
  source: !env
    variable: PWD

File

Read a file and use its contents as the rendered value.

FieldTypeDescriptionDefault
pathTemplatePath of the file to load (relative to current directory)Required

Examples

username:
  source: !file
    path: ./username.txt

Prompt

Prompt the user for text input to use as the rendered value.

FieldTypeDescriptionDefault
messageTemplateDescriptive prompt for the userChain ID
defaultTemplateValue to pre-populated the prompt textbox. Note: Due to a library limitation, not supported on chains with sensitive: true in the CLInull

Examples

password:
  source: !prompt
    message: Enter Password
  sensitive: true

Select

Prompt the user to select a defined value from a list.

FieldTypeDescriptionDefault
messageTemplateDescriptive prompt for the userChain ID
optionsSelectOptionsList of options to present to the userRequired

Select Options

The list of options to present to the user. This can be a static list of values or a dynamic template to generate the list of options.

VariantTypeDescription
fixedTemplate[]Fixed list of options
dynamicTemplateTemplate that renders to a JSON array

Examples

fruit:
  source: !select
    message: Select Fruit
    options:
      - apple
      - banana
      - guava
fruit_response:
  source: !request
    recipe: list_fruit
  # Assume this response body looks like:
  # [{ "name": "apple" }, { "name": "guava" }, { "name": "pear" }]
  selector: $[*].name
dynamic_fruit:
  source: !select
    message: Select Fruit
    # This option is powerful when combined with the `selector` field on an
    # upstream chain
    options: "{{chains.fruit_response}}"