Skip to content

Commit 439ac05

Browse files
authored
Add pre-commit hooks for ocids, copyright and secrets (#234)
1 parent bb86b6e commit 439ac05

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

.gitleaks.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
title = "Gitleaks Config"
2+
3+
# Gitleaks feature, extending the existing base config from:
4+
# https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml
5+
[extend]
6+
useDefault = true
7+
8+
# Allowlist's 'stopwords' and 'regexes' excludes any secrets or mathching patterns from the current repository.
9+
# Paths listed in allowlist will not be scanned.
10+
[allowlist]
11+
description = "Global allow list"
12+
stopwords = ["test_password", "sample_key"]
13+
regexes = [
14+
'''example-password''',
15+
'''this-is-not-the-secret''',
16+
'''<redacted>'''
17+
]
18+
paths = [
19+
'''tests/integration/tests_configs.yaml'''
20+
]
21+
22+
# Describe rule to search real ocids
23+
[[rules]]
24+
description = "Real ocids"
25+
id = "ocid"
26+
regex = '''ocid[123]\.[a-z1-9A-Z]*\.oc\d\.[a-z1-9A-Z]*\.[a-z1-9A-Z]+'''
27+
keywords = [
28+
"ocid"
29+
]
30+
31+
# Describe rule to search generic secrets
32+
[[rules]]
33+
description = "Generic secret"
34+
id = "generic-secret"
35+
regex = '''(?i)((key|api|token|secret|passwd|password|psw|pass|pswd)[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([0-9a-zA-Z!@#$%^&*<>\\\-_.=]{3,100})['\"]'''
36+
entropy = 0
37+
secretGroup = 4
38+
keywords = [
39+
"key","api","token","secret","passwd","password", "psw", "pass", "pswd"
40+
]

.pre-commit-config.yaml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
repos:
2+
# Standard hooks
23
- repo: https://github.com/pre-commit/pre-commit-hooks
34
rev: v4.4.0
45
hooks:
56
- id: check-ast
7+
exclude: ^docs/
68
- id: check-docstring-first
7-
exclude: ^tests/
9+
exclude: ^(docs/|tests/)
810
- id: check-json
911
- id: check-merge-conflict
1012
- id: check-yaml
@@ -14,14 +16,34 @@ repos:
1416
- id: pretty-format-json
1517
args: ['--autofix']
1618
- id: trailing-whitespace
19+
args: [--markdown-linebreak-ext=md]
20+
exclude: ^docs/
21+
# Black, the code formatter, natively supports pre-commit
1722
- repo: https://github.com/psf/black
18-
rev: 22.12.0
23+
rev: 23.3.0
1924
hooks:
2025
- id: black
26+
exclude: ^docs/
27+
# Regex based rst files common mistakes detector
2128
- repo: https://github.com/pre-commit/pygrep-hooks
22-
rev: v1.9.0
29+
rev: v1.10.0
2330
hooks:
2431
- id: rst-backticks
32+
files: ^docs/
2533
- id: rst-inline-touching-normal
26-
27-
exclude: ^(docs/)
34+
files: ^docs/
35+
# Hardcoded secrets and ocids detector
36+
- repo: https://github.com/gitleaks/gitleaks
37+
rev: v8.17.0
38+
hooks:
39+
- id: gitleaks
40+
# Oracle copyright checker
41+
- repo: https://github.com/oracle-samples/oci-data-science-ai-samples/
42+
rev: cbe0136
43+
hooks:
44+
- id: check-copyright
45+
name: check-copyright
46+
entry: .pre-commit-scripts/check-copyright.py
47+
language: script
48+
types_or: ['python', 'shell', 'bash']
49+
exclude: ^docs/

0 commit comments

Comments
 (0)