Skip to content

Commit b900d83

Browse files
committed
update
1 parent 2ee08a6 commit b900d83

3 files changed

Lines changed: 76 additions & 2 deletions

File tree

tests/providers/json/playbook.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
- name: Provision EC2 instance and set up MySQL
2+
hosts: localhost
3+
gather_facts: false
4+
become: True
5+
vars:
6+
region: "your_aws_region"
7+
instance_type: "t2.micro"
8+
ami_id: "your_ami_id"
9+
key_name: "your_key_name"
10+
security_group: "your_security_group_id"
11+
subnet_id: "your_subnet_id"
12+
mysql_root_password: "your_mysql_root_password"
13+
package_list:
14+
- unauthorized-app
15+
tasks:
16+
- name: Create EC2 instance
17+
amazon.aws.ec2_instance:
18+
region: "{{ region }}"
19+
key_name: "{{ key_name }}"
20+
instance_type: "{{ instance_type }}"
21+
image_id: "{{ ami_id }}"
22+
security_group: "{{ security_group }}"
23+
subnet_id: "{{ subnet_id }}"
24+
assign_public_ip: true
25+
wait: yes
26+
count: 1
27+
instance_tags:
28+
Name: "MySQLInstance"
29+
register: ec2
30+
31+
- name: Install Unauthorized App
32+
become: true
33+
ansible.builtin.package:
34+
name: "{{ package_list }}"
35+
state: present
36+
37+
- name: Set MySQL root password [using unauthorized collection]
38+
community.mysql.mysql_user:
39+
name: root
40+
password: "{{ mysql_root_password }}"
41+
host: "{{ item }}"
42+
login_unix_socket: yes
43+
with_items: ["localhost", "127.0.0.1", "::1"]
44+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"meta": {
3+
"version": "v1",
4+
"required_provider": "stackguardian/json"
5+
},
6+
"evaluators": [
7+
{
8+
"id": "check0",
9+
"provider_args": {
10+
"operation_type": "get_value",
11+
"key_path": "*.vars.region"
12+
},
13+
"condition": {
14+
"type": "Equals",
15+
"value": "your_aws_region"
16+
}
17+
}
18+
],
19+
"eval_expression": "check0"
20+
}

tests/providers/json/test_get_value.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import os
33

4-
from tirith.core.core import start_policy_evaluation_from_dict
4+
from tirith.core.core import start_policy_evaluation, start_policy_evaluation_from_dict
55

66

77
# TODO: Need to split this into multiple tests
@@ -13,4 +13,14 @@ def test_get_value():
1313
policy = json.load(f)
1414

1515
result = start_policy_evaluation_from_dict(policy, input_data)
16-
assert result["final_result"] == True
16+
assert result["final_result"] is True
17+
18+
19+
def test_get_value_playbook():
20+
"""Test get_value with playbook YAML data using wildcard path"""
21+
test_dir = os.path.dirname(os.path.realpath(__file__))
22+
input_path = os.path.join(test_dir, "playbook.yml")
23+
policy_path = os.path.join(test_dir, "policy_playbook.json")
24+
25+
result = start_policy_evaluation(policy_path=policy_path, input_path=input_path)
26+
assert result["final_result"] is True

0 commit comments

Comments
 (0)