Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 809877d

Browse files
author
bweigel
committed
initial commit
1 parent 2da0bb6 commit 809877d

File tree

11 files changed

+621
-0
lines changed

11 files changed

+621
-0
lines changed

.gitignore

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### VirtualEnv template
3+
# Virtualenv
4+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
5+
.Python
6+
[Bb]in
7+
[Ii]nclude
8+
[Ll]ib
9+
[Ll]ib64
10+
[Ll]ocal
11+
[Ss]cripts
12+
pyvenv.cfg
13+
.venv
14+
pip-selfcheck.json
15+
### Python template
16+
# Byte-compiled / optimized / DLL files
17+
__pycache__/
18+
*.py[cod]
19+
*$py.class
20+
21+
# C extensions
22+
*.so
23+
24+
# Distribution / packaging
25+
build/
26+
develop-eggs/
27+
dist/
28+
downloads/
29+
eggs/
30+
.eggs/
31+
lib/
32+
lib64/
33+
parts/
34+
sdist/
35+
var/
36+
wheels/
37+
*.egg-info/
38+
.installed.cfg
39+
*.egg
40+
MANIFEST
41+
42+
# PyInstaller
43+
# Usually these files are written by a python script from a template
44+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
45+
*.manifest
46+
*.spec
47+
48+
# Installer logs
49+
pip-log.txt
50+
pip-delete-this-directory.txt
51+
52+
# Unit test / coverage reports
53+
htmlcov/
54+
.tox/
55+
.coverage
56+
.coverage.*
57+
.cache
58+
nosetests.xml
59+
coverage.xml
60+
*.cover
61+
.hypothesis/
62+
63+
# Translations
64+
*.mo
65+
*.pot
66+
67+
# Django stuff:
68+
*.log
69+
.static_storage/
70+
.media/
71+
local_settings.py
72+
73+
# Flask stuff:
74+
instance/
75+
.webassets-cache
76+
77+
# Scrapy stuff:
78+
.scrapy
79+
80+
# Sphinx documentation
81+
docs/_build/
82+
83+
# PyBuilder
84+
target/
85+
86+
# Jupyter Notebook
87+
.ipynb_checkpoints
88+
89+
# pyenv
90+
.python-version
91+
92+
# celery beat schedule file
93+
celerybeat-schedule
94+
95+
# SageMath parsed files
96+
*.sage.py
97+
98+
# Environments
99+
.env
100+
env/
101+
venv/
102+
ENV/
103+
env.bak/
104+
venv.bak/
105+
106+
# Spyder project settings
107+
.spyderproject
108+
.spyproject
109+
110+
# Rope project settings
111+
.ropeproject
112+
113+
# mkdocs documentation
114+
/site
115+
116+
# mypy
117+
.mypy_cache/
118+
/LaWip.egg-info/
119+
120+
121+
.idea/

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.1, 2018-03-11 -- initial release

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
===========
2+
LaWip
3+
===========
4+
5+
LaWip provides data-classes for AWS lambda events::
6+
7+
#!/usr/bin/env python
8+
9+
from towelstuff import location
10+
from towelstuff import utils
11+
12+
if utils.has_towel():
13+
print "Your towel is located:", location.where_is_my_towel()
14+
15+
16+
A Section
17+
=========
18+
19+
Lists look like this:
20+
21+
* First
22+
23+
* Second. Can be multiple lines
24+
but must be indented properly.
25+
26+
A Sub-Section
27+
-------------
28+
29+
Numbered lists look like you'd expect:
30+
31+
1. hi there
32+
33+
2. must be going
34+
35+
Urls are http://like.this and links can be
36+
written `like this <http://www.example.com/foo/bar>`_.

lawip/__init__.py

Whitespace-only changes.

lawip/http_proxy_event.py

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
class Identity:
2+
def __init__(self,
3+
api_key: str,
4+
user_arn: str,
5+
cognito_auth_type: str,
6+
caller: str,
7+
user_agent: str,
8+
user: str,
9+
cognito_identity_pool_id: str,
10+
cognito_auth_provider: str,
11+
source_ip: str,
12+
account_id: str,
13+
cognito_identity_id: str):
14+
self._api_key = api_key
15+
self._user_arn = user_arn
16+
self._cognito_auth_type = cognito_auth_type
17+
self._caller = caller
18+
self._user_agent = user_agent
19+
self._user = user
20+
self._cognito_identity_pool_id = cognito_identity_pool_id
21+
self._cognito_auth_provider = cognito_auth_provider
22+
self._source_ip = source_ip
23+
self._account_id = account_id
24+
self._cognito_identity_id = cognito_identity_id
25+
26+
@classmethod
27+
def from_json(cls, identity):
28+
return cls(identity["apiKey"],
29+
identity["userArn"],
30+
identity["cognitoAuthenticationType"],
31+
identity["caller"],
32+
identity["userAgent"],
33+
identity["user"],
34+
identity["cognitoIdentityPoolId"],
35+
identity["cognitoAuthenticationProvider"],
36+
identity["sourceIp"],
37+
identity["accountId"],
38+
identity["cognitoIdentityId"])
39+
40+
41+
class RequestContext:
42+
def __init__(self, resource_id: str,
43+
api_id: str,
44+
resource_path: str,
45+
http_method: str,
46+
request_id: str,
47+
account_id: str,
48+
identity: Identity,
49+
stage: str):
50+
self._resource_id = resource_id
51+
self._api_id = api_id
52+
self._resource_path = resource_path
53+
self._http_method = http_method
54+
self._request_id = request_id
55+
self._account_id = account_id
56+
self._identity = identity
57+
self._stage = stage
58+
59+
@classmethod
60+
def from_json(cls, context):
61+
return cls(context["resourceId"],
62+
context["apiId"],
63+
context["resourcePath"],
64+
context["httpMethod"],
65+
context["requestId"],
66+
context["accountId"],
67+
context["identity"],
68+
context["stage"])
69+
70+
@property
71+
def resource_id(self):
72+
return self._resource_id
73+
74+
@property
75+
def resource_path(self):
76+
return self._resource_path
77+
78+
@property
79+
def api_id(self):
80+
return self._api_id
81+
82+
@property
83+
def http_method(self):
84+
return self._http_method
85+
86+
@property
87+
def request_id(self):
88+
return self._request_id
89+
90+
@property
91+
def account_id(self):
92+
return self._account_id
93+
94+
@property
95+
def identity(self):
96+
return self._identity
97+
98+
@property
99+
def stage(self):
100+
return self._stage
101+
102+
103+
class ApiGwProxyEvent:
104+
def __init__(self, body: str,
105+
resource: str,
106+
request_context: RequestContext,
107+
query_string_parameters: dict,
108+
headers: dict,
109+
path_parameters: dict,
110+
http_method: str,
111+
stage_variables: dict,
112+
path: str):
113+
self._body = body
114+
self._resource = resource
115+
self._request_context = request_context
116+
self._query_string_parameters = query_string_parameters
117+
self._headers = headers
118+
self._path_parameters = path_parameters
119+
self._http_method = http_method
120+
self._stage_variables = stage_variables
121+
self._path = path
122+
123+
@classmethod
124+
def from_event(cls, event):
125+
return cls(event["body"],
126+
event["resource"],
127+
RequestContext.from_json(event["requestContext"]),
128+
event["queryStringParameters"],
129+
event["headers"],
130+
event["pathParameters"],
131+
event["httpMethod"],
132+
event["stageVariables"],
133+
event["path"])
134+
135+
@property
136+
def body(self) -> str:
137+
return self._body
138+
139+
@property
140+
def resource(self) -> str:
141+
return self._resource
142+
143+
@property
144+
def request_context(self) -> RequestContext:
145+
return self._request_context
146+
147+
@property
148+
def query_string_parameters(self) -> dict:
149+
return self._query_string_parameters
150+
151+
@property
152+
def headers(self) -> dict:
153+
return self._headers
154+
155+
@property
156+
def path_parameters(self) -> dict:
157+
return self._path_parameters
158+
159+
@property
160+
def http_method(self) -> str:
161+
return self._http_method
162+
163+
@property
164+
def stage_variables(self) -> dict:
165+
return self._stage_variables
166+
167+
@property
168+
def path(self) -> str:
169+
return self._path

0 commit comments

Comments
 (0)