Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfnlint v1 compatibility upgrade #192

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
87a93a0
chore: updated gitignore
sliedig Sep 10, 2024
824abc5
chore: minor formatting and spelling mistakes in readme
sliedig Sep 10, 2024
5203a47
chore: minor formatting corrections
sliedig Sep 10, 2024
bfcf93b
chore(ci): testing against supported versions of python
sliedig Sep 10, 2024
f136e70
feat: modified Lambda message to more easily identify the Lambda prop…
sliedig Sep 10, 2024
15228a8
chore: minor refactorings
sliedig Sep 10, 2024
1ccaf82
feat: upgrading cfnlint to version 1.12.4 and min python version to 3…
sliedig Sep 10, 2024
a0059b6
fix: build config
sliedig Sep 10, 2024
92b506b
Removing python 3.6 and 3.7
leandrodamascena Nov 22, 2024
9f4d7d3
Removing python 3.6 and 3.7
leandrodamascena Nov 22, 2024
44e1280
chore(deps): bump setuptools in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
7c0e8b8
chore(deps): bump urllib3 from 1.26.7 to 1.26.19 in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
37b277b
chore(deps-dev): bump certifi in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
4af8bc3
chore(deps-dev): bump future in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
a4af269
chore(deps-dev): bump requests in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
0416acb
chore(deps-dev): bump black in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
9ce8363
chore(deps-dev): bump idna from 3.3 to 3.7 in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
19e637f
chore(deps-dev): bump bandit in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
952ca6a
chore(deps): bump actions/setup-go from 3 to 5
dependabot[bot] Nov 22, 2024
b9a1dbc
chore(deps-dev): bump flake8-bugbear in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
4c4de1e
chore(deps-dev): bump radon from 5.1.0 to 6.0.1 in /cfn-lint-serverless
dependabot[bot] Nov 22, 2024
0565b35
fix: updated python runtime version for templates and docs
sliedig Nov 30, 2024
3000590
fix: python test
sliedig Nov 30, 2024
214dbce
chore(deps): bumping min python version
sliedig Nov 30, 2024
c58e633
chore(ci): updating gh actions
sliedig Nov 30, 2024
f54983f
chore(deps): updating go runtime and dependencies
sliedig Nov 30, 2024
595138c
Merge remote-tracking branch 'upstream/main' into sliedig-patch
sliedig Nov 30, 2024
071417b
chore(deps): bumping cfn-lint
sliedig Nov 30, 2024
8c703d6
chore(deps): update pytest and related dependencies to latest versions
sliedig Nov 30, 2024
6ac0943
fix: resolved issue cause cfnlint E3601 failure
sliedig Dec 1, 2024
94305dc
chore: bump version to 0.3.3 in pyproject.toml
sliedig Dec 1, 2024
47481dc
chore(ci): updating publishing token
sliedig Dec 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@ on:
types:
- published

# Add concurrency to prevent multiple simultaneous runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

jobs:
run_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set release notes tag
run: |
export RELEASE_TAG_VERSION=${{ github.event.release.tag_name }}
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
- name: Check version tags
run: make release-check
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.12'
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.16
go-version: '1.21'
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v2
with:
tflint_version: v0.29.0
tflint_version: v0.50.0
- name: Install dependencies
run: make dev
- name: Run all checks
Expand All @@ -40,32 +45,32 @@ jobs:
needs: run_tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set release notes tag
run: |
export RELEASE_TAG_VERSION=${{ github.event.release.tag_name }}
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.12'
- name: Install dependencies
run: make -C cfn-lint-serverless dev
- name: Upload to PyPi
run: make -C cfn-lint-serverless release
env:
PYPI_USERNAME: __token__
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
PYPI_TOKEN: ${{ secrets.PIPY_TOKEN24 }}

publish_go:
needs: run_tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.16
go-version: '1.21'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
Expand Down
36 changes: 20 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ name: tests

on:
pull_request:
branches:
- main
branches: [main]
push:
branches:
- main
branches: [main]

# Add concurrency to prevent parallel runs on same ref
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
cfn-lint-tests:
strategy:
fail-fast: false
max-parallel: 4
matrix:
python-version: [3.8, 3.9]
os:
- ubuntu-latest
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
FOLDER: cfn-lint-serverless
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: make -C $FOLDER dev
- name: Formatting and Linting
Expand All @@ -38,23 +41,24 @@ jobs:

tflint-tests:
strategy:
fail-fast: false
max-parallel: 4
matrix:
golang-version: [1.14, 1.15, 1.16]
os:
- ubuntu-latest
go-version: ['1.20', '1.21', '1.22']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
FOLDER: tflint-ruleset-aws-serverless
steps:
- uses: actions/checkout@v3
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Install dependencies
run: make -C $FOLDER dev
- name: Formatting and Linting
run: make -C $FOLDER lint
- name: Tests
run: make -C $FOLDER test

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,5 @@ dmypy.json
.prof

