Skip to content

Commit

Permalink
[Code Quality]: Implementing custom writer, bug fixes, new integratio…
Browse files Browse the repository at this point in the history
…n test framework, and adding initial tests for all commands (#325)

* Origin/custom writer (#319)

* Added build targets to release workflow

* Added build targets to release workflow

* Moved TARGETS env variable

* Removed JSON variable

* Added OS-specific runs

* Removed external dependency

* Added braces to target in path

* Reverting to OS-specific runs

* Fixed indent

* temp commit with temp fix for DI on execute method

* small fix + implementing poc for a test

* Added initial tests for verbose output validation

* Refactoring to add Writer across all commands

* Minor refactoring, removed unused imports

* rename from_utf8 to into_string due to clippy warning

* fixed bug from renaming from_utf8

Co-authored-by: Akshay Rane <raneaks@amazon.com>
Co-authored-by: Josh Fried <joshfri@amazon.com>

* Set all field in rules file to serialize with recursive singleton map  (#320)

* testing rust-fmt action with incorectly formatted file

* reverting previous commit

* testing rust-fmt action with incorectly formatted file

* reverting previous commit

* fixed serialization issues for enums

* cleanup

* Refactored resources and tests directory (#321)

Co-authored-by: Akshay Rane <raneaks@amazon.com>

* [Code Quality]: Improve test coverage (#322)

* testing rust-fmt action with incorectly formatted file

* reverting previous commit

* testing rust-fmt action with incorectly formatted file

* reverting previous commit

* create test runners for validate, parse-tree, and test. refactored tests in validate to use rstest + added new test cases. added parse-tree test cases

* removed unneeded cargo_test2 fn

* removing unused cargo_test fn

* rust fmt

* more parse-tree tests

* fixes as per comments

* rustfmt

* Custom writer (#323)

* Adding license info for indoc

* Added tests for migrate and rulegen, added constants for status codes, incorporated writer into test command

* Formatting changes

* Corrected typos in resource file paths

* Added license info for strip-ansi-escapes library

---------

Co-authored-by: Akshay Rane <raneaks@amazon.com>

* [Code Quality]: Unit tests for yaml loader  (#324)

* testing rust-fmt action with incorectly formatted file

* reverting previous commit

* testing rust-fmt action with incorectly formatted file

* reverting previous commit

* more parse-tree tests

* fixes as per comments

* added tests for laoder and fixed some bugs found while writing tests

* removed unneeded use

---------

Co-authored-by: Akshay Rane <aks.rane@gmail.com>
Co-authored-by: Akshay Rane <raneaks@amazon.com>
  • Loading branch information
3 people committed Jan 31, 2023
1 parent df540fc commit 1aca900
Show file tree
Hide file tree
Showing 65 changed files with 2,284 additions and 1,001 deletions.
63 changes: 62 additions & 1 deletion ATTRIBUTION
Original file line number Diff line number Diff line change
Expand Up @@ -1571,4 +1571,65 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

--

dtolnay/indoc


Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.


--

luser/strip-ansi-escapes


Copyright (c) 2018 Mozilla

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
48 changes: 46 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions guard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ nom_locate = "2.0.0"
indexmap = { version = "1.6.0", features = ["serde-1"] }
regex = "1.5.5"
clap = "2.29.0"
strip-ansi-escapes = "0.1.1"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9.10"
walkdir = "2.3.1"
Expand All @@ -39,6 +40,7 @@ grep-matcher = "0.1.5"
grep-regex = "0.1.9"
unsafe-libyaml = "0.2.2"
rstest = "0.15.0"
indoc = "1.0.8"

[dependencies.serde_json]
version = "1.0.85"
Expand Down
9 changes: 9 additions & 0 deletions guard/resources/migrate/output-dir/test_migrate_rule.guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let encryption_flag = true
let aws_ec2_volume = Resources.*[ Type == "AWS::EC2::Volume" ]
rule aws_ec2_volume_checks WHEN %aws_ec2_volume NOT EMPTY {
%aws_ec2_volume {
Properties.Encrypted == %encryption_flag
Properties.Size <= 100
}
}

4 changes: 4 additions & 0 deletions guard/resources/migrate/rules-dir/rule_1dot0.guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let encryption_flag = true

AWS::EC2::Volume Encrypted == %encryption_flag
AWS::EC2::Volume Size <= 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
assignments:
- var: aws_serverless_functions
value:
AccessClause:
query:
- Key: Resources
- AllValues: null
- Filter:
- null
- - - Clause:
access_clause:
query:
query:
- Key: Type
match_all: true
comparator:
- Eq
- false
compare_with:
Value:
path: ''
value: AWS::Serverless::Function
custom_message: null
location:
line: 1
column: 45
negation: false
match_all: true
guard_rules:
- rule_name: KEY_COMPLIANCE_CHECK
conditions:
- - Clause:
access_clause:
query:
query:
- Key: '%aws_serverless_functions'
match_all: true
comparator:
- Empty
- true
compare_with: null
custom_message: null
location:
line: 3
column: 32
negation: false
block:
assignments:
- var: key
value:
AccessClause:
query:
- Key: '%aws_serverless_functions'
- AllIndices: null
- Key: Properties
- Key: Tags
- MapKeyFilter:
- null
- comparator:
- Eq
- false
compare_with:
Value:
path: ''
value: /^(?i)first([-|_])?name$/
match_all: true
conjunctions:
- - Clause:
Clause:
access_clause:
query:
query:
- Key: '%aws_serverless_functions'
- AllIndices: null
- Key: Properties
- Key: Tags
match_all: true
comparator:
- IsMap
- false
compare_with: null
custom_message: null
location:
line: 4
column: 3
negation: false
- - Clause:
Clause:
access_clause:
query:
query:
- Key: '%aws_serverless_functions'
- AllIndices: null
- Key: Properties
- Key: Tags
match_all: true
comparator:
- Empty
- true
compare_with: null
custom_message: null
location:
line: 5
column: 3
negation: false
- - Clause:
Clause:
access_clause:
query:
query:
- Key: '%aws_serverless_functions'
- AllIndices: null
- Key: Properties
- Key: Tags
- AllValues: null
match_all: false
comparator:
- Eq
- false
compare_with:
Value:
path: ''
value: /^(?i)prod$/
custom_message: null
location:
line: 11
column: 3
negation: false
- - Clause:
Clause:
access_clause:
query:
query:
- Key: '%key'
match_all: true
comparator:
- Empty
- true
compare_with: null
custom_message: null
location:
line: 13
column: 3
negation: false
parameterized_rules: []

0 comments on commit 1aca900

Please sign in to comment.