-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
sensitive_data_tools.obfuscate_value_if_sensitive()
[minor] (#87)
Co-authored-by: github-actions <[email protected]>
- Loading branch information
Showing
10 changed files
with
100 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,34 @@ on: [push] | |
|
||
jobs: | ||
|
||
py-versions: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.versions.outputs.matrix }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: versions | ||
uses: WIPACrepo/[email protected] | ||
|
||
flake8: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
- uses: actions/setup-python@v3 | ||
- uses: WIPACrepo/[email protected] | ||
|
||
mypy: | ||
needs: [py-versions] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
py3: ${{ fromJSON(needs.py-versions.outputs.matrix) }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
- uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.py3 }} | ||
- uses: WIPACrepo/[email protected] | ||
|
||
py-setup: | ||
|
@@ -38,18 +54,9 @@ jobs: | |
github.ref_type == 'branch' && | ||
format('refs/heads/{0}', github.event.repository.default_branch) != github.ref | ||
name: wipac-dev-py-setup-action (only for non-dependabot non-default branches) | ||
uses: WIPACrepo/wipac-dev-py-setup-action@v2.8 | ||
uses: WIPACrepo/wipac-dev-py-setup-action@v2.9 | ||
with: | ||
base-keywords: "WIPAC IceCube" | ||
py-versions: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.versions.outputs.matrix }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: versions | ||
uses: WIPACrepo/[email protected] | ||
base-keywords: WIPAC IceCube | ||
tests: | ||
needs: [py-versions] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Tests for data_safety_tools.py.""" | ||
|
||
|
||
from wipac_dev_tools import data_safety_tools | ||
|
||
|
||
def test_00() -> None: | ||
"""Test with usual values.""" | ||
senstives = ["my_token", "AUTHOR", "secretive_number", "YouShallNotPass"] | ||
|
||
unimportant_value = "12345" | ||
|
||
for name in ["foo", "bar", "baz"] + senstives: | ||
print(name) | ||
actual = data_safety_tools.obfuscate_value_if_sensitive(name, unimportant_value) | ||
print(actual) | ||
if name in senstives: | ||
assert actual == "***" | ||
else: | ||
assert actual == unimportant_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Tools for handling sensitive data.""" | ||
|
||
_OBFUSCATE_SUBSTRINGS_UPPER = ["TOKEN", "AUTH", "PASS", "SECRET"] | ||
|
||
|
||
def obfuscate_value_if_sensitive(name: str, value: str) -> str: | ||
"""Return "***" if the included `value` is sensitive (by its `name`).""" | ||
if any(s in name.upper() for s in _OBFUSCATE_SUBSTRINGS_UPPER): | ||
return "***" | ||
else: | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters