File: README.md

package info (click to toggle)
aws-crt-python 0.28.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,428 kB
  • sloc: ansic: 437,955; python: 27,657; makefile: 5,855; sh: 4,289; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (51 lines) | stat: -rw-r--r-- 2,138 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Mock S3 server

A **NON-TLS** mock S3 server based on [python-hyper/h11](https://github.com/python-hyper/h11) and [trio](http://trio.readthedocs.io/en/latest/index.html). The server code implementation is based on the trio-server example from python-hyper/h11 [here](https://github.com/python-hyper/h11/blob/master/examples/trio-server.py). Only supports very basic mock response for request received.

## How to run the server

Python 3.7+ required.

- Install hyper/h11 and trio python module. `python3 -m pip install h11 trio`
- Run python. `python3 ./mock_s3_server.py`.

### Supported Operations

- CreateMultipartUpload
- CompleteMultipartUpload
- UploadPart
- AbortMultipartUpload
- GetObject

### Defined response

The server will read from ./{OperationName}/{Key}.json. The json file is formatted as following:

```json
{
    "status": 200,
    "headers": {"Connection": "close"},
    "request_headers:" {"HeaderA": "ValueA"}
    "body": [
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
        "",
        "<Error>",
         "<Code>InternalError</Code>",
         "<Message>We encountered an internal error. Please try again.</Message>",
         "<RequestId>656c76696e6727732072657175657374</RequestId>",
         "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>",
        "</Error>"
    ]
}
```

Where you can define the expected response status, header and response body. If the {Key}.json is not found from file system, it will load the `default.json`.

The server validates that all specified headers in the "request_headers" field are present in the incoming request. If any required header is missing, the request will fail. These headers will not be part of the Response headers.
If the "delay" field is present, the response will be delayed by X seconds.

### GetObject Response

By default, the GetObject response will read from ./{OperationName}/{Key}.json for the status and headers. But the body will be generated to match the range in the request.

To proper handle ranged GetObject, you will need to modify the mock server code. Check function `handle_get_object` for details.