Skip to content

Commit

Permalink
documentation for remote postserve action
Browse files Browse the repository at this point in the history
  • Loading branch information
kapishmalik committed Apr 5, 2024
1 parent 3cbdfeb commit a63fb91
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 5 additions & 3 deletions docs/pages/keyconcepts/postserveaction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ Post Serve Action
Overview
--------

- PostServeAction allows you to execute custom code after a response has been served in simulate or spy mode.
- PostServeAction allows you to execute custom code or invoke endpoint with request-response pair after a response has been served in simulate or spy mode.

- It is custom script that can be written in any language. Hoverfly has the ability to invoke a script or binary file on a host operating system. Custom code is execute after a provided delay(in ms) once simulated response is served.
- It is custom script that can be written in any language. Hoverfly has the ability to invoke a script or binary file on a host operating system or on the remote host. Custom code is executed/remote host is invoked after a provided delay(in ms) once simulated response is served.

- We can register multiple post serve actions.

- In order to register post serve action, it takes mainly four parameters - binary to invoke script, script content/location, delay(in ms) post which it will be executed and name of that action.
- In order to register local post serve action, it takes mainly four parameters - binary to invoke script, script content/location, delay(in ms) post which it will be executed and name of that action.

- In order to register remote post serve action, it takes mainly three parameters - remote host to be invoked with request-response pair, delay(in ms) post which it will be executed and name of that action.

Ways to register a Post Serve Action
------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion docs/pages/reference/hoverfly/hoverfly.output
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ Usage of hoverfly:
-metrics
Enable metrics logging to stdout
-post-serve-action string
Set post serve action by passing the action name, binary and the path of the action script and delay in Ms separated by space.
Set local post serve action by passing the action name, binary and the path of the action script and delay in Ms separated by space.
(i.e. -post-serve-action "<action name> python3 <script path to load> 1000" -post-serve-action "<action name> python3 <script path to load> 3000")
Set remote post serve action by passing the action name, remote host and delay in Ms separated by space.
(i.e. -post-serve-action "<action name> <http/https remote host> 1000" -post-serve-action "<action name> <http/https remote host> 3000")
We can set multiple post serve actions and use in our simulation schema file.
-middleware string
Set middleware by passing the name of the binary and the path of the middleware script separated by space. (i.e. '-middleware "python script.py"')
Expand Down
18 changes: 17 additions & 1 deletion examples/postserveaction/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Steps for invoking post serve action
# Examples
## Steps for invoking local post serve action

- Install the python requests library via pip
```shell
Expand All @@ -15,3 +16,18 @@
```shell
INFO[2023-09-03T12:46:25+01:00] Output from post serve action HTTP call invoked from IP Address: 100.197.184.111
```

## Steps for invoking remote post serve action

- Start hoverfly by passing a remote post-serve-action, and a simulation file that invokes post serve action by its name.

```shell
hoverfly -post-serve-action "outbound-http https://echo.free.beeceptor.com 1000" -import examples/postserveaction/simulation-with-callback.json
```
- You can verify that the post serve action is registered by using the admin endpoint: http://localhost:8888/api/v2/hoverfly/post-serve-action

- Proxying a request to http://helloworld-test.com should invoke remote postserve action to https://echo.free.beeceptor.com,
and the log should be printed out to the hoverfly logs:
```shell
INFO[2024-04-05T12:09:58+05:30] Remote post serve action invoked successfully
```
6 changes: 4 additions & 2 deletions hoverctl/cmd/postserveaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ var postServeActionSetCommand = &cobra.Command{
Use: "set",
Short: "Set postServeAction for Hoverfly",
Long: `
Hoverfly PostServeAction can be set using the following flags:
--name --binary --script --delay --remote
Hoverfly Local PostServeAction can be set using the following flags:
--name --binary --script --delay
Hoverfly Remote PostServeAction can be set using the following flags:
--name --remote --delay
`,
Run: func(cmd *cobra.Command, args []string) {
checkTargetAndExit(target)
Expand Down

0 comments on commit a63fb91

Please sign in to comment.