Skip to content

Commit

Permalink
Adds support for excluding rules. Version 0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Lorenc committed Jan 26, 2020
1 parent 682a321 commit 28e947b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 25 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ It contains rules for checking whether:

- [X] Support json specs
- [ ] Ignore path-params if `http_proxy` integration type used
- [ ] Add option to disable rules via CLI
- [ ] Add option to disable rules for specific paths
- [X] Add option to disable rules via CLI
- [X] Add warning threshold to return with status code 0 if limit not exceeded
- [X] Fix flake8 violations
- [X] Add a license
Expand All @@ -40,9 +39,10 @@ pip install aws-openapi-lint
`$ aws-openapi-lint path/to/spec.yml`

```
usage: aws-openapi-lint [-h] [--treat-errors-as-warnings]
[--warning-threshold WARNING_THRESHOLD]
lint_file
usage: main.py [-h] [--treat-errors-as-warnings]
[--warning-threshold WARNING_THRESHOLD]
[--exclude-rules EXCLUDE_RULES]
lint_file
Lint OpenAPI specifications based on AWS API Gateway.
Expand All @@ -57,7 +57,7 @@ optional arguments:
--warning-threshold WARNING_THRESHOLD
Warning threshold which when surpassed renders exit
code to become 1)
--exclude-rules EXCLUDE_RULES
Excluded rules separated by comma.
```

The program terminates with exit code equal to the amount of violations found.
28 changes: 19 additions & 9 deletions aws_openapi_lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,35 @@ def parse_arguments():
help='Treats errors as warnings (exit code will be 0 unless warning threshold is specified')
parser.add_argument('--warning-threshold', default=-1, type=int, help='Warning threshold which when surpassed '
'renders exit code to become 1)')
parser.add_argument('--exclude-rules', default="", type=str, help='Excluded rules separated by comma.')
return parser.parse_args()


def cli(args=None, input_format="yaml", program_name="yq"):
def cli(args=None, input_format="yaml", program_name="aws-openapi-lint"):
if len(sys.argv) == 1:
print('File path not passed as command line argument.')
exit(1)

args = parse_arguments()

supported_rules = [
ConflictingHttpVerbsRule(),
MissingAmazonIntegrationRule(),
PathParamNotMappedRule(),
AuthorizerOnOptionsRule(),
AuthorizerReferencedButMissingRule(),
NoCORSPresentRule(),
CORSNotEnoughVerbsRule(),
CORSInconsistentHeadersRule()
]

exclude_rules = args.exclude_rules.split(",")
effective_rules = filter(lambda r: r.rule_name not in exclude_rules, supported_rules)

rule_validator = RuleValidator(args.lint_file)
rule_validator.add_rule(ConflictingHttpVerbsRule())
rule_validator.add_rule(MissingAmazonIntegrationRule())
rule_validator.add_rule(PathParamNotMappedRule())
rule_validator.add_rule(AuthorizerOnOptionsRule())
rule_validator.add_rule(AuthorizerReferencedButMissingRule())
rule_validator.add_rule(NoCORSPresentRule())
rule_validator.add_rule(CORSNotEnoughVerbsRule())
rule_validator.add_rule(CORSInconsistentHeadersRule())

for rule in effective_rules:
rule_validator.add_rule(rule)

violations = rule_validator.validate()

Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/AuthorizerOnOptionsRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class AuthorizerOnOptionsRule:
def __init__(self):
pass
self.rule_name = 'authorizer_on_options'

def validate(self, spec):
violations = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class AuthorizerReferencedButMissingRule:
def __init__(self):
pass
self.rule_name = 'authorizer_referenced_but_missing'

def validate(self, spec):
violations = []
Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/CORSInconsistentHeadersRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class CORSInconsistentHeadersRule:
def __init__(self):
pass
self.rule_name = 'options_cors_incosistent_headers'

def validate(self, spec):
violations = []
Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/CORSNotEnoughVerbsRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class CORSNotEnoughVerbsRule:
def __init__(self):
pass
self.rule_name = 'options_cors_not_enough_verbs'

def validate(self, spec):
violations = []
Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/ConflictingHttpVerbsRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ConflictingHttpVerbsRule:
def __init__(self):
pass
self.rule_name = 'conflicting_http_verbs'

def validate(self, spec):
violations = []
Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/MissingAmazonIntegrationRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MissingAmazonIntegrationRule:
def __init__(self):
pass
self.rule_name = 'missing_amazon_integration'

def validate(self, spec):
violations = []
Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/NoCORSPresentRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class NoCORSPresentRule:
def __init__(self):
pass
self.rule_name = 'options_no_cors_present'

def validate(self, spec):
violations = []
Expand Down
2 changes: 1 addition & 1 deletion aws_openapi_lint/rules/PathParamNotMappedRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class PathParamNotMappedRule:
def __init__(self):
pass
self.rule_name = 'path_parameter_not_mapped'

def validate(self, spec):
violations = []
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from aws_openapi_lint import cli

cli()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='AWS-OpenAPI-Lint',
version='0.1.6',
version='0.1.7',
url='https://github.com/evilmint/aws-openapi-lint',
download_url='https://github.com/evilmint/aws-openapi-lint/archive/0.1.6.tar.gz',
description='AWS API Gateway OpenAPI spec linter',
Expand Down

0 comments on commit 28e947b

Please sign in to comment.