forked from wso2/product-microgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (78 loc) · 3.56 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: PR Check - Integration Tests
on:
push:
branches: [choreo]
pull_request:
branches: [choreo]
jobs:
build:
runs-on: ubuntu-20.04
env:
USER_SOURCE_REPO: VirajSalaka/proxy-from-gh
MAX_HEAP: 2048m
MIN_HEAP: 512m
APIM_ENDPOINT: https://sts.preview-dv.choreo.dev
RUDDER_ENDPOINT: http://dp-rudder
SUB_PATH: adminService
ORG_UUID: e615dff6-6691-4cec-96af-45be2a11a2ca
LINTER_ENDPOINT: undefined
SERVICE_SOURCE_DIR: proxy-dir
COMPONENT_ID: 5f7ad903-54ab-4724-aa4b-5cedf8604c88
PROJECT_ID: 01fe8d09-0f76-458a-b40f-d15afbc69f8c
CP_GW_ENDPOINT: https://apis.preview-dv.choreo.dev
steps:
- uses: actions/checkout@v2
- name: Install python dependencies
id: "install_python_deps"
run: |
python3 -m pip install --upgrade pip
pip3 install tabulate
- name: Echo string
id: "validate_linting"
run: |-
sleep 3
LINTER_URL="${{env.CP_GW_ENDPOINT}}/governance/v1.0/projects/${{env.PROJECT_ID}}/components/${{env.COMPONENT_ID}}/endpoints/${{inputs.apiId}}/rule-adherence" >> $GITHUB_OUTPUT
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X GET "${{LINTER_URL}}" -H "Authorization: Bearer ${{github.events.inputs.userToken}}") >> $GITHUB_OUTPUT
RESPONSE=$(curl -o response.json -s -w "%{http_code}" ${LINTER_URL})
if [[ $RESPONSE != "200" ]]; then
echo "Governance Validation Failed Internally"
exit 1
fi
cat response.json | python3 -c "
import json;
import sys;
from tabulate import tabulate;
def visualize_trivy_like_table(json_data):
data = json.loads(json_data)
print(\"Summary:\")
print(f\" Violated rulesets: {data['summary']['ruleset']['violated']}\")
print(f\" Adhered rulesets: {data['summary']['ruleset']['adhered']}\")
print(f\" Total rulesets: {data['summary']['ruleset']['total']}\")
print()
table_data = []
for ruleset in data['list']:
if ruleset['status'] == 'violated':
for rule in ruleset['violatedRules']['list']:
if rule['severity'] in ['error', 'warn']:
severity = rule['severity'].upper()
ruleset_name = ruleset['rulesetName']
# rule_id = rule['ruleId']
message = rule['message']
pathsList = []
for path in rule['paths']['list']:
if len(path[2:]) <= 43:
pathsList.append(path)
else:
pathsList.append(f\"{path[:1]}...{path[-41:]}\")
paths = '\n'.join(pathsList)
table_data.append([severity, ruleset_name, message, paths])
if table_data:
headers = [\"SEVERITY\", \"RULESET\", \"MESSAGE\", \"PATHS\"]
maxcolwidths = [10, 30, 30, None]
print(tabulate(table_data, headers=headers, tablefmt=\"grid\", maxcolwidths=maxcolwidths))
else:
print(\"No errors or warnings found.\")
print(f\"\nTotal rulesets evaluated: {data['count']}\")
json_payload = sys.stdin.read()
visualize_trivy_like_table(json_payload)
"