substitute-token
A code desensitization tool, which can substitute tokens (and other sensitive information) in your code.
-
Run:
pip install stoken -
In the root directory of your project, create
stoken.yamland edit it with syntax of yaml.suffix: the suffix of the files you want to detect. Don't forget there's a.before it.token: the sensitive data you want to substitute.
suffix:
- .py
- .js
token:
SECRET_TOKEN: qwertyuiop123456789
MY_PASSWORD: poiuytrewq987654321- Here is demonstration code file, with the suffix
.py:
# demo.py
token = "qwertyuiop123456789"
password = "poiuytrewq987654321"
print(f"{token=}, {password=}")- Run
stoken --mode hide, or run directlystokenwith the default parameter--mode auto, the tokens will be substituted.
# demo.py
token = "#{{SECRET_TOKEN}}#"
password = "#{{MY_PASSWORD}}#"
print(f"{token=}, {password=}")- Run
stoken --mode restore, or run directlystokenwith the default parameter--mode auto, the tokens will be restored.
stoken --help
Options:
--mode [auto|hide|restore|debug] The mode of operation. Default: auto.
-e, --encoding TEXT The encoding used to decode the file.
-p, --variable-prefix TEXT The prefix of variable placeholder.
-s, --variable-suffix TEXT The suffix of variable placeholder.
--debug In debug mode, `stoken` won't modify files,
only detect tokens.
--help Show this message and exit.