sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

allow empty auth definitions in parser

Open spolti opened this issue 3 years ago • 3 comments

fixes https://github.com/serverlessworkflow/sdk-go/issues/110

Signed-off-by: spolti [email protected]

Many thanks for submitting your Pull Request :heart:!

What this PR does / why we need it:

Special notes for reviewers:

Additional information (if needed):

spolti avatar Oct 20 '22 22:10 spolti

The problem is not cause by AuthDefinitions.Unmarshal implement, according to the specificaiton, auth field is an array of object, which like: image

But in the source code, we place an Defs field under Auth Definition struct. So after we marshal object to json, it looks like:

{
	"id": "applicantrequest",
	"name": "Applicant Request Decision Workflow",
	"description": "Determine if applicant request is valid",
	"version": "1.0",
	"start": {
		"stateName": "CheckApplication"
	},
	"specVersion": "0.7",
	"expressionLang": "jq",
	"auth": {
		"Defs": [{
			"name": "testAuth",
			"scheme": "bearer",
			"properties": {
				"token": "test_token"
			}
		}, {
			"name": "testAuth2",
			"scheme": "basic",
			"properties": {
				"username": "test_user",
				"password": "test_pwd"
			}
		}]
	},
	"states": [{
		"name": "CheckApplication",
		"type": "switch",
		"defaultCondition": {},
		"dataConditions": [{
			"condition": "${ .applicants | .age \u003e= 18 }",
			"transition": {
				"nextState": "StartApplication"
			}
		}, {
			"condition": "${ .applicants | .age \u003c 18 }",
			"transition": {
				"nextState": "RejectApplication"
			}
		}],
		"timeouts": {}
	}, {
		"name": "StartApplication",
		"type": "operation",
		"end": {
			"terminate": true
		},
		"actions": [{
			"subFlowRef": {
				"workflowId": "startApplicationWorkflowId",
				"invoke": "sync",
				"onParentComplete": "terminate"
			},
			"sleep": {},
			"actionDataFilter": {
				"useResults": true
			}
		}]
	}, {
		"name": "RejectApplication",
		"type": "operation",
		"end": {
			"terminate": true
		},
		"actionMode": "sequential",
		"actions": [{
			"functionRef": {
				"refName": "sendRejectionEmailFunction",
				"invoke": "sync"
			},
			"sleep": {},
			"actionDataFilter": {
				"useResults": true
			}
		}]
	}],
	"functions": [{
		"name": "sendRejectionEmailFunction",
		"operation": "http://myapis.org/applicationapi.json#emailRejection"
	}],
	"retries": [{
		"name": "TimeoutRetryStrategy",
		"delay": "PT1M",
		"maxAttempts": "5",
		"jitter": 0
	}]
}

It's not equivalent. I think we should fix the struct field layout.

lsytj0413 avatar Oct 21 '22 05:10 lsytj0413

needed for v08 https://github.com/serverlessworkflow/sdk-go/issues/70

spolti avatar Oct 24 '22 14:10 spolti

About the defs problem, there is another problem as well, see:

https://gist.github.com/spolti/ac43ce2cc5a51532987259db4f9fa5b7 Will address it on another issue: https://github.com/serverlessworkflow/sdk-go/issues/126

spolti avatar Oct 26 '22 16:10 spolti

/lgtm

lsytj0413 avatar Nov 05 '22 14:11 lsytj0413