Skip to content

Commit 0e8cec9

Browse files
authored
Version 3.3.0: Add rule details (#40)
1 parent 01d3d21 commit 0e8cec9

File tree

11 files changed

+344
-5
lines changed

11 files changed

+344
-5
lines changed

openapi.json

+131-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"title": "Repository Scanner (RESC)",
55
"description": "RESC API helps you to perform several operations upon findings obtained from multiple source code repositories.",
6-
"version": "3.3.5"
6+
"version": "3.5.0"
77
},
88
"paths": {
99
"/resc/v1/health": {
@@ -625,6 +625,74 @@
625625
}
626626
}
627627
},
628+
"/resc/v1/rule-packs/{rule_pack_version}/rules": {
629+
"get": {
630+
"tags": [
631+
"resc-rule-packs"
632+
],
633+
"summary": "Get unique rule from rule pack",
634+
"description": "Retrieve the rule data from a rule_name and rule_pack\n\n- **db_connection**: Session of the database connection\n- **rule_pack_version**: filter on rule pack version\n- **rule_name**: filter on rule pack version\n- **return**: List[str] The output will contain a list of strings of unique rules in the findings table",
635+
"operationId": "get_rule_from_rule_pack_resc_v1_rule_packs__rule_pack_version__rules_get",
636+
"parameters": [
637+
{
638+
"required": true,
639+
"schema": {
640+
"type": "string",
641+
"title": "Rule Pack Version"
642+
},
643+
"name": "rule_pack_version",
644+
"in": "path"
645+
},
646+
{
647+
"required": true,
648+
"schema": {
649+
"type": "string",
650+
"title": "RuleName"
651+
},
652+
"name": "rule_name",
653+
"in": "query"
654+
}
655+
],
656+
"responses": {
657+
"200": {
658+
"description": "Retrieve the rule data for a rule pack",
659+
"content": {
660+
"application/json": {
661+
"schema": {
662+
"$ref": "#/components/schemas/RuleRead"
663+
}
664+
}
665+
}
666+
},
667+
"404": {
668+
"description": "Scan <scan_id> not found",
669+
"content": {
670+
"application/json": {
671+
"schema": {
672+
"$ref": "#/components/schemas/Model404"
673+
}
674+
}
675+
}
676+
},
677+
"422": {
678+
"description": "RulePackVersion and RuleName required",
679+
"content": {
680+
"application/json": {
681+
"schema": {
682+
"$ref": "#/components/schemas/Model422"
683+
}
684+
}
685+
}
686+
},
687+
"500": {
688+
"description": "Internal server error. Contact your system administrator"
689+
},
690+
"503": {
691+
"description": "Unable to communicate with DataBase, Please contact your system administrator"
692+
}
693+
}
694+
}
695+
},
628696
"/resc/v1/findings": {
629697
"get": {
630698
"tags": [
@@ -4720,6 +4788,68 @@
47204788
],
47214789
"title": "RulePackVersion"
47224790
},
4791+
"RuleRead": {
4792+
"properties": {
4793+
"rule_name": {
4794+
"type": "string",
4795+
"maxLength": 400,
4796+
"minLength": 1,
4797+
"title": "Rule Name"
4798+
},
4799+
"description": {
4800+
"type": "string",
4801+
"maxLength": 4000,
4802+
"title": "Description"
4803+
},
4804+
"comment": {
4805+
"type": "string",
4806+
"maxLength": 2000,
4807+
"title": "Comment"
4808+
},
4809+
"entropy": {
4810+
"type": "number",
4811+
"title": "Entropy"
4812+
},
4813+
"secret_group": {
4814+
"type": "integer",
4815+
"title": "Secret Group"
4816+
},
4817+
"regex": {
4818+
"type": "string",
4819+
"title": "Regex"
4820+
},
4821+
"path": {
4822+
"type": "string",
4823+
"title": "Path"
4824+
},
4825+
"keywords": {
4826+
"type": "string",
4827+
"title": "Keywords"
4828+
},
4829+
"rule_pack": {
4830+
"type": "string",
4831+
"pattern": "^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$",
4832+
"title": "Rule Pack"
4833+
},
4834+
"allow_list": {
4835+
"type": "integer",
4836+
"exclusiveMinimum": 0.0,
4837+
"title": "Allow List"
4838+
},
4839+
"id_": {
4840+
"type": "integer",
4841+
"exclusiveMinimum": 0.0,
4842+
"title": "Id "
4843+
}
4844+
},
4845+
"type": "object",
4846+
"required": [
4847+
"rule_name",
4848+
"rule_pack",
4849+
"id_"
4850+
],
4851+
"title": "RuleRead"
4852+
},
47234853
"ScanCreate": {
47244854
"properties": {
47254855
"scan_type": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "resc-frontend",
3-
"version": "3.2.9",
3+
"version": "3.3.0",
44
"author": "ABN AMRO Bank",
55
"description": "Repository Scanner Frontend",
66
"license": "MIT",

src/components/ScanFindings/FindingPanel.vue

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<b-tabs pills card>
3838
<AuditTab :finding="findingRef"></AuditTab>
3939
<HistoryTab :finding="findingRef"></HistoryTab>
40+
<RuleTab :ruleName="findingRef.rule_name" :rulePack="findingRef.rule_pack"></RuleTab>
4041
</b-tabs>
4142
</b-card>
4243
</div>
@@ -47,6 +48,7 @@
4748
<script setup lang="ts">
4849
import AuditTab from '@/components/ScanFindings/AuditTab.vue';
4950
import HistoryTab from '@/components/ScanFindings/HistoryTab.vue';
51+
import RuleTab from '@/components/ScanFindings/RuleTab.vue';
5052
import type { AugmentedDetailedFindingRead } from '@/services/shema-to-types';
5153
import { ref } from 'vue';
5254

src/components/ScanFindings/HistoryTab.vue

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
</div>
1111

1212
<div class="pr-1" v-if="hasRecords">
13-
<!-- sticky-header="230px" -->
1413
<b-table
1514
id="audit-history-table"
1615
:items="auditList"
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<template>
2+
<div>
3+
<b-tab title="RULE" title-item-class="tab-pills" v-on:click="fetchRuleForRulePack">
4+
<SpinnerVue v-if="!loadedData" />
5+
6+
<div class="pr-1" v-if="loadedData && rule">
7+
<b-card-text v-if="rule?.description"
8+
><span class="fw-bold">Description: </span>{{ rule.description }}</b-card-text
9+
>
10+
<b-card-text v-if="rule?.regex"
11+
><span class="fw-bold">Regex: </span>{{ rule.regex }}</b-card-text
12+
>
13+
<b-card-text v-if="rule?.path"
14+
><span class="fw-bold">Path: </span>{{ rule.path }}</b-card-text
15+
>
16+
<b-card-text v-if="rule?.comment"
17+
><span class="fw-bold">Comment: </span>{{ rule.comment }}</b-card-text
18+
>
19+
</div>
20+
<div class="pr-1" v-if="loadedData && !rule">Rule not found.</div>
21+
</b-tab>
22+
</div>
23+
</template>
24+
25+
<script setup lang="ts">
26+
import AxiosConfig from '@/configuration/axios-config';
27+
import RulePackService from '@/services/rule-pack-service';
28+
import SpinnerVue from '@/components/Common/SpinnerVue.vue';
29+
import type { RuleRead } from '@/services/shema-to-types';
30+
import { ref } from 'vue';
31+
32+
const loadedData = ref(false);
33+
34+
type Props = {
35+
ruleName: string;
36+
rulePack: string;
37+
};
38+
const props = defineProps<Props>();
39+
40+
const rule = ref(null as RuleRead | null);
41+
42+
function fetchRuleForRulePack() {
43+
loadedData.value = false;
44+
RulePackService.getRuleFromRulePack(props.rulePack, props.ruleName)
45+
.then((response) => {
46+
rule.value = response.data;
47+
loadedData.value = true;
48+
})
49+
.catch((error) => {
50+
loadedData.value = true;
51+
AxiosConfig.handleError(error);
52+
});
53+
}
54+
</script>

src/services/rule-pack-service.ts

+11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ const RulePackService = {
8282
version: toRaw(rulePackVersion),
8383
});
8484
},
85+
86+
async getRuleFromRulePack(
87+
rulePackVersion: string,
88+
ruleId: string,
89+
): Promise<
90+
AxiosResponse<
91+
paths['/resc/v1/rule-packs/{rule_pack_version}/rules']['get']['responses']['200']['content']['application/json']
92+
>
93+
> {
94+
return axios.get(`/rule-packs/${rulePackVersion}/rules?rule_name=${ruleId}`);
95+
},
8596
};
8697

