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

Update README.md #135

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 53 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Tirith scans declarative Infrastructure as Code (IaC) configurations like Terraf
<!-- - [Local Development Environment](#local-development-environment) -->
- [What is Tirith?](#what-is-tirith)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Example Tirith policies](#example-tirith-policies)
- [Terraform Plan](#terraform-plan-provider)
Expand Down Expand Up @@ -66,6 +67,53 @@ This is only a list of approved features that will be included in Tirith over th
- Support for Cloudformation and ARM
- Extended library of evaluator functions -->

## Installation

### For users

```
pip install git+https://github.com/StackGuardian/tirith.git
```

### For developers
Here we are going to install Tirith in a Python virtual environment.

1. Clone the Tirith repository to your system
```
git clone https://github.com/StackGuardian/tirith.git
```

2. Change directory to the cloned repository
```
cd tirith
```

3. Setup a virtualenv
```
virtualenv .venv
```

4. Activate the virtualenv
```
source .venv/bin/activate
```

5. Install Tirith in the virtualenv
```
# The -e is optional, just in case you wanna make some changes to the codebase
pip install -e .
```

6. Verify that Tirith is installed

```
tirith --version
1.0.0-beta.12

```

Congratulations! Tirith has been setup in your system

## Usage

```
Expand Down Expand Up @@ -273,7 +321,7 @@ Input:


Output:
![](https://github.com/StackGuardian/tirith/blob/updating_readme/docs/tf_example.gif)
![](docs/tf_plan_example.gif)

JSON Output:
```json
Expand Down Expand Up @@ -521,7 +569,7 @@ Input:
```

Output:
![](https://github.com/StackGuardian/tirith/blob/updating_readme/docs/infracost_example.gif)
![](docs/infracost_example.gif)

JSON Output:
```json
Expand Down Expand Up @@ -665,7 +713,7 @@ Example Input:
```

Output:
![](https://github.com/StackGuardian/tirith/blob/updating_readme/docs/sg_workflow_example.gif)
![](docs/sg_workflow_example.gif)


JSON Output:
Expand Down Expand Up @@ -822,7 +870,7 @@ Example Input
```

Output:
![](https://github.com/StackGuardian/tirith/blob/updating_readme/docs/json_example.gif)
![](docs/json_example.gif)

JSON Output
```json
Expand Down Expand Up @@ -1008,7 +1056,7 @@ apiVersion: rbac.authorization.k8s.io/v1
```

Output:
![](https://github.com/StackGuardian/tirith/blob/updating_readme/docs/kubernetes_example.gif)
![](docs/kubernetes_example.gif)

JSON Output:
```json
Expand Down
22 changes: 12 additions & 10 deletions src/tirith/core/evaluators/not_contains.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def evaluate(self, evaluator_input, evaluator_data):
if result:
evaluation_result["message"] = "Did not find {} inside {}".format(evaluator_data, evaluator_input)
else:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
# if evaluator_input is a list
elif isinstance(evaluator_input, list):
evaluator_input = sort_collections(evaluator_input)
Expand All @@ -49,20 +49,20 @@ def evaluate(self, evaluator_input, evaluator_data):
result = evaluator_data not in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Did not find {} inside {}".format(evaluator_data, evaluator_input)
else:
evaluation_result["message"] = "Found {} inside {}".format(
evaluation_result["message"] = "Did not find {} inside {}".format(
evaluator_data, evaluator_input
)
else:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
else:
result = evaluator_data not in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Did not find {} inside {}".format(evaluator_data, evaluator_input)
else:
evaluation_result["message"] = "Found {} inside {}".format(
evaluation_result["message"] = "Did not find {} inside {}".format(
evaluator_data, evaluator_input
)
else:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
elif isinstance(evaluator_input, dict):
if isinstance(evaluator_data, dict):
evaluation_result["passed"] = True
Expand All @@ -71,18 +71,20 @@ def evaluate(self, evaluator_input, evaluator_data):
if key not in evaluator_input:
continue

if evaluator_input[key] == evaluator_data[key]:#changes for xontains
if evaluator_input[key] == evaluator_data[key]: # changes for xontains
evaluation_result["passed"] = False
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)
break
else:
result = evaluator_data not in evaluator_input
evaluation_result["passed"] = result
if result:
evaluation_result["message"] = "Did not find {} inside {}".format(evaluator_data, evaluator_input)
evaluation_result["message"] = "Did not find {} inside {}".format(
evaluator_data, evaluator_input
)
else:
evaluation_result["message"] = "Found {} inside {}".format(evaluator_data, evaluator_input)

else:
evaluation_result["passed"] = False
evaluation_result["message"] = (
Expand Down
18 changes: 6 additions & 12 deletions tests/core/evaluators/test_not_contains.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@
]

checks_passing = [
(["a", "b", "c", "d"],"e"),
(["a", "b", "c", "d"],["a"]),
(["a", "b"],"c"),
({"b": 8, "a": ["a", "c"], "c": 16},{"a": ["a", "d"], "b": 6}),
({"a": "val1", "b": "val2"},"c"),
(["a", "b", "c", "d"], "e"),
(["a", "b", "c", "d"], ["a"]),
(["a", "b"], "c"),
({"b": 8, "a": ["a", "c"], "c": 16}, {"a": ["a", "d"], "b": 6}),
({"a": "val1", "b": "val2"}, "c"),
]

checks_unsupported = [
(2, "a"),
("3", 3),
(1, 1),
(1, 2),
("e", ["a", "b", "c", "d"])
]
checks_unsupported = [(2, "a"), ("3", 3), (1, 1), (1, 2), ("e", ["a", "b", "c", "d"])]

evaluator = NotContains()

Expand Down
Loading