shayanorellana:

ex: MongoClient(username: mongodb_pass) instead of having the password in plain sight in the script.

Not having the credentials directly in the script is good practice, yes. That has nothing to do with masking, though.

You can use environment variable just like in the Actions workflow, you’ll just have to set them when you run the script. Just be aware of what else you run in the same environment and of shell history (if you use Bash, HISTCONTROL is your friend).

An alternative is to use a config file, just read the values from another file instead of coding them into the script. Python has built-in parsers for JSON and INI-style files. I like YAML, but that requires installing PyYAML. Obviously don’t commit that file, I recommend adding it to .gitignore.

You can even support both in your script: Read environment variables or config file depending on command line options or simply what’s available.

🌐
GitHub
github.com › python › cpython › blob › main › Lib › secrets.py
cpython/Lib/secrets.py at main · python/cpython
managing secrets such as account authentication, tokens, and similar. · See PEP 506 for more information. https://peps.python.org/pep-0506/ · """ · __all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom', 'token_bytes', 'token_hex', 'token_urlsafe', 'compare_digest', ] ·
Author   python
Discussions

How to pass secrets from GitHub Actions to python environ variables? - Stack Overflow
To run pytest within GitHub Actions, I have to pass some secrets for Python running environ. e.g., - name: Test env vars for python run: python -c 'import os;print(os.environ)' env: More on stackoverflow.com
🌐 stackoverflow.com
git - How do I include GitHub secrets in a python script? - Stack Overflow
I am trying to move my bot written using discord.py/pycord to github for easier access, and I accidentally pushed my bot tokn to the hub, thankfully discord reset it for me and nothing hapened. Now i More on stackoverflow.com
🌐 stackoverflow.com
python - Using github with secret keys - Stack Overflow
I have a Python script with secret keys for the Tweeter API. I would like to version control my script using Github. How do I keep my keys secret while still uploading to Github? That is, the value... More on stackoverflow.com
🌐 stackoverflow.com
March 15, 2015
Manage your GitHub Actions secrets, with a simple Python script
🌐 r/github
2
7
April 15, 2020
🌐
GitHub
github.com › mbacchi › python-git-secrets
GitHub - mbacchi/python-git-secrets: A pure Python library providing git-secrets functionality.
A pure Python library providing git-secrets functionality. We don't plan to do everything that git-secrets does (i.e. placing patterns in your .gitconfig file), but provide you with the building blocks for matching patterns you don't want exposed ...
Starred by 4 users
Forked by 5 users
Languages   Python 96.7% | Makefile 3.3% | Python 96.7% | Makefile 3.3%
🌐
PyPI
pypi.org › project › githubsecrets
githubsecrets · PyPI
A simple CLI to manage GitHub secrets, that are used with GitHub Actions
      » pip install githubsecrets
    
Published   Nov 05, 2020
Version   1.0.8
🌐
Netlify
canovasjm.netlify.app › 2021 › 01 › 12 › github-secrets-from-python-and-r
GitHub Secrets from Python and R - JM - Netlify
We’ve just set our environment variables. Now, we need to read them and, as you will see next, the process is very similar in Python and R. You can always check the full code on the GitHub repository, but the main lines to read the variables into our scripts are:
🌐
GitHub
github.com › davedittrich › python_secrets
GitHub - davedittrich/python_secrets: Python CLI for managing secrets and eliminating default passwords in FOSS · GitHub
Python CLI for managing secrets and eliminating default passwords in FOSS - davedittrich/python_secrets
Starred by 16 users
Forked by 6 users
Languages   Python 90.1% | Shell 8.0% | Makefile 1.9%
Find elsewhere
🌐
Medium
medium.datadriveninvestor.com › accessing-github-secrets-in-python-d3e758d8089b
Accessing GitHub secrets in Python | by Dipam Vasani | DataDrivenInvestor
April 21, 2021 - You can use it to store tokens, account details, passwords, anything you would want to encrypt. Join Medium for free to get updates from this writer. ... To add a new secret, go to your GitHub repository > Settings > Secrets > New Repository Secret.
🌐
GitHub
gist.github.com › 9a53bb00767a16d6646464c4b8249094
Create Github Secrets when you are not the owner and dont have access from the UI · GitHub
export SECRET_VALUE=SecretThatYouWouldLikeToStoreAndReferenceUsingTheSecretNameInActions · Run The Script · python github_create_secret.py -o repo_owner -r repo_name · List The Secrets (Only needs the export GITHUB_AUTHORIZATION_TOKEN=CreatePatFromGithubUi) python github_create_secret.py -o repo_owner -r repo_name -l ·
🌐
PyPI
pypi.org › project › python-git-secrets
python-git-secrets · PyPI
A pure Python library providing git-secrets functionality. We don't plan to do everything that git-secrets does (i.e. placing patterns in your .gitconfig file), but provide you with the building blocks for matching patterns you don't want exposed ...
      » pip install python-git-secrets
    
Published   Feb 17, 2020
Version   0.1.3
🌐
GitHub
github.com › futurice › secret
GitHub - futurice/secret: For managing secrets.
$ secret envs $ secret put hello world --env production $ secret get --env production · To enable verbose output for commands use --debug 1 argument. ... virtualenv py2venv --python=python2 source py2venv/bin/activate pip install -r requirements.txt pip install pytest mkdir -p ~/.secret/credentials echo """ [default] vault=secret vaultkey=alias/secret region=eu-central-1 """ > $HOME/.secret/credentials export AWS_PROFILE=default
Starred by 11 users
Forked by 2 users
Languages   Python 97.9% | Shell 2.1% | Python 97.9% | Shell 2.1%
🌐
Reddit
reddit.com › r/github › manage your github actions secrets, with a simple python script
r/github on Reddit: Manage your GitHub Actions secrets, with a simple Python script
April 15, 2020 -

Hi all,

I found myself struggling with managing the GitHub Actions secrets from UI, so I wrote a very simple Python script which acts as a CLI - https://github.com/unfor19/githubsecrets

Enjoy!

🌐
GitHub
github.com › anthonynsimon › secrets-vault
GitHub - anthonynsimon/secrets-vault: Simple encrypted secrets for Python
Simple encrypted secrets for Python. Contribute to anthonynsimon/secrets-vault development by creating an account on GitHub.
Author   anthonynsimon
🌐
GitHub
github.com › dmnd › secrets.py › blob › master › secrets.py
secrets.py/secrets.py at master · dmnd/secrets.py
#!/usr/bin/env python · · _HELP = """usage: secrets.py <command> · Commands: encrypt: Add new secrets. Overwrites the ciphertext · with a newly encrypted secrets.py · · decrypt: Discard changes to secrets.py. Overwrites · secrets.py by decrypting the ciphertext.
Author   dmnd
🌐
GitHub
github.com › unfor19 › githubsecrets
GitHub - unfor19/githubsecrets: Manage your GitHub Actions secrets with a simple CLI
$ sudo apt-get update && sudo apt-get install -y libdbus-glib-1-dev $ pip install secretstorage dbus-python keyring
Starred by 45 users
Forked by 5 users
Languages   Python 71.9% | Shell 16.5% | Dockerfile 11.6% | Python 71.9% | Shell 16.5% | Dockerfile 11.6%
🌐
Medium
saurabh-sawhney.medium.com › o-github-tell-me-your-secrets-c06130bd4c2e
O GitHub, tell me your secrets - Saurabh - Medium
November 30, 2023 - Thus, to give you an example, if your secret were “password”, (which is a surprisingly common secret, by the way), the GitHub runner logs would show it as ... And if you are too lazy to put away the gymweights by yourself, the GitHub logs will also show you a helpful python command that you can run on your local CLI or wherever, and that will restore and reveal THE_SECRET sans the disguise.
🌐
GitHub
github.com › jsdalton › secrets.py
GitHub - jsdalton/secrets.py: Simplified encryption and decryption of strings and files. · GitHub
>>> import secrets >>> msg = "One if by land; two if by sea" >>> key = "swordfish" >>> encrypted_msg = secrets.encrypt(key, msg) >>> encrypted_msg 'ZnSzzAj6q9Ug2bDWB3RBFjFCEANLgYUC9Ji/uVpx9n+GP9OVBRZIW+50M24J' >>> secrets.decrypt(key, encrypted_msg) 'One if by land; two if by sea'
Author   jsdalton