# stoken
> substitute-token
[简体中文](https://github.com/laorange/stoken/blob/main/README.zh.md) | [English docs](https://github.com/laorange/stoken/blob/main/README.md)
A code desensitization tool, which can substitute tokens (and other sensitive information) in your code.
---
## Quick start
1. Run: `pip install stoken`
2. In the root directory of your project, create **`stoken.yaml`** and edit it with [syntax of yaml](https://en.wikipedia.org/wiki/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.
```yaml
suffix:
- .py
- .js
token:
SECRET_TOKEN: qwertyuiop123456789
MY_PASSWORD: poiuytrewq987654321
```
3. Here is demonstration code file, with the suffix `.py`:
```python
# demo.py
token = "qwertyuiop123456789"
password = "poiuytrewq987654321"
print(f"{token=}, {password=}")
```
4. Run `stoken --mode hide`, or run directly `stoken` with the default parameter `--mode auto`, the tokens will be substituted.
```python
# demo.py
token = "#{{SECRET_TOKEN}}#"
password = "#{{MY_PASSWORD}}#"
print(f"{token=}, {password=}")
```
5. Run `stoken --mode restore`, or run directly `stoken` with the default parameter `--mode auto`, the tokens will be restored.
## API
`stoken --help`
| options | description |
| ----------------------- | ------------------------------------------------------------ |
| --mode | The mode of operation. Default: `auto` |
| -e \| --encoding | The encoding used to decode the file. Default: `utf-8` |
| -p \| --variable-prefix | The prefix of variable placeholder. Default: `#{{` |
| -s \| --variable-suffix | The suffix of variable placeholder. Default: `}}#` |
| --debug | Activate this option to enter debug mode, as result, `stoken` won't modify files, only detect tokens. |
| --no-git | By default, the program will detect if there is a git directory, and if so, it will ignore the files in `.gitignore`. Activate this option to detect all the files. |
| --help | Show this message and exit. |
Raw data
{
"_id": null,
"home_page": "https://github.com/laorange/stoken",
"name": "stoken",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "git,data desensitization,replace token",
"author": "laorange",
"author_email": "laorange6666@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7f/cf/a1025e628bed4f52626e1ecff211b0d7e08986f00eb1803dba3f426bc888/stoken-0.2.2.tar.gz",
"platform": "any",
"description": "# stoken \r\n\r\n> substitute-token\r\n\r\n[\u7b80\u4f53\u4e2d\u6587](https://github.com/laorange/stoken/blob/main/README.zh.md) | [English docs](https://github.com/laorange/stoken/blob/main/README.md)\r\n\r\nA code desensitization tool, which can substitute tokens (and other sensitive information) in your code. \r\n\r\n---\r\n\r\n## Quick start\r\n\r\n1. Run: `pip install stoken` \r\n\r\n2. In the root directory of your project, create **`stoken.yaml`** and edit it with [syntax of yaml](https://en.wikipedia.org/wiki/YAML).\r\n + `suffix` : the suffix of the files you want to detect. **Don't forget there's a `.` before it**.\r\n + `token` : the sensitive data you want to substitute. \r\n\r\n```yaml\r\nsuffix:\r\n - .py\r\n - .js\r\n \t\r\ntoken:\r\n SECRET_TOKEN: qwertyuiop123456789\r\n MY_PASSWORD: poiuytrewq987654321\r\n```\r\n\r\n3. Here is demonstration code file, with the suffix `.py`\uff1a\r\n\r\n```python\r\n# demo.py\r\ntoken = \"qwertyuiop123456789\"\r\npassword = \"poiuytrewq987654321\"\r\nprint(f\"{token=}, {password=}\")\r\n```\r\n\r\n4. Run `stoken --mode hide`, or run directly `stoken` with the default parameter `--mode auto`, the tokens will be substituted.\r\n\r\n```python\r\n# demo.py\r\ntoken = \"#{{SECRET_TOKEN}}#\"\r\npassword = \"#{{MY_PASSWORD}}#\"\r\nprint(f\"{token=}, {password=}\")\r\n```\r\n\r\n5. Run `stoken --mode restore`, or run directly `stoken` with the default parameter `--mode auto`, the tokens will be restored.\r\n\r\n## API\r\n\r\n`stoken --help`\r\n\r\n| options | description |\r\n| ----------------------- | ------------------------------------------------------------ |\r\n| --mode | The mode of operation. Default: `auto` |\r\n| -e \\| --encoding | The encoding used to decode the file. Default: `utf-8` |\r\n| -p \\| --variable-prefix | The prefix of variable placeholder. Default: `#{{` |\r\n| -s \\| --variable-suffix | The suffix of variable placeholder. Default: `}}#` |\r\n| --debug | Activate this option to enter debug mode, as result, `stoken` won't modify files, only detect tokens. |\r\n| --no-git | By default, the program will detect if there is a git directory, and if so, it will ignore the files in `.gitignore`. Activate this option to detect all the files. |\r\n| --help | Show this message and exit. |\r\n\r\n",
"bugtrack_url": null,
"license": "AGPL-3.0",
"summary": "A code desensitization tool, which can substitute tokens (and other sensitive information) in your code.",
"version": "0.2.2",
"split_keywords": [
"git",
"data desensitization",
"replace token"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "2b439b295dcdb2adf56b7d6dfe6a819c",
"sha256": "5a424e80af14a9880ecbd67b43b7c7ebbc43fed02f0ac659bde6cc17b71beed8"
},
"downloads": -1,
"filename": "stoken-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "2b439b295dcdb2adf56b7d6dfe6a819c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 16449,
"upload_time": "2022-12-13T10:47:55",
"upload_time_iso_8601": "2022-12-13T10:47:55.678385Z",
"url": "https://files.pythonhosted.org/packages/7f/cf/a1025e628bed4f52626e1ecff211b0d7e08986f00eb1803dba3f426bc888/stoken-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-13 10:47:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "laorange",
"github_project": "stoken",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pyyaml",
"specs": [
[
">=",
"6.0"
]
]
},
{
"name": "setuptools",
"specs": [
[
">=",
"65.5.0"
]
]
},
{
"name": "colorama",
"specs": [
[
">=",
"0.4.6"
]
]
},
{
"name": "pydantic",
"specs": [
[
">=",
"1.10.2"
]
]
},
{
"name": "click",
"specs": [
[
">=",
"8.1.3"
]
]
},
{
"name": "GitPython",
"specs": [
[
">=",
"3.1.29"
]
]
}
],
"lcname": "stoken"
}