Skip to content

Commit 67567f5

Browse files
authored
3.0 updates (#23) (#24)
* Updating precommit hook to not require an api key * updating reference and readme for 3.0
1 parent 352398f commit 67567f5

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This integration requires an endpoint to make requests against. For instructions
1919
``` yaml
2020
repos:
2121
- repo: https://github.com/privateai/pai-pre-commit-hook.git
22-
rev: v1.2.1-beta
22+
rev: v1.3.0
2323
hooks:
2424
- id: pii-check
2525
args:
@@ -35,9 +35,7 @@ This integration requires an endpoint to make requests against. For instructions
3535

3636
1. Replace `<URL>` with the url of where your container is hosted.\
3737
eg. [http://localhost:8080/v3/process_text](http://localhost:8080/v3/process_text) for a container running locally.
38-
1. Create a .env file and add your API_KEY like so:\
39-
API_KEY=`<put your API KEY here>`
40-
1. Replace `<ENV_FILE_PATH>` with the path to your .env file.
38+
4139
1. Run 'pre-commit install' from inside the git repo where you want to use this hook.
4240

4341
After the above steps, your project structure should look somewhat like:
@@ -65,7 +63,7 @@ Here is an example of what your pre-commit-config.yaml may look like:
6563
``` yaml
6664
repos:
6765
- repo: https://github.com/privateai/pai-pre-commit-hook.git
68-
rev: v1.2.1-beta
66+
rev: v1.3.0
6967
hooks:
7068
- id: pii-check
7169
args:

pii_check/pii_check_hook.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def get_ignored_lines(filename: str) -> Set[int]:
6161
return ignored_lines
6262

6363

64-
def get_response_from_api(content, url, api_key, enabled_entity_list, blocked_list):
64+
def get_response_from_api(content, url, enabled_entity_list, blocked_list):
6565
payload = get_payload(content, enabled_entity_list, blocked_list)
66-
headers = {"Content-Type": "application/json", "X-API-KEY": api_key}
66+
headers = {"Content-Type": "application/json"}
6767

6868
response = requests.post(url, json=payload, headers=headers)
6969
response.raise_for_status()
@@ -106,7 +106,7 @@ class PiiResult:
106106
entity_type: str
107107

108108

109-
def check_for_pii(filename: str, url: str, api_key: str, enabled_entity_list: List[str], blocked_list: List[str]) -> List[PiiResult]:
109+
def check_for_pii(filename: str, url: str, enabled_entity_list: List[str], blocked_list: List[str]) -> List[PiiResult]:
110110

111111
if not os.path.getsize(filename):
112112
# dont't expect PII in empty files
@@ -121,7 +121,7 @@ def check_for_pii(filename: str, url: str, api_key: str, enabled_entity_list: Li
121121
# this contains also context around the added lines
122122
added_text = ["".join(hunk.target) for hunk in hunks]
123123

124-
api_pii_results = get_response_from_api(added_text, url, api_key, enabled_entity_list, blocked_list)
124+
api_pii_results = get_response_from_api(added_text, url, enabled_entity_list, blocked_list)
125125
ignored_lines = get_ignored_lines(filename)
126126

127127
pii_results: List[PiiResult] = []
@@ -158,11 +158,6 @@ def main():
158158
dotenv_path = Path(os.environ["PWD"], args.env_file_path)
159159
load_dotenv(dotenv_path=dotenv_path)
160160

161-
if "API_KEY" in os.environ:
162-
API_KEY = os.environ["API_KEY"]
163-
else:
164-
sys.exit("Your .env file is missing from the provided path or does not contain API_KEY")
165-
166161
enabled_entity_list = [item.upper() for item in args.enabled_entities]
167162

168163
blocked_list = [blocked for blocked in args.blocked_list] if args.blocked_list else []
@@ -171,7 +166,7 @@ def main():
171166
pii_results = [
172167
result
173168
for filename in args.filenames
174-
for result in check_for_pii(os.path.abspath(filename), args.url, API_KEY, enabled_entity_list, blocked_list)
169+
for result in check_for_pii(os.path.abspath(filename), args.url, enabled_entity_list, blocked_list)
175170
]
176171
except RuntimeError as e:
177172
print(e)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import find_packages, setup
22

3-
VERSION = "1.2.1"
3+
VERSION = "1.3.0"
44
DESCRIPTION = "Pre-commit hook to check if modified files have PII and marks it."
55

66

0 commit comments

Comments
 (0)