This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Workaround for Accessing config_context in a Mistral Workflow

Reference

Problem
Currently in a Mistral Workflow you can not access the config_context described here: Actions — StackStorm 2.10.1 documentation

StackStorm currently doesn’t pass this context into Mistral or provide a Jinja filter to access it.

Workaround
To access the config context information in a Mistral workflow, you can simply create a new parameter in the StackStorm action metadata. This new paramter can be immutable parameter and set with default that reads from the config context.

Example :

Action metadata file

parameters:
    config_username:
        type: "string"
        description: "Username from the pack's config"
        required: true
        immutable: true
        default: "{{ config_context.username }}"

Finally, add this new parameter as an input in your Mistral workflow, then you can access it like a normal Mistral variable.

examples.config_context_example:
  description: 
  type: direct
  input:
    - config_username

  tasks:
    action: core.local
    input:
      cmd: "echo {{ _.config_username }}"

We have added a task to just fetch the pack config in the workflow.

pack_config:
    action: core.http
    input:
      url: "{{ env().st2_action_api_url }}/configs/{{ env()['__actions']['st2.action']['st2_context']['parent']['pack'] }}"
      method: GET
      headers:
        X-Auth-Token: "{{ env()['__actions']['st2.action']['st2_context']['auth_token'] }}"
   on-success:
      - call_next_task

Later, you can define input or output to tasks / workflows like so:

      schema_registry_url: '<% task(pack_config).result.body.values.kafka_schema_registry_url %>'
      bootstrap_servers:   "{{ task('pack_config')['result']['body']['values']['kafka_bootstrap_servers'] }}"

Attempting to reproduce this above in orquesta - but the env() appears not to be a function there. Is there a list of all the system functions / data structures availalbe for orquesta ? I have seached the docs to no avail.

Try this doc section on StackStorm Context and Functions

Here is an Orquestra workflow that replicates the one above. The workflow context does not include an “auth token” to make the API call, so it is stored in the ST2 keystore and the name of the key is submitted as input to the workflow. It is written to pull the Pack name out of the workflow context as well but since it is using the API, it could be re-worked to have that submitted as input to the workflow as well to get config values from another Pack if needed.

version: 1.0

description: A workflow to pull the pack config values from the system using an API call over HTTPS

#############################################
#   Need a valid API key to access ST2 API  #
#############################################

input:
  - api_key_name

##################################################
#  Variables published by workflow on success    #
##################################################

vars:
  - pack_config:
- api_key_value:

#########################################
#   Output at the end of the workflow   #
#########################################

output:
  - pack_config: <% ctx().pack_config %>

##################################
#   Workflow tasks to complete   #
##################################

tasks:
  get_api_token:
    action: st2.kv.get
    input:
      key: <% ctx().api_key_name %>
      decrypt: True
    next:
      - when: <% succeeded() %>
        publish: api_key_value=<% result().result %>
        do: get_pack_config
  get_pack_config:
    action: core.http
    input:
      url: <% ctx().st2.api_url %>/configs/<% ctx().st2.pack %>
      method: GET
      headers: {"St2-Api-Key": <% ctx().api_key_value %>}
      params: {"show_secrets": "True"}
    next:
      - when: <% succeeded() %>
        publish: pack_config=<% result().body.values %>

The yaml file for this workflow is:

---
name: get_pack_config
pack: packname
description: Workflow to extract the pack config data using an HTTP api call
runner_type: orquesta
entry_point: workflows/get_pack_config.yaml
enabled: true
parameters:
  api_key_name:
    required: true
    type: string
    description: Name of the keystore entry that contains a valid ST2 API key