Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Simple app configuration via environment variables, in the spirit of argparse.
envappconfig is intended to provide simple configuration via environment variables, in the same spirit as argparse, which can be useful when developing and deploying 12-factor apps.
Features:
from envappconfig import EnvAppConfig
env = EnvAppConfig(description='Amazing app')
env.add_env('port', default=1234, transform=int, help='The listen port')
env.add_env('mirror', help='The URL to mirror')
config = env.configure()
# Returns PORT from os.environ transformed to an int,
# or 1234 if PORT does not exist.
config.port
# Returns MIRROR from os.environ,
# or displays usage at env.configure()
# if MIRROR does not exist, then exits.
config.mirror
If all the environment variables for the app have the same prefix, it can be specified with the prefix
parameter.
from envappconfig import EnvAppConfig
env = EnvAppConfig(prefix='MYAPP', description='Amazing app')
env.add_env('port', default=1234, transform=int, help='The listen port')
env.add_env('mirror', help='The URL to mirror')
config = env.configure()
# Returns MYAPP_PORT from os.environ transformed to an int,
# or 1234 if MYAPP_PORT does not exist.
config.port
# Returns MYAPP_MIRROR from os.environ,
# or displays usage at env.configure()
# if MYAPP_MIRROR does not exist, then exits.
config.mirror
The transform
parameter can be used to specify normal transforms, like int
or float
(the default is str
), but it can also take custom transform functions. The transform function must take a single parameter, which will be filled in with the string value from the environment variable.
env = EnvAppConfig(description='Amazing app')
# Double the timeout specified in the TIMEOUT environment variable,
# or default to 60.
env.add_env('timeout', default=60, transform=lambda x: int(x) * 2, help='Timeout in seconds')
...
Additional config values can be added to an existing namespace, which can be helpful when there's a config value that needs to be calculated based on other config values.
from envappconfig import EnvAppConfig
env = EnvAppConfig(description='Amazing app')
env.add_env('bind', help='IP address to bind to')
env.add_env('port', default=1234, transform=int, help='The listen port')
config = env.configure()
config.listen = f'{config.bind}:{config.port}'
# Returns the combined bind:port string.
config.listen
There are a couple options for using envappconfig at the command line (eg. when testing).
If you've only got a couple environment variables to set, just put them before the command:
PORT=9999 NAME=foo python3 script_using_envappconfig.py
If you have more environment variables to set, consider using dotenv
. First put your environment variables in a file named .env
:
PORT=9999
NAME=foo
Then call dotenv
as follows, which will load up the variables from .env
for this command:
dotenv run -- python3 script_using_envappconfig.py
You can install the dotenv
command line tool with:
python3 -m pip install "python-dotenv[cli]"
FAQs
Simple app configuration via environment variables, in the spirit of argparse.
We found that envappconfig demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.