-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.py
More file actions
40 lines (30 loc) · 980 Bytes
/
handler.py
File metadata and controls
40 lines (30 loc) · 980 Bytes
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
import json
from smaug import counter
def get(event, *args, **kwargs):
config = event.get('config')
return {
'statusCode': 200,
'body': json.dumps(counter.get(config)),
}
def increment(event, *args, **kwargs):
config = event.get('config')
n = event.get('n') or 1
return {
'statusCode': 200,
'body': json.dumps({'incremented': counter.incr(config, n)}),
}
if __name__ == '__main__':
config = {
'id': 'test-api-call',
'whitelabel': 4,
'customer': 789,
'minute': 10,
}
incremented = counter.incr(config, n=3)
print(config, f'\n\tincremented: {incremented}')
# negative value to only log without counter for rate limit
incremented = counter.incr(config, n=-10)
print(config, f'\n\tincremented: {incremented}')
config = {'id': 'test-api-call-unlimited'}
incremented = counter.incr(config, n=1)
print(config, f'\n\tincremented: {incremented}')