-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(general): Used jsonpath to update vertex attributes (#6852)
* Added calculation of Fn::Sub in case of using Pseudo Parameter as it is a default one from cloudformation and shouldn't exist in the code * Only do sub in case of pseudo parameter usage * added example * Middle of debugging, currently works * Refactored update attribtue code to a method for jsonpath specifically * Created test based on example * Do not return jsonpath key from inner function * Check key in attribtues before accessing it * Removed mistakenly changed calculation of end vertices * Removed tmp example files * Added try-except to handle errors when parsing the jsonpath attribute * Removed re module usage to improve performance * Implemented cache for jsonpath to improve performance * Updated threshold on linux machine performance from 10 to 11 * Removed bad comment:
- Loading branch information
Showing
7 changed files
with
256 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...loudformation/graph/graph_runner/external_graph_checks/complex_jsonpath_if_condition.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
metadata: | ||
id: "complex_jsonpath_if_condition" | ||
name: "cfn-if" | ||
severity: "high" | ||
guidelines: "MGUIFDE" | ||
category: "general" | ||
scope: | ||
provider: "aws" | ||
definition: | ||
and: | ||
- cond_type: "attribute" | ||
resource_types: | ||
- "AWS::ECS::TaskDefinition" | ||
attribute: "ContainerDefinitions[?([email protected])]" | ||
operator: "jsonpath_not_exists" |
127 changes: 127 additions & 0 deletions
127
tests/cloudformation/graph/graph_runner/resources/complex_jsonpath_if_condition/example.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
Description: This template deploys microservice to a ECS cluster with Fargate. | ||
Parameters: | ||
AppName: | ||
Description: Tech stack name to use when constructing resource names | ||
Type: String | ||
|
||
ApplicationIAMRole: | ||
Description: "IAM Role for the application" | ||
Type: String | ||
|
||
CloudformationBucket: | ||
Type: String | ||
|
||
DockerImage: | ||
Description: Placeholder image for the primeval task definition | ||
Type: String | ||
Default: moodysanalytics.jfrog.io/ | ||
|
||
env: | ||
Type: String | ||
Default: dev | ||
|
||
version: | ||
Type: String | ||
|
||
AWSSSMAgentDockerImage: | ||
Description: Image for AWS Amazon SSM Agent | ||
Type: String | ||
Default: "amazon-ssm-agent" | ||
|
||
ApplicationPort: | ||
Type: String | ||
Default: "80" | ||
|
||
TaskDefMemory: | ||
Type: String | ||
Default: 2048 | ||
|
||
TaskDefCPU: | ||
Type: String | ||
Default: 1024 | ||
|
||
Conditions: | ||
IsTrueCondition: !And | ||
- !Equals [ !Ref AWSSSMAgentDockerImage, "amazon-ssm-agent" ] | ||
- !Equals [ !Ref ApplicationPort, "80" ] | ||
IsFalseCondition: !And | ||
- !Equals [ !Ref AWSSSMAgentDockerImage, "amazon-ssm-agent" ] | ||
- !Equals [ !Ref ApplicationPort, "81" ] | ||
|
||
Resources: | ||
PassingExample: | ||
Type: AWS::ECS::TaskDefinition | ||
Properties: | ||
Family: !Ref AppName | ||
ContainerDefinitions: | ||
- !If | ||
- IsTrueCondition | ||
- Name: amazon-ssm-agent | ||
Image: !Ref AWSSSMAgentDockerImage | ||
Essential: true | ||
Cpu: 0 | ||
EntryPoint: [ ] | ||
Command: [ | ||
"/bin/bash", | ||
"-c", | ||
"echo hello" | ||
] | ||
Environment: | ||
- Name: MANAGED_INSTANCE_ROLE_NAME | ||
Value: lobadmin-managed-fis-ssm-instance | ||
LogConfiguration: | ||
LogDriver: awslogs | ||
Options: | ||
awslogs-group: !Ref SSMLogGroup | ||
awslogs-region: !Ref AWS::Region | ||
awslogs-stream-prefix: !Ref AppName | ||
- !Ref "AWS::NoValue" | ||
Cpu: !Ref TaskDefCPU | ||
Memory: !Ref TaskDefMemory | ||
ExecutionRoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/${ApplicationIAMRole} | ||
TaskRoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/lobadmin-managed-ecs-instance-default | ||
NetworkMode: awsvpc | ||
RequiresCompatibilities: | ||
- FARGATE | ||
Tags: | ||
- Key: application_name | ||
Value: !Ref AppName | ||
|
||
FailingExample: | ||
Type: AWS::ECS::TaskDefinition | ||
Properties: | ||
Family: !Ref AppName | ||
ContainerDefinitions: | ||
- !If | ||
- IsFalseCondition | ||
- Name: amazon-ssm-agent | ||
Image: !Ref AWSSSMAgentDockerImage | ||
Essential: true | ||
Cpu: 0 | ||
EntryPoint: [ ] | ||
Command: [ | ||
"/bin/bash", | ||
"-c", | ||
"echo hello" | ||
] | ||
Environment: | ||
- Name: MANAGED_INSTANCE_ROLE_NAME | ||
Value: lobadmin-managed-fis-ssm-instance | ||
LogConfiguration: | ||
LogDriver: awslogs | ||
Options: | ||
awslogs-group: !Ref SSMLogGroup | ||
awslogs-region: !Ref AWS::Region | ||
awslogs-stream-prefix: !Ref AppName | ||
- !Ref "AWS::NoValue" | ||
Cpu: !Ref TaskDefCPU | ||
Memory: !Ref TaskDefMemory | ||
ExecutionRoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/${ApplicationIAMRole} | ||
TaskRoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/lobadmin-managed-ecs-instance-default | ||
NetworkMode: awsvpc | ||
RequiresCompatibilities: | ||
- FARGATE | ||
Tags: | ||
- Key: application_name | ||
Value: !Ref AppName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters