Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eladcon committed Jun 18, 2024
1 parent 808a22a commit e50d421
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
14 changes: 13 additions & 1 deletion python/function.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ bring ses;
bring fs;
bring "./lib.w" as python;

class CustomLiftable impl python.ILiftable {
pub liftData(): Json {
return {
"info": "CustomData",
};
}
}

let table = new dynamodb.Table(
attributes: [
{
Expand Down Expand Up @@ -42,6 +50,10 @@ let func = new cloud.Function(new python.InflightFunction(
obj: emailClient,
allow: ["sendEmail"],
},
"custom": {
obj: new CustomLiftable(),
allow: [],
}
},
), { env: { "FOO": "bar" } });

Expand All @@ -51,5 +63,5 @@ new std.Test(inflight () => {
let res = func.invoke("function1");
log("res: {res ?? "null"}");
expect.equal(Json.parse(res!).get("body"), "Hello!");
expect.equal(bucket.get("test.txt"), "Hello, world!function1bardynamoDbValue");
expect.equal(bucket.get("test.txt"), "Hello, world!function1bardynamoDbValueCustomData");
}, timeout: 3m) as "invokes the function";
4 changes: 4 additions & 0 deletions python/lib.w
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ bring "./sim/api_onrequest_inflight.w" as simapi;
bring "./tfaws/inflight.w" as aws;
bring "./tfaws/api_onrequest_inflight.w" as tfawsapi;

pub interface ILiftable {
liftData(): Json;
}

pub class InflightFunction impl cloud.IFunctionHandler {
_inflightType: str;
inner: types.IInflight;
Expand Down
7 changes: 5 additions & 2 deletions python/test-assets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ def handler(event, context):
table = lifted("table")
response = table.get(Key={"id":"test"})
table_value = response["Item"]["body"]

custom = lifted("custom")
custom_data = custom["liftData"]["info"]

bucket = lifted("bucket")
value = bucket.get("test.txt")
bucket.put("test.txt", value + payload + foo_env + table_value)
bucket.put("test.txt", value + payload + foo_env + table_value + custom_data)

return {
"statusCode": 200,
"body": "Hello!"
Expand Down
2 changes: 1 addition & 1 deletion python/test-assets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wingsdk == 0.0.4
wingsdk == 0.0.6
requests
boto3
Faker
Expand Down
9 changes: 9 additions & 0 deletions python/tfaws/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ module.exports.Function = class Function extends Construct {
target: "aws",
props: {},
}
} else if (typeof client.liftData === "function") {
client.onLift(this.dummy, allow);
clients[clientId] = {
type: "@winglibs.python.ILiftable",
target: "aws",
props: {
liftData: client.liftData(),
},
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions python/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ const getLifted = (resource, id) => {
props: {},
}
}
} else if (typeof resource.liftData === "function") {
lifted = {
id,
path: resource.node.path,
handle: makeEnvVarName("LIFT_DATA", resource),
type: "@winglibs.python.ILiftable",
target: "sim",
resource,
props: {
liftData: resource.liftData(),
},
};
}

return lifted;
Expand Down

0 comments on commit e50d421

Please sign in to comment.