jexia / semaphore

Take control of your data, connect with anything, and expose it anywhere through protocols such as HTTP, GraphQL, and gRPC.

Home Page:https://jexia.github.io/semaphore/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom defined functions

jeroenrinzema opened this issue · comments

Currently, it is possible to define custom-defined functions and pass them as an argument when initializing Maestro. These functions could be used inside property templates to manipulate data.

Functions could call services to validate values or to generate a new value. The output is returned and could be referenced as a resource.

// define a function called authenticate
function "authenticate" {
  input {
    token = "string"
  }

  resource "auth" {
    request "maestro.Authenticate" "Authenticate" {
      token = "{{ input:token }}"
    }
  }

  output {
    valid = "{{ auth:valid }}"
    name = "{{ auth:claim.name }}"
  }
}

flow "greeter" {
  input "maestro.greeter.Request" {}

  // resources are functions or properties which are referenced
  resources {
    auth = "authenticate(input.header:Authorization)",
  }

  resource "user" {
    request "maestro.greeter.Say" "Hello" {
      name = "{{ auth:name }}"
    }
  }

  output "maestro.greeter.Response" {
    msg = "{{ user:msg }}"
  }
}