# End of https://www.toptal.com/developers/gitignore/api/python,go

cfn-lint-serverless/.idea/**
2 changes: 1 addition & 1 deletion cfn-lint-serverless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Usage

```bash
cfn-lint template.yaml -a cfn_lint_serverless.rules
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for API Gateway resources
"""


import json
import re
from typing import List
Expand Down
1 change: 0 additions & 1 deletion cfn-lint-serverless/cfn_lint_serverless/rules/appsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for AppSync resources
"""


from cfnlint.rules import CloudFormationLintRule, RuleMatch


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for EventBridge resources
"""


from cfnlint.rules import CloudFormationLintRule, RuleMatch


Expand Down
3 changes: 1 addition & 2 deletions cfn-lint-serverless/cfn_lint_serverless/rules/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for Lambda resources
"""


from collections import defaultdict
from typing import Dict, List, Union

Expand All @@ -22,7 +21,7 @@ class LambdaTracingRule(CloudFormationLintRule):
source_url = "https://awslabs.github.io/serverless-rules/rules/lambda/tracing/"
tags = ["lambda"]

_message = "Lambda function {} should have TracingConfig.Mode set to 'Active'."
_message = "Lambda function {} should have Tracing property set to 'Active'."

def match(self, cfn):
"""
Expand Down
1 change: 0 additions & 1 deletion cfn-lint-serverless/cfn_lint_serverless/rules/sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for SNS resources
"""


from cfnlint.rules import CloudFormationLintRule, RuleMatch


Expand Down
1 change: 0 additions & 1 deletion cfn-lint-serverless/cfn_lint_serverless/rules/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for SQS resources
"""


from cfnlint.rules import CloudFormationLintRule, RuleMatch

from ..utils import Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Rules for Step Functions resources
"""


from cfnlint.rules import CloudFormationLintRule, RuleMatch


Expand Down
31 changes: 10 additions & 21 deletions cfn-lint-serverless/cfn_lint_serverless/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Utilities
"""


import re
from typing import List, Tuple, TypeVar, Union

Expand All @@ -20,14 +19,11 @@ class Value:
def __new__(cls, value: Union[None, dict, str]) -> Union[None, TValue]:
"""
Create a new Value object

If the 'value' passed is None, this will return None instead of a class object
"""

return None if value is None else super(Value, cls).__new__(cls)

if value is None:
return None

return super(Value, cls).__new__(cls)

def __init__(self, value: Union[dict, str]):
"""
Expand All @@ -46,7 +42,7 @@ def __init__(self, value: Union[dict, str]):

# Not a dict - return an error here
elif not isinstance(value, dict):
raise ValueError("'value' should be of type str or dict, got '%s'" % type(value))
raise ValueError(f"'value' should be of type str or dict, got '{type(value)}'")

# 'Ref' intrinsic function
elif "Ref" in value:
Expand All @@ -56,11 +52,11 @@ def __init__(self, value: Union[dict, str]):
elif "Fn::GetAtt" in value:
self.id, self.references = self._get_from_getatt(value["Fn::GetAtt"])

# 'Fn::Join' intrisic function
# 'Fn::Join' intrinsic function
elif "Fn::Join" in value:
self.id, self.references = self._get_from_join(value["Fn::Join"])

# 'Fn::Sub' intrisic function
# 'Fn::Sub' intrinsic function
elif "Fn::Sub" in value:
self.id, self.references = self._get_from_sub(value["Fn::Sub"])

Expand Down Expand Up @@ -102,27 +98,20 @@ def _get_from_sub(self, value: Union[str, list]) -> Tuple[str, List[str]]:
Return the name and references from a 'Fn::Sub' intrinsic function
"""

pattern = value
variables = {}

if isinstance(value, list):
pattern = value[0]
# Using Value() here to get nested references
variables = {k: Value(v) for k, v in value[1].items()}
pattern, variables = value[0], {k: Value(v) for k, v in value[1].items()}
else:
pattern, variables = value, {}

references = []

for match in SUB_PATTERN.findall(pattern):
if match in variables:
# Variable with reference(s)
if len(variables[match].references) > 0:
if variables[match].references:
references.extend(variables[match].references)
# Hard-coded variable
else:
# Replace with hard-coded value in value ID
pattern = pattern.replace(f"${{{match}}}", variables[match].id)
# No matching variable
else:
references.append(match)

return (pattern, references)
return pattern, references
Loading
Loading