-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_documentation.txt
191 lines (144 loc) · 6.79 KB
/
api_documentation.txt
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
The API supports the following endpoints:
/add: Add email addresses
/remove: Remove email addresses
/clear: Remove all email addresses
/replace: Remove and add (in this order) email addresses
/replace_all: Remove all email addresses and add new ones
Every endpoint expects two POST parameters:
data: A JSON string
signature: A hash of the JSON string together with a shared secret
The hash is the SHA512-Hash of the concatenation of the JSON string
'data' shared secret, represented as hexadecimals. In Python:
sha512(data + secret).hexdigest()
The JSON objekt must have the following structure according to the
corresponding endpoint:
/add: {"mailinglist": "…", "addresses": […]}
/remove {"mailinglist": "…", "addresses": […]}
/clear {"mailinglist": "…"}
/replace {"mailinglist": "…", "add": […], "remove": […]}
/replace_all {"mailinglist": "…", "addresses": […]}
The API returns one of the following status codes:
200 OK: Ok, but the addition or removal of some or
all addresses may have failed
400 Bad Request: Invalid POST data or JSON object
403 Forbidden: Invalid signature
404 Not Found: Invalid URL
405 Method Not Allowed: Not a POST request
422 Unprocessable Entity: Error connecting to the internal mailman API
500 Internal Server Error: Unexpected error
Except for status 500, the response is always a JSON object that always
contains a field "status" which might eiter be "ok" or "failed". If the
status is /not/ 200, the status is always "failed". (The reverse does not
hold true.)
{"status": "failed", reason: "<Begründung>", …}
If the status is 200, the fields "succeded" and "failed" are present:
{"status": "ok", "failed": […], "succeded": […]} ODER
{"status": "failed", "reason": "<Bgr.>", "failed": […], "succeded": […]}
Especially, if the list "failed" is non-empty and "succeded" is empty,
the status will be "failed" and the "reason" will be
"All operations failed.":
{"status": "failed", "reason": "All operations failed.", "failed": […],
"succeded": []}
This is the general schema of a request object:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Request",
"type": "object",
"properties": {
"mailinglist": {
"type": "string"
},
"addresses": {
"type": "array",
"items": {
"type": "string"
}
},
"add": {
"type": "array",
"items": {
"type": "string"
}
},
"remove": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["mailinglist"]
}
This is the general schema of a response object:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Response",
"type": "object",
"properties": {
"status": {
"type": "string"
},
"reason": {
"type": "string"
},
"succeded": {
"type": "array",
"items": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
},
"required": ["address"]
}
},
"failed": {
"type": "array",
"items": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"reason": {
"type": "string"
},
},
"required": ["address", "reason"]
}
},
},
"required": ["status"]
}
Some examples using 'curl' (not showing the valid signature):
Successful adding (Status 200):
$ curl localhost:8080/add -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"failed": [], "succeded": [{"address": "[email protected]"}], "status": "ok"}
Successful removal (Status 200):
$ curl localhost:8080/remove -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"failed": [], "succeded": [{"address": "[email protected]"}], "status": "ok"}
Failed adding (Status 200):
$ curl localhost:8080/add -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"failed": [{"address": "[email protected]", "reason": "HTTP Error 409: b'Member already subscribed'"}], "succeded": [], "status": "failed", "reason": "All operations failed."}
Failed removal (Status 200):
$ curl localhost:8080/remove -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"failed": [{"address": "[email protected]", "reason": "[email protected] is not a member address of [email protected]"}], "succeded": [], "status": "failed", "reason": "All operations failed."}
Partial error (adding) (Status 200):
$ curl localhost:8080/add -d data='{"mailinglist":"[email protected]","addresses":["[email protected]", "[email protected]"]}' -d signature=x
{"failed": [{"address": "[email protected]", "reason": "HTTP Error 409: b'Member already subscribed'"}], "succeded": [{"address": "[email protected]"}], "status": "ok"}
Partial error (replacing) (Status 200):
$ curl localhost:8080/replace -d data='{"mailinglist":"[email protected]","add":["[email protected]", "[email protected]"],"remove":["[email protected]","[email protected]"]}' -d signature=x
{"failed": [{"address": "[email protected]", "reason": "[email protected] is not a member address of [email protected]"}, {"address": "[email protected]", "reason": "HTTP Error 409: b'Member already subscribed'"}], "succeded": [{"address": "[email protected]"}, {"address": "[email protected]"}], "status": "ok"}
Wrong data format (Status 400):
$ curl localhost:8080/add -d blub='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"reason": "Data error: b'data'", "status": "failed"}
Mailman not running / API not reachable (Status 422):
$ curl localhost:8080/add -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"status": "failed", "reason": "Mailman error ([email protected]): Could not connect to Mailman API"}
Signature invalid (Status 403):
$ curl localhost:8080/add -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
{"reason": "Could not verify authentication", "status": "failed"}
Robert broke everything! (Status 500):
$ curl localhost:8080/add -d data='{"mailinglist":"[email protected]","addresses":["[email protected]"]}' -d signature=x
A server error occurred. Please contact the administrator.