Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eladcon committed Jun 13, 2024
1 parent 5a35970 commit 1be0184
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "wingsdk"
version = "0.0.2"
version = "0.0.3"
description = "Wing SDK in Python"
authors = [{name = "Elad Cohen", email = "[email protected]"}]
readme = "README.md"
Expand Down
14 changes: 13 additions & 1 deletion wing.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def lifted(id: str):
if id in jsonValue:
return create_client(jsonValue[id])

print(f"Client with id={id} not found")
raise Exception(f"Client not found (id={id}).")

def create_client(idValue: dict):
Expand All @@ -215,12 +216,18 @@ def create_client(idValue: dict):
return SESEmailService_aws(idValue["props"])
elif target == "sim":
return SESEmailService_sim(create_client(idValue["children"]["store"]))


def _set_context(event):
context = json.loads(event["context"])
for key, value in context.items():
os.environ[key] = value

def from_function_event(event):
target = os.getenv(f"WING_TARGET")
if target == "tf-aws":
return str(event)
elif target == "sim":
_set_context(event)
payload = event["payload"]
return payload if isinstance(payload, str) else json.dumps(payload)
else:
Expand All @@ -231,6 +238,7 @@ def from_topic_event(event):
if target == "tf-aws":
return [event["Records"][0]["Sns"]["Message"]]
elif target == "sim":
_set_context(event)
return [str(event["payload"])]
else:
raise Exception(f"Unsupported target: {target}")
Expand All @@ -240,6 +248,7 @@ def from_queue_event(event):
if target == "tf-aws":
return [event["Records"][0]["body"]]
elif target == "sim":
_set_context(event)
return [str(event["payload"])]
else:
raise Exception(f"Unsupported target: {target}")
Expand All @@ -258,6 +267,7 @@ def from_bucket_event(event):
bucket_event.type = os.getenv("WING_BUCKET_EVENT")
return [bucket_event]
elif target == "sim":
_set_context(event)
data = event["payload"]
bucket_event = BucketEvent()
bucket_event.key = data["key"]
Expand Down Expand Up @@ -287,6 +297,7 @@ def from_api_event(event):
}
return req
elif target == "sim":
_set_context(event)
data = event["payload"]
req: ApiRequest = {
'method': data["method"],
Expand Down Expand Up @@ -333,6 +344,7 @@ def api_to_lambda(event: dict[str, Any]):
if target == "tf-aws":
return req
elif target == "sim":
_set_context(event)
data = event["payload"]
body = data["body"]
req = {
Expand Down

0 comments on commit 1be0184

Please sign in to comment.