8798
export default RulePackService;

src/services/schema.d.ts

+84
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ export interface paths {
128128
*/
129129
post: operations['mark_rule_pack_as_outdated_resc_v1_rule_packs_mark_as_outdated_post'];
130130
};
131+
'/resc/v1/rule-packs/{rule_pack_version}/rules': {
132+
/**
133+
* Get unique rule from rule pack
134+
* @description Retrieve the rule data from a rule_name and rule_pack
135+
*
136+
* - **db_connection**: Session of the database connection
137+
* - **rule_pack_version**: filter on rule pack version
138+
* - **rule_name**: filter on rule pack version
139+
* - **return**: List[str] The output will contain a list of strings of unique rules in the findings table
140+
*/
141+
get: operations['get_rule_from_rule_pack_resc_v1_rule_packs__rule_pack_version__rules_get'];
142+
};
131143
'/resc/v1/findings': {
132144
/**
133145
* Get findings
@@ -1381,6 +1393,31 @@ export interface components {
13811393
/** Version */
13821394
version: string;
13831395
};
1396+
/** RuleRead */
1397+
RuleRead: {
1398+
/** Rule Name */
1399+
rule_name: string;
1400+
/** Description */
1401+
description?: string;
1402+
/** Comment */
1403+
comment?: string;
1404+
/** Entropy */
1405+
entropy?: number;
1406+
/** Secret Group */
1407+
secret_group?: number;
1408+
/** Regex */
1409+
regex?: string;
1410+
/** Path */
1411+
path?: string;
1412+
/** Keywords */
1413+
keywords?: string;
1414+
/** Rule Pack */
1415+
rule_pack: string;
1416+
/** Allow List */
1417+
allow_list?: number;
1418+
/** Id */
1419+
id_: number;
1420+
};
13841421
/** ScanCreate */
13851422
ScanCreate: {
13861423
/** @default BASE */
@@ -1923,6 +1960,53 @@ export interface operations {
19231960
};
19241961
};
19251962
};
1963+
/**
1964+
* Get unique rule from rule pack
1965+
* @description Retrieve the rule data from a rule_name and rule_pack
1966+
*
1967+
* - **db_connection**: Session of the database connection
1968+
* - **rule_pack_version**: filter on rule pack version
1969+
* - **rule_name**: filter on rule pack version
1970+
* - **return**: List[str] The output will contain a list of strings of unique rules in the findings table
1971+
*/
1972+
get_rule_from_rule_pack_resc_v1_rule_packs__rule_pack_version__rules_get: {
1973+
parameters: {
1974+
query: {
1975+
rule_name: string;
1976+
};
1977+
path: {
1978+
rule_pack_version: string;
1979+
};
1980+
};
1981+
responses: {
1982+
/** @description Retrieve the rule data for a rule pack */
1983+
200: {
1984+
content: {
1985+
'application/json': components['schemas']['RuleRead'];
1986+
};
1987+
};
1988+
/** @description Scan <scan_id> not found */
1989+
404: {
1990+
content: {
1991+
'application/json': components['schemas']['Model404'];
1992+
};
1993+
};
1994+
/** @description RulePackVersion and RuleName required */
1995+
422: {
1996+
content: {
1997+
'application/json': components['schemas']['Model422'];
1998+
};
1999+
};
2000+
/** @description Internal server error. Contact your system administrator */
2001+
500: {
2002+
content: never;
2003+
};
2004+
/** @description Unable to communicate with DataBase, Please contact your system administrator */
2005+
503: {
2006+
content: never;
2007+
};
2008+
};
2009+
};
19262010
/**
19272011
* Get findings
19282012
* @description Retrieve all findings objects paginated

src/services/shema-to-types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type RepositoryEnrichedRead = components['schemas']['RepositoryEnrichedRe
4444
export type RepositoryRead = components['schemas']['RepositoryRead'];
4545
export type RuleFindingCountModel = components['schemas']['RuleFindingCountModel'];
4646
export type RulePackRead = components['schemas']['RulePackRead'];
47+
export type RuleRead = components['schemas']['RuleRead'];
4748
export type ScanCreate = components['schemas']['ScanCreate'];
4849
export type ScanRead = components['schemas']['ScanRead'];
4950
export type ScanType = components['schemas']['ScanType'];

tests/resources/mock_rule.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"data": {
3+
"rule_name": "rule1",
4+
"description": "some description",
5+
"comment": "some comment for CLI",
6+
"regex": "BEGIN PRIVATE KEY some base64 fluff END PRIVATE KEY",
7+
"path": "something.pem",
8+
"rule_pack": "1.0.0",
9+
"allow_list": 0,
10+
"id_": 15
11+
}
12+
}

0 commit comments

Comments
 (0)