Replace request/response with new commands

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-09-05 08:40:59 +02:00
parent f6ce9935a5
commit 58a800e5e9
13 changed files with 72 additions and 74 deletions
+4 -4
View File
@@ -34,7 +34,7 @@ that contains:
.. code-block:: bash
kapow route add /backups \
-c 'cloudx storage ls /backups | grep $(request /params/query) | response /body'
-c 'cloudx storage ls /backups | grep $(kapow get /request/params/query) | kapow set /response/body'
and execute it in the host with the command:
@@ -53,7 +53,7 @@ First you must create a pow file named ``hello.pow`` with the following contents
.. code-block:: bash
kapow route add /greet -c "echo 'hello world' | response /body"
kapow route add /greet -c "echo 'hello world' | kapow set /response/body"
then, you must execute:
@@ -75,7 +75,7 @@ First you must create a pow file named ``echo.pow`` with the following contents:
.. code-block:: bash
kapow route add -X POST /echo -c 'request /body | response /body'
kapow route add -X POST /echo -c 'kapow get /request/body | kapow set /response/body'
then, you must execute:
@@ -108,7 +108,7 @@ Let's write a ``multiline.pow`` file with the following content:
kapow route add /log_and_love - <<- 'EOF'
echo "[$(date)] and stuff" >> stuff.log
echo love | response /body
echo love | kapow set /response/body
EOF
and then we serve it with ``kapow``:
-2
View File
@@ -10,8 +10,6 @@ zip_safe = True
include_package_data = True
scripts =
bin/kapow
bin/request
bin/response
bin/static
install_requires =
aiohttp==3.5.4
+14 -14
View File
@@ -159,7 +159,7 @@ Content-Length: 189
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
"index": 0,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
@@ -194,7 +194,7 @@ field must be a json scaped string.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
"index": 0,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
},
@@ -202,7 +202,7 @@ field must be a json scaped string.
"method": "POST",
"url_pattern": "/bye",
"entrypoint": null,
"command": "echo Bye World | response /body",
"command": "echo Bye World | kapow set /response/body",
"index": 1,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
@@ -227,7 +227,7 @@ A new id is created for the appended route so it can be referenced later.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body"
"command": "echo Hello World | kapow set /response/body"
}
```
* **Success Responses**:
@@ -239,7 +239,7 @@ A new id is created for the appended route so it can be referenced later.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
"index": 0,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
@@ -254,7 +254,7 @@ A new id is created for the appended route so it can be referenced later.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body"
"command": "echo Hello World | kapow set /response/body"
}
EOF
```
@@ -280,7 +280,7 @@ A new id is created for the appended route so it can be referenced later.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
}
```
* **Success Responses**:
@@ -292,7 +292,7 @@ A new id is created for the appended route so it can be referenced later.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
"index": 0,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
@@ -307,7 +307,7 @@ A new id is created for the appended route so it can be referenced later.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
"index": 0
}
EOF
@@ -354,7 +354,7 @@ Retrieves the information about the route identified by `{id}`.
"method": "GET",
"url_pattern": "/hello",
"entrypoint": null,
"command": "echo Hello World | response /body",
"command": "echo Hello World | kapow set /response/body",
"index": 0,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
@@ -673,7 +673,7 @@ Options:
#### Example
```sh
kapow route add -X GET '/list/{ip}' -c 'nmap -sL $(request /matches/ip) | response /body'
kapow route add -X GET '/list/{ip}' -c 'nmap -sL $(kapow get /request/matches/ip) | kapow set /response/body'
```
### `request`
@@ -689,7 +689,7 @@ Exposes the requests' resources.
#### Example
```sh
# Access the body of the request
request /body
kapow get /request/body
```
@@ -706,14 +706,14 @@ Exposes the response's resources.
#### Example
```sh
# Write to the body of the response
echo 'Hello, World!' | response /body
echo 'Hello, World!' | kapow set /response/body
```
## An End-to-End Example
```sh
$ cat nmap.kpow
kapow route add -X GET '/list/{ip}' -c 'nmap -sL $(request /matches/ip) | response /body'
kapow route add -X GET '/list/{ip}' -c 'nmap -sL $(kapow get /request/matches/ip) | kapow set /response/body'
```
```sh
$ kapow ./nmap.kapow
@@ -12,7 +12,7 @@ Feature: Kapow! server rejects requests with semantic errors.
"""
{
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body"
"command": "ls -la / | kapow set /response/body"
}
"""
Then I get 422 as response code
@@ -29,7 +29,7 @@ Feature: Kapow! server rejects requests with semantic errors.
"method": "GET",
"url_pattern": "+123--",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body"
"command": "ls -la / | kapow set /response/body"
}
"""
Then I get 422 as response code
@@ -14,7 +14,7 @@ Feature: Append new routes in Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body"
"command": "ls -la / | kapow set /response/body"
}
"""
Then I get 201 as response code
@@ -25,7 +25,7 @@ Feature: Append new routes in Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
}
@@ -37,15 +37,15 @@ Feature: Append new routes in Kapow! server.
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
When I append the route:
"""
{
"method": "GET",
"url_pattern": "/baz",
"entrypoint": "/bin/sh -c",
"command": "ls -la /etc | response /body"
"command": "ls -la /etc | kapow set /response/body"
}
"""
Then I get 201 as response code
@@ -56,7 +56,7 @@ Feature: Append new routes in Kapow! server.
"method": "GET",
"url_pattern": "/baz",
"entrypoint": "/bin/sh -c",
"command": "ls -la /etc | response /body",
"command": "ls -la /etc | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -5,10 +5,10 @@ Feature: Consistent route order after a route deletion in Kapow! server.
Background:
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /bar | /bin/sh -c | ls -la /var \| response /body |
| GET | /baz | /bin/sh -c | ls -la /etc \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /bar | /bin/sh -c | ls -la /var \| kapow set /response/body |
| GET | /baz | /bin/sh -c | ls -la /etc \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
Scenario: Removing the first route.
After removing the first route the remaining ones
@@ -24,7 +24,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -32,7 +32,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/baz",
"entrypoint": "/bin/sh -c",
"command": "ls -la /etc | response /body",
"command": "ls -la /etc | kapow set /response/body",
"index": 1,
"id": ANY
},
@@ -40,7 +40,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/qux/{dirname}",
"entrypoint": "/bin/sh -c",
"command": "ls -la /request/params/dirname | response /body",
"command": "ls -la /request/params/dirname | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -60,7 +60,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -68,7 +68,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 1,
"id": ANY
},
@@ -76,7 +76,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/baz",
"entrypoint": "/bin/sh -c",
"command": "ls -la /etc | response /body",
"command": "ls -la /etc | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -97,7 +97,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -105,7 +105,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/baz",
"entrypoint": "/bin/sh -c",
"command": "ls -la /etc | response /body",
"command": "ls -la /etc | kapow set /response/body",
"index": 1,
"id": ANY
},
@@ -113,7 +113,7 @@ Feature: Consistent route order after a route deletion in Kapow! server.
"method": "GET",
"url_pattern": "/qux/{dirname}",
"entrypoint": "/bin/sh -c",
"command": "ls -la /request/params/dirname | response /body",
"command": "ls -la /request/params/dirname | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -7,8 +7,8 @@ Feature: Delete routes in Kapow! server.
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
When I delete the first route
Then I get 204 as response code
And I get "No Content" as response reason phrase
@@ -7,8 +7,8 @@ Feature: Retrieve route details in Kapow! server.
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
When I get the first route
Then I get 200 as response code
And I get "OK" as response reason phrase
@@ -18,7 +18,7 @@ Feature: Retrieve route details in Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
}
@@ -15,7 +15,7 @@ Feature: Kapow! server rejects insertion requests with malformed JSON bodies.
"url_pattern": /hello,
"entrypoint": null
"command": "echo Hello
World | response /body",
World | kapow set /response/body",
"index": 0,
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
@@ -11,7 +11,7 @@ Feature: Kapow! server rejects insertion requests with semantic errors.
"""
{
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body"
"command": "ls -la / | kapow set /response/body"
}
"""
Then I get 422 as response code
@@ -28,7 +28,7 @@ Feature: Kapow! server rejects insertion requests with semantic errors.
"method": "GET",
"url_pattern": "+123--",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0
}
"""
@@ -46,7 +46,7 @@ Feature: Kapow! server rejects insertion requests with semantic errors.
"method": "GET",
"url_pattern": "+123--",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": -1
}
"""
@@ -5,8 +5,8 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
Background:
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
Scenario: Inserting before the first route.
After inserting before the first route the previous set
@@ -19,7 +19,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 0
}
"""
@@ -31,7 +31,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -39,7 +39,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 1,
"id": ANY
},
@@ -47,7 +47,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/qux/{dirname}",
"entrypoint": "/bin/sh -c",
"command": "ls -la /request/params/dirname | response /body",
"command": "ls -la /request/params/dirname | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -64,7 +64,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 2
}
"""
@@ -76,7 +76,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -84,7 +84,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/qux/{dirname}",
"entrypoint": "/bin/sh -c",
"command": "ls -la /request/params/dirname | response /body",
"command": "ls -la /request/params/dirname | kapow set /response/body",
"index": 1,
"id": ANY
},
@@ -92,7 +92,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -110,7 +110,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 1
}
"""
@@ -122,7 +122,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -130,7 +130,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 1,
"id": ANY
},
@@ -138,7 +138,7 @@ Feature: Consistent route ordering after inserting a route in a Kapow! server.
"method": "GET",
"url_pattern": "/qux/{dirname}",
"entrypoint": "/bin/sh -c",
"command": "ls -la /request/params/dirname | response /body",
"command": "ls -la /request/params/dirname | kapow set /response/body",
"index": 2,
"id": ANY
}
@@ -6,8 +6,8 @@ Feature: Insert new routes in Kapow! server.
Background:
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
Scenario: Insert a route at the beginning.
A route can be inserted at the beginning of the list
@@ -19,7 +19,7 @@ Feature: Insert new routes in Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 0
}
"""
@@ -31,7 +31,7 @@ Feature: Insert new routes in Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 0,
"id": ANY
}
@@ -48,7 +48,7 @@ Feature: Insert new routes in Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 1
}
"""
@@ -60,7 +60,7 @@ Feature: Insert new routes in Kapow! server.
"method": "GET",
"url_pattern": "/bar",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"command": "ls -la /var | kapow set /response/body",
"index": 1,
"id": ANY
}
@@ -22,8 +22,8 @@ Feature: Listing routes in a Kapow! server.
Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command |
| GET | /foo | /bin/sh -c | ls -la / \| response /body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
| GET | /foo | /bin/sh -c | ls -la / \| kapow set /response/body |
| GET | /qux/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| kapow set /response/body |
When I request a routes listing
Then I get 200 as response code
And I get "OK" as response reason phrase
@@ -34,7 +34,7 @@ Feature: Listing routes in a Kapow! server.
"method": "GET",
"url_pattern": "/foo",
"entrypoint": "/bin/sh -c",
"command": "ls -la / | response /body",
"command": "ls -la / | kapow set /response/body",
"index": 0,
"id": ANY
},
@@ -42,7 +42,7 @@ Feature: Listing routes in a Kapow! server.
"method": "GET",
"url_pattern": "/qux/{dirname}",
"entrypoint": "/bin/sh -c",
"command": "ls -la /request/params/dirname | response /body",
"command": "ls -la /request/params/dirname | kapow set /response/body",
"index": 1,
"id": ANY
}