Skip to content

Commit f2e0388

Browse files
authored
[patch] Apply PEP-8, fix code smells, add detect-secrets (#28)
1 parent 3762da0 commit f2e0388

14 files changed

Lines changed: 830 additions & 595 deletions

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
# These rules are ignored
3+
# - E501 line too long
4+
ignore = E501
5+
max-line-length = 120

.github/workflows/pre-commit.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: pre-commit
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v3
13+
- uses: pre-commit/action@v3.0.1

.github/workflows/python-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
# stop the build if there are Python syntax errors or undefined names
4343
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
4444
# exit-zero treats all errors as warnings.
45-
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
45+
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
4646
4747
# 4. Publish to PyPi
4848
# -------------------------------------------------------------------------------------------

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
default_language_version:
2+
python: python
3+
repos:
4+
- repo: https://github.com/hhatto/autopep8
5+
rev: v2.3.1
6+
hooks:
7+
- id: autopep8
8+
- repo: https://github.com/PyCQA/flake8
9+
rev: 7.1.1
10+
hooks:
11+
- id: flake8
12+
- repo: https://github.com/ibm/detect-secrets
13+
rev: 0.13.1+ibm.62.dss
14+
hooks:
15+
- id: detect-secrets
16+
args: [--baseline, .secrets.baseline, --use-all-plugins, --fail-on-unaudited]

.secrets.baseline

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"exclude": {
3+
"files": "^.secrets.baseline$",
4+
"lines": null
5+
},
6+
"generated_at": "2024-10-18T09:38:24Z",
7+
"plugins_used": [
8+
{
9+
"name": "AWSKeyDetector"
10+
},
11+
{
12+
"name": "ArtifactoryDetector"
13+
},
14+
{
15+
"name": "AzureStorageKeyDetector"
16+
},
17+
{
18+
"base64_limit": 4.5,
19+
"name": "Base64HighEntropyString"
20+
},
21+
{
22+
"name": "BasicAuthDetector"
23+
},
24+
{
25+
"name": "BoxDetector"
26+
},
27+
{
28+
"name": "CloudantDetector"
29+
},
30+
{
31+
"ghe_instance": "github.ibm.com",
32+
"name": "GheDetector"
33+
},
34+
{
35+
"name": "GitHubTokenDetector"
36+
},
37+
{
38+
"hex_limit": 3,
39+
"name": "HexHighEntropyString"
40+
},
41+
{
42+
"name": "IbmCloudIamDetector"
43+
},
44+
{
45+
"name": "IbmCosHmacDetector"
46+
},
47+
{
48+
"name": "JwtTokenDetector"
49+
},
50+
{
51+
"keyword_exclude": null,
52+
"name": "KeywordDetector"
53+
},
54+
{
55+
"name": "MailchimpDetector"
56+
},
57+
{
58+
"name": "NpmDetector"
59+
},
60+
{
61+
"name": "PrivateKeyDetector"
62+
},
63+
{
64+
"name": "SlackDetector"
65+
},
66+
{
67+
"name": "SoftlayerDetector"
68+
},
69+
{
70+
"name": "SquareOAuthDetector"
71+
},
72+
{
73+
"name": "StripeDetector"
74+
},
75+
{
76+
"name": "TwilioKeyDetector"
77+
}
78+
],
79+
"results": {
80+
"test/src/test_db2.py": [
81+
{
82+
"hashed_secret": "a4b48a81cdab1e1a5dd37907d6c85ca1c61ddc7c",
83+
"is_secret": false,
84+
"is_verified": false,
85+
"line_number": 263,
86+
"type": "Secret Keyword",
87+
"verified_result": null
88+
}
89+
],
90+
"test/test_cases/manage_fail/db2set.txt": [
91+
{
92+
"hashed_secret": "bd78032d1e51d595c52a633d3041cf7a22bddbf5",
93+
"is_secret": false,
94+
"is_verified": false,
95+
"line_number": 11,
96+
"type": "Secret Keyword",
97+
"verified_result": null
98+
}
99+
],
100+
"test/test_cases/manage_fail/db2uinstance.yaml": [
101+
{
102+
"hashed_secret": "a4b48a81cdab1e1a5dd37907d6c85ca1c61ddc7c",
103+
"is_secret": false,
104+
"is_verified": false,
105+
"line_number": 91,
106+
"type": "Secret Keyword",
107+
"verified_result": null
108+
}
109+
],
110+
"test/test_cases/manage_pass/db2set.txt": [
111+
{
112+
"hashed_secret": "1459943ba5fd876f7ef6e48f566a40b448a2bf08",
113+
"is_secret": false,
114+
"is_verified": false,
115+
"line_number": 11,
116+
"type": "Secret Keyword",
117+
"verified_result": null
118+
}
119+
],
120+
"test/test_cases/manage_pass/db2uinstance.yaml": [
121+
{
122+
"hashed_secret": "1459943ba5fd876f7ef6e48f566a40b448a2bf08",
123+
"is_secret": false,
124+
"is_verified": false,
125+
"line_number": 107,
126+
"type": "Secret Keyword",
127+
"verified_result": null
128+
}
129+
]
130+
},
131+
"version": "0.13.1+ibm.62.dss",
132+
"word_list": {
133+
"file": null,
134+
"hash": null
135+
}
136+
}

CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Developer Guide
2+
===============================================================================
3+
4+
5+
Detect Secrets
6+
-------------------------------------------------------------------------------
7+
- Update the `.secrets.baseline` file using: `detect-secrets scan --update .secrets.baseline`
8+
- Audit secrets using: `detect-secrets audit .secrets.baseline`
9+
10+
11+
Pre-Commit Hooks
12+
-------------------------------------------------------------------------------
13+
The follow pre-commit hooks are enabled:
14+
15+
- **autopep8**
16+
- **flake8**
17+
- **detect-secrets**
18+
19+
These hooks are also executed in a GitHub action in the [pre-commit workflow](.github/workflows/pre-commit.yml).
20+
21+
```bash
22+
python -m pip install pre-commit --upgrade
23+
pre-commit install
24+
```
25+
26+
Manually run the pre-commit hooks against changed files
27+
```bash
28+
pre-commit run
29+
```
30+
31+
Manually run the pre-commit hooks against all files
32+
```bash
33+
pre-commit run -a
34+
```

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
mas.devops
22
===============================================================================
3+
[![Code style: PEP8](https://img.shields.io/badge/code%20style-PEP--8-blue.svg)](https://peps.python.org/pep-0008/)
4+
[![Flake8: checked](https://img.shields.io/badge/flake8-checked-blueviolet)](https://flake8.pycqa.org/en/latest/)
5+
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ibm-mas/python-devops/python-release.yml)
6+
![PyPI - Version](https://img.shields.io/pypi/v/mas.devops)
7+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mas.devops)
8+
![PyPI - Downloads](https://img.shields.io/pypi/dm/mas.devops)
39

410

511
Example

bin/mas-devops-db2-validate-config

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,21 @@ if __name__ == "__main__":
3131

3232
args, unknown = parser.parse_known_args()
3333

34-
3534
log_level = getattr(logging, args.log_level)
3635
logging.basicConfig()
3736
logging.getLogger('mas.devops.db2').setLevel(level=log_level)
3837

39-
4038
try:
41-
# Try to load in-cluster configuration
42-
config.load_incluster_config()
43-
print("Loaded in-cluster configuration")
39+
# Try to load in-cluster configuration
40+
config.load_incluster_config()
41+
print("Loaded in-cluster configuration")
4442
except ConfigException:
45-
# If that fails, fall back to kubeconfig file
46-
config.load_kube_config()
47-
print("Loaded kubeconfig file")
43+
# If that fails, fall back to kubeconfig file
44+
config.load_kube_config()
45+
print("Loaded kubeconfig file")
4846

4947
validate_db2_config(
50-
client.api_client.ApiClient(),
51-
args.mas_instance_id,
52-
args.mas_app_id
53-
)
48+
client.api_client.ApiClient(),
49+
args.mas_instance_id,
50+
args.mas_app_id
51+
)

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
# http://www.eclipse.org/legal/epl-v10.html
88
# *****************************************************************************
99

10+
from setuptools import setup, find_namespace_packages
1011
import codecs
1112
import sys
1213
import os
1314
sys.path.insert(0, 'src')
1415

15-
from setuptools import setup, find_namespace_packages
1616

1717
if not os.path.exists('README.rst'):
1818
import pypandoc
@@ -25,11 +25,14 @@
2525

2626
# Maintain a single source of versioning
2727
# https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
28+
29+
2830
def read(rel_path):
2931
here = os.path.abspath(os.path.dirname(__file__))
3032
with codecs.open(os.path.join(here, rel_path), 'r') as fp:
3133
return fp.read()
3234

35+
3336
def get_version(rel_path):
3437
for line in read(rel_path).splitlines():
3538
if line.startswith('__version__'):
@@ -38,6 +41,7 @@ def get_version(rel_path):
3841
else:
3942
raise RuntimeError("Unable to find version string.")
4043

44+
4145
setup(
4246
name='mas-devops',
4347
version=get_version("src/mas/devops/__init__.py"),

0 commit comments

Comments
 (0)