Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/db-agent/configs/db-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ name: Database Agent API
http:
listenPath: /db_agent
method: POST
next: $conditional.validate
next: conditional.validate

conditionals:
validate:
expression: |
{{ notempty (param "query") "Query" true }}
validPath: $action.agent
invalidPath: $response.400
onTrue: action.agent
onFalse: response.400

actions:
agent:
Expand All @@ -34,12 +34,12 @@ actions:
workflowConfig:
name: mongodbquerier
description: |
Accepts a filter query in the form of json and a projection in the form of json and performs queries on the collection "users"
Accepts a filter query in the form of json and a projection in the form of json and performs queries on the collection "users"
params: ["filter", "projection"]
returnValue: '{{ jsonout .variable_actions_queryDB}}'
start: "$action.queryDB"
returnValue: "{{ jsonout .variable_actions_queryDB}}"
start: "action.queryDB"
history: true
next: $response.200
next: response.200

queryDB:
type: mongoquery
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/configs/hello-world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Hello World API
http:
listenPath: /hello
method: GET
next: $response.success
next: response.success

responses:
success:
Expand Down
26 changes: 13 additions & 13 deletions examples/user-registration/configs/user-registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: User Registration API
http:
listenPath: /register
method: POST
next: $conditional.validateInput
next: conditional.validateInput

conditionals:
validateInput:
Expand All @@ -27,13 +27,13 @@ conditionals:
(notempty (param "password") "Password" true)
(notempty (param "name") "Name" true)
}}
validPath: $action.checkExistingUser
invalidPath: $response.validationError
onTrue: action.checkExistingUser
onFalse: response.validationError

userExists:
expression: "{{ gt (len .variable_actions_checkExistingUser) 0 }}"
validPath: $response.userAlreadyExists
invalidPath: $action.hashPassword
onTrue: response.userAlreadyExists
onFalse: action.hashPassword

actions:
checkExistingUser:
Expand All @@ -45,16 +45,16 @@ actions:
- field: email
operator: eq
value: '{{ param "email" }}'
next: $conditional.userExists
fail: $action.hashPassword
next: conditional.userExists
fail: action.hashPassword

hashPassword:
type: hash
config:
value: '{{ param "password" }}'
algorithm: bcrypt
next: $action.createUser
fail: $response.serverError
next: action.createUser
fail: response.serverError

createUser:
type: store
Expand All @@ -68,17 +68,17 @@ actions:
created_at: "{{ now }}"
status: active
mode: insert
next: $action.generateToken
fail: $response.serverError
next: action.generateToken
fail: response.serverError

generateToken:
type: jwt
config:
key: '{{ secret "JWT_SECRET" }}'
field: '{{ param "email" }}'
mode: encode
next: $response.registrationSuccess
fail: $response.serverError
next: response.registrationSuccess
fail: response.serverError

responses:
registrationSuccess:
Expand Down
12 changes: 3 additions & 9 deletions pkg/definitions/apiconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,10 @@ type Action struct {
Fail string `json:"fail" yaml:"fail"`
}

type ConditionalExpressions struct {
Value string `json:"value" yaml:"value"`
Type string `json:"type" yaml:"type"`
Compare string `json:"compare,omitempty" yaml:"compare,omitempty"`
}

type Conditional struct {
ValidPath string `json:"validPath" yaml:"validPath"`
InvalidPath string `json:"invalidPath" yaml:"invalidPath"`
Expression string `json:"expression" yaml:"expression"`
OnTrue string `json:"onTrue" yaml:"onTrue"`
OnFalse string `json:"onFalse" yaml:"onFalse"`
Expression string `json:"expression" yaml:"expression"`
}

type ResponseConfig struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/definitions/apiconfig_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"definitions": {
"HttpConfig": {
"type": "object",
"required": ["listenPath","method", "next"],
"required": ["listenPath", "method", "next"],
"properties": {
"listenPath": {
"type": "string"
Expand Down Expand Up @@ -140,10 +140,10 @@
"type": "object",
"required": ["expression"],
"properties": {
"validPath": {
"onTrue": {
"type": "string"
},
"invalidPath": {
"onFalse": {
"type": "string"
},
"expression": {
Expand Down
6 changes: 3 additions & 3 deletions pkg/definitions/apiconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func TestAPIConfig_SchemaValidate(t *testing.T) {
},
Conditionals: map[string]Conditional{
"cond1": {
ValidPath: "action1",
InvalidPath: "action2",
Expression: "request.id == 'test'",
OnTrue: "action1",
OnFalse: "action2",
Expression: "request.id == 'test'",
},
},
Responses: map[string]ResponseConfig{
Expand Down
6 changes: 3 additions & 3 deletions pkg/engine/plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/Servflow/servflow/internal/logging"
"github.com/Servflow/servflow/pkg/definitions"
apiconfig "github.com/Servflow/servflow/pkg/definitions"
"github.com/Servflow/servflow/pkg/engine/actions"
requestctx2 "github.com/Servflow/servflow/pkg/engine/requestctx"
"github.com/stretchr/testify/assert"
Expand All @@ -20,15 +20,15 @@ func TestPlan_Execute(t *testing.T) {
cfg := apiconfig.APIConfig{
Actions: map[string]apiconfig.Action{
"action1": {
Next: "$response.success",
Next: "response.success",
Type: "action1",
},
"action2": {
Type: "action2",
},
"action3": {
Type: "action3",
Next: "$response.second",
Next: "response.second",
},
},
Responses: map[string]apiconfig.ResponseConfig{
Expand Down
7 changes: 5 additions & 2 deletions pkg/engine/plan/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (p *PlannerV2) generateStep(id string) (Step, error) {
}
logging.GetLogger().Debug("Generating planner v2 step", zap.String("id", id))

// backwards compatibility
id = strings.TrimPrefix(id, "$")

if _, ok := p.finalSteps[id]; ok {
return p.finalSteps[id], nil
}
Expand Down Expand Up @@ -180,12 +183,12 @@ func (p *PlannerV2) generateConditionalStep(id string) (*ConditionStep, error) {
return nil, fmt.Errorf("condition not found: %s", id)
}

validStep, err := p.generateStep(condition.ValidPath)
validStep, err := p.generateStep(condition.OnTrue)
if err != nil {
return nil, err
}

invalidStep, err := p.generateStep(condition.InvalidPath)
invalidStep, err := p.generateStep(condition.OnFalse)
if err != nil {
return nil, err
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/engine/plan/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/Servflow/servflow/internal/logging"
"github.com/Servflow/servflow/pkg/definitions"
apiconfig "github.com/Servflow/servflow/pkg/definitions"
"github.com/Servflow/servflow/pkg/engine/actions"
"github.com/Servflow/servflow/pkg/engine/requestctx"
"github.com/stretchr/testify/assert"
Expand All @@ -20,15 +20,15 @@ var sampleConfig = &apiconfig.APIConfig{
Actions: map[string]apiconfig.Action{
"action1": {
Type: "action1",
Next: "$action.action2",
Next: "action.action2",
Config: map[string]interface{}{"key": "value"},
},
"action2": {
Next: "$action.action3",
Next: "action.action3",
Config: map[string]interface{}{"key": "value"},
},
"action3": {
Next: "$conditional.cond1",
Next: "conditional.cond1",
Config: map[string]interface{}{"key": "value2"},
},
"action4": {
Expand All @@ -37,15 +37,15 @@ var sampleConfig = &apiconfig.APIConfig{
Config: map[string]interface{}{"key": "value"},
},
"action5": {
Next: "$action.action4",
Next: "action.action4",
Config: map[string]interface{}{"key": "value"},
},
},
Conditionals: map[string]apiconfig.Conditional{
"cond1": {
Expression: "true",
ValidPath: "$response.success",
InvalidPath: "$response.failure",
Expression: "true",
OnTrue: "response.success",
OnFalse: "response.failure",
},
},
Responses: map[string]apiconfig.ResponseConfig{
Expand Down Expand Up @@ -107,19 +107,19 @@ func TestPlannerV2_Generate(t *testing.T) {
config := &apiconfig.APIConfig{
Actions: map[string]apiconfig.Action{
"action1": {
Next: "$conditional.cond1",
Next: "conditional.cond1",
Config: map[string]interface{}{"key": "value"},
},
"action2": {
Config: map[string]interface{}{"key": "value2"},
Fail: "$response.failure",
Fail: "response.failure",
},
},
Conditionals: map[string]apiconfig.Conditional{
"cond1": {
Expression: "true",
ValidPath: "$response.success",
InvalidPath: "$response.failure",
Expression: "true",
OnTrue: "response.success",
OnFalse: "response.failure",
},
},
Responses: map[string]apiconfig.ResponseConfig{
Expand Down Expand Up @@ -322,9 +322,9 @@ func TestPlannerV2_generateConditionalStep(t *testing.T) {
config := &apiconfig.APIConfig{
Conditionals: map[string]apiconfig.Conditional{
"cond1": {
Expression: `{{ (and (email (printf "%s" .email) "email" false) (eq (printf "%s" .field1) (printf "hello" ))) }}`,
ValidPath: "$response.success",
InvalidPath: "$response.failure",
Expression: `{{ (and (email (printf "%s" .email) "email" false) (eq (printf "%s" .field1) (printf "hello" ))) }}`,
OnTrue: "response.success",
OnFalse: "response.failure",
},
},
Responses: map[string]apiconfig.ResponseConfig{
Expand Down
8 changes: 3 additions & 5 deletions pkg/engine/requestctx/dpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ type DataType int
const noValue = "<no value>"

const (
GroupTagPrefix = "$grouptag_"
GroupTagFinish = GroupTagPrefix + "finish"
ActionConfigPrefix = "$action."
ConditionalConfigPrefix = "$conditional."
ResponsesConfigPrefix = "$response."
ActionConfigPrefix = "action."
ConditionalConfigPrefix = "conditional."
ResponsesConfigPrefix = "response."
BareVariablesPrefixStripped = "variable_"
VariableActionPrefix = BareVariablesPrefixStripped + "actions_"
ErrorTagStripped = "error"
Expand Down
10 changes: 5 additions & 5 deletions pkg/engine/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http/httptest"
"testing"

"github.com/Servflow/servflow/pkg/definitions"
apiconfig "github.com/Servflow/servflow/pkg/definitions"
plan2 "github.com/Servflow/servflow/pkg/engine/plan"
"github.com/Servflow/servflow/pkg/engine/requestctx"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestCreateCustomMuxHandler(t *testing.T) {
config := &apiconfig.APIConfig{
McpTool: apiconfig.MCPToolConfig{
Name: "mcptool",
Start: "$action.action1",
Start: "action.action1",
Result: fmt.Sprintf(`{{ .%saction2.key }}`, requestctx.VariableActionPrefix),
//Result: dpl.VariableActionPrefix + "action2",
Description: "Test Endpoint",
Expand All @@ -183,7 +183,7 @@ func TestCreateCustomMuxHandler(t *testing.T) {
},
"action1": {
Type: "stub",
Next: "$action.action2",
Next: "action.action2",
Config: map[string]interface{}{
"key": "value",
},
Expand Down Expand Up @@ -310,12 +310,12 @@ func TestExtractURLParam(t *testing.T) {
HttpConfig: apiconfig.HttpConfig{
ListenPath: "/test/{id}",
Method: "POST",
Next: "$action.action1",
Next: "action.action1",
},
Actions: map[string]apiconfig.Action{
"action1": {
Type: "stub",
Next: "$response.finish",
Next: "response.finish",
Config: map[string]interface{}{
"key": "value",
},
Expand Down
Loading