-
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.
feat(serverless): Serverless graph vertices (#6894)
* add vertices implementation
- Loading branch information
1 parent
fad7d8f
commit f90934f
Showing
10 changed files
with
370 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
|
||
def build_definitions_context(definitions: dict[str, dict[str, Any]], definitions_raw: dict[str, list[tuple[int, str]]] | ||
) -> dict[str, dict[str, Any]]: | ||
return {} | ||
|
||
|
||
def add_resource_to_definitions_context(definitions_context: dict[str, dict[str, Any]], resource_key: str, | ||
resource_attributes: dict[str, Any], definition_attribute: str, | ||
definitions_raw: dict[str, Any], file_path: str) -> None: | ||
pass |
12 changes: 0 additions & 12 deletions
12
checkov/serverless/graph_builder/graph_components/block_types.py
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from pathlib import Path | ||
from typing import Any, TYPE_CHECKING | ||
|
||
from checkov.serverless.utils import ServerlessElements | ||
|
||
if TYPE_CHECKING: | ||
from checkov.serverless.graph_builder.graph_components.blocks import ServerlessBlock | ||
|
||
|
||
def convert_graph_vertices_to_definitions(vertices: list[ServerlessBlock], root_folder: str | Path | None) \ | ||
-> tuple[dict[str, dict[str, Any]], dict[str, dict[str, Any]]]: | ||
serverless_definitions: dict[str, dict[str, Any]] = {} | ||
breadcrumbs: dict[str, dict[str, Any]] = {} | ||
for vertex in vertices: | ||
block_path = vertex.path | ||
element_name = vertex.name.split('.')[-1] | ||
# Plugins section is formatted as a list | ||
if vertex.block_type == ServerlessElements.PLUGINS: | ||
serverless_definitions.setdefault(block_path, {}).setdefault(vertex.block_type, []).append(element_name) | ||
|
||
# If there is a ket named 'value' in the config it means that | ||
# this vertex's config contains only a single string | ||
elif 'value' in vertex.config: | ||
# If the vertex is provider or service and it only contains a string the section should look like: | ||
# provider: <value> | ||
# service: <value> | ||
if element_name == ServerlessElements.PROVIDER or element_name == ServerlessElements.SERVICE: | ||
serverless_definitions.setdefault(block_path, {})[vertex.block_type] = vertex.config['value'] | ||
|
||
# Otherwise it's a vertex of a specific nested attribute and need to include the full path | ||
# Examples: | ||
# provider: | ||
# runtime: nodejs20.x | ||
# custom: | ||
# myCustomVar: value | ||
else: | ||
serverless_definitions.setdefault(block_path, {}).setdefault(vertex.block_type, {})[element_name] = \ | ||
vertex.config['value'] | ||
|
||
# Otherwise, the vertex config is a dict | ||
else: | ||
serverless_definitions.setdefault(block_path, {}).setdefault(vertex.block_type, {})[ | ||
element_name] = vertex.config | ||
|
||
if vertex.breadcrumbs: | ||
relative_block_path = f"/{os.path.relpath(block_path, root_folder)}" | ||
add_breadcrumbs(vertex, breadcrumbs, relative_block_path) | ||
return serverless_definitions, breadcrumbs | ||
|
||
|
||
def add_breadcrumbs(vertex: ServerlessBlock, breadcrumbs: dict[str, dict[str, Any]], relative_block_path: str) -> None: | ||
breadcrumbs.setdefault(relative_block_path, {})[vertex.name] = vertex.breadcrumbs |
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
Empty file.
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,62 @@ | ||
service: acme-service | ||
|
||
frameworkVersion: "^2.30.0" | ||
|
||
plugins: | ||
- serverless-vpc-discovery | ||
|
||
custom: | ||
resources: ${file(./serverless.${opt:stage}.yml)} | ||
vpc: | ||
vpcName: acme-vpc | ||
subnetNames: | ||
- private-subnet-a | ||
- private-subnet-b | ||
securityGroupNames: | ||
- allow_out_to_vpc_endpoints | ||
- lambda_sg | ||
provider: | ||
region: us-east-1 | ||
name: aws | ||
runtime: python3.7 | ||
tracing: | ||
lambda: true | ||
deploymentBucket: ${self:custom.resources.deploymentBucket} | ||
environment: ${self:custom.resources.environment} | ||
iamManagedPolicies: | ||
- arn:aws:iam::aws:policy/ReadOnlyAccess | ||
iamRoleStatements: ${self:custom.resources.iamRoleStatements} | ||
ecr: | ||
images: | ||
base: | ||
path: ../../ | ||
file: ./path/to/Dockerfile | ||
|
||
functions: | ||
acmeFunc: | ||
image: base | ||
timeout: 120 | ||
memorySize: 3000 | ||
environment: | ||
EFS_MOUNT_PATH: ${self:custom.localMountPath} | ||
fileSystemConfig: | ||
localMountPath: ${self:custom.localMountPath} | ||
arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.resources.efsAccessPoint}' | ||
events: | ||
- sqs: | ||
arn: arn:aws:sqs:#{AWS::Region}:#{AWS::AccountId}:job_queue | ||
batchSize: 10 | ||
maximumBatchingWindow: 0 | ||
acmeFunc2: | ||
image: base | ||
environment: | ||
EFS_MOUNT_PATH: ${self:custom.localMountPath} | ||
CLEAN_UP_BEFORE_PROCESS: 'true' | ||
timeout: 900 | ||
memorySize: 9000 | ||
fileSystemConfig: | ||
localMountPath: ${self:custom.localMountPath} | ||
arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.resources.efsAccessPoint}' | ||
|
||
resources: | ||
Resources: ${file(./serverless.${opt:stage}.yml)} # just shouldn't raise an exception |
Oops, something went wrong.