Skip to content

Commit

Permalink
[aws][fix] Aws lambda function can not be read (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Jan 24, 2023
1 parent 5388d48 commit 3038096
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
22 changes: 11 additions & 11 deletions plugins/aws/resoto_plugin_aws/resource/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class AwsLambdaPolicyStatement:
"resource": S("Resource"),
"condition": S("Condition") >> Bend(AwsLambdaCondition.mapping),
}
sid: str = field(default=None)
effect: str = field(default=None)
principal: Dict[str, str] = field(default=None)
action: str = field(default=None)
resource: str = field(default=None)
condition: AwsLambdaCondition = field(default=None)
sid: Optional[str] = field(default=None)
effect: Optional[str] = field(default=None)
principal: Optional[Dict[str, str]] = field(default=None)
action: Optional[str] = field(default=None)
resource: Optional[str] = field(default=None)
condition: Optional[AwsLambdaCondition] = field(default=None)


@define(eq=False, slots=False)
Expand All @@ -54,9 +54,9 @@ class AwsLambdaPolicyDetails:
"policy_version": S("Version"),
"policy_statement": S("Statement") >> ForallBend(AwsLambdaPolicyStatement.mapping),
}
id: str = field(default=None)
id: Optional[str] = field(default=None)
policy_version: Optional[str] = field(default=None)
policy_statement: List[AwsLambdaPolicyStatement] = field(factory=list)
policy_statement: Optional[List[AwsLambdaPolicyStatement]] = field(default=None)


@define(eq=False, slots=False)
Expand All @@ -66,7 +66,7 @@ class AwsLambdaGetPolicyResponse:
"policy": S("Policy") >> F(json.loads) >> Bend(AwsLambdaPolicyDetails.mapping),
"policy_revision_id": S("RevisionId"),
}
policy: AwsLambdaPolicyDetails = field(default=None)
policy: Optional[AwsLambdaPolicyDetails] = field(default=None)
policy_revision_id: Optional[str] = field(default=None)


Expand Down Expand Up @@ -120,8 +120,8 @@ class AwsLambdaImageConfig:
"command": S("Command", default=[]),
"working_directory": S("WorkingDirectory"),
}
entry_point: List[str] = field(factory=list)
command: List[str] = field(factory=list)
entry_point: Optional[List[str]] = field(default=None)
command: Optional[List[str]] = field(default=None)
working_directory: Optional[str] = field(default=None)


Expand Down
24 changes: 23 additions & 1 deletion plugins/aws/test/resources/lambda_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
from resoto_plugin_aws.resource.lambda_ import AwsLambdaFunction
from resoto_plugin_aws.resource.lambda_ import AwsLambdaFunction, AwsLambdaGetPolicyResponse
from resotolib.json import from_json
from test.resources import round_trip_for
from typing import Any, cast
from types import SimpleNamespace
from resoto_plugin_aws.aws_client import AwsClient


def test_regression_lamda_get_policy() -> None:
value_to_read = {
"policy": {
"id": "default",
"policy_version": "2012-10-17",
"policy_statement": [
{
"sid": "StackSet-AWSControlTower-ALCD-LZ-resource-owner-tag",
"effect": "Allow",
"principal": {"Service": "events.amazonaws.com"},
"action": "lambda:InvokeFunction",
"resource": "arn:aws:lambda:eu-central-1:test:function:aws-controltower-owner-tagging-func",
"condition": None,
}
],
},
"policy_revision_id": "b3f179eb-569b-4ea2-8ec4-4324609b0694",
}
from_json(value_to_read, AwsLambdaGetPolicyResponse)


def test_lambda() -> None:
first, graph = round_trip_for(AwsLambdaFunction)
assert len(graph.resources_of(AwsLambdaFunction)) == 2
Expand Down

0 comments on commit 3038096

Please sign in to comment.