Coder Social home page Coder Social logo

envparse's People

Contributors

ivajloip avatar rconradharris avatar russelldavies avatar sloria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

envparse's Issues

Cannot parse dict with bool subtypes

I haven't found a way to parse dictionary with boolean subtypes.
The variable in .env file is:
FOO=bar1=true, bar2=false
and I parse it with env.dict('FOO', subcast=bool).

Expected result is
{'bar1':True, 'bar2':False}
but I get
{'bar1':True, 'bar2':True} instead.

The reason why this happens is that subcast is called as constructor and dict value is read as string so bool('false') evaluates to True.

The only way I found this working is specifing variable as
FOO=bar1=true, bar2=, but this would be too messy if i had more dict keys.

Another way to parse it as desired is to specify environment variable as json, but I don't want to do that.

Improve API for preprocessor

Hi,

instead of raising an error in pre processing method if env variable is not set, it would be useful to set the variable to None.

this raise an error

import random

from envparse import env


def get_secret_key(secret_key):
    if not secret_key:
        return "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$^&*(-_=+)") for i in range(50)])
    return secret_key


SECRET_KEY = env('SECRET_KEY', preprocessor=get_secret_key)

print(SECRET_KEY)

the solution I use, make the API is not pretty

SECRET_KEY = env('SECRET_KEY', preprocessor=get_secret_key, default=None)

Is there a reason to raise an exception instead or setting the env var to None ?

Thanks for reading me

Env file always overridden by environment

Problem

In Kubernetes, sensitive values cannot be safely stored in the containers environment as this is exposed to any who can view a pod's spec: this is usually a broad selection of people. However, they can be safely stored in Secrets, which can be safely mounted to files in the container: Secrets are usually encrypted at rest, and can have much tighter restriction on who can read/write them without impairing the maintenance of the cluster.

Unfortunately, file contents are lower priority than environment variables in envparse, meaning that anyone with the ability to write environment variables to a pod can supersede more sensitive/controlled values that have been set in an env file sourced from a mounted Secret.

Proposal

We can add a flag to the read_envfile method that will switch the behaviour from setdefault to a straight assignment, allowing people to choose to prioritise environment variables or env file contents when there is a conflict.

Allow existing env vars to be updated

We're using envparse in a Django project that uses consul-template to provide the env file. When config is updated in Consul, the env file is updated and we touch the WSGI file to (attempt to) pick up the new configuration.

However this doesn't work as env.read_envfile uses os.environ.setdefault so updates are never applied (as the env var already exists).

What's the reasoning for using setdefault instead of just setting directly. If that can't be changed, would you be open to passing an additional flag to read_envfile to allow updates? Am happy to write pull request.

Hash symbol breaks the line

I have this secret key (an example): DJANGO_SECRET_KEY=YwRqr;u|g_Qb3hEPRm/B6ry#bMb;-c,YmFaGsi>/s?rdhnc$M`

It contains #. When I try to use it, that's what I see:

>>> env('DJANGO_SECRET_KEY')
'YwRqr;u|g_Qb3hEPRm/B6ry'

Collaborative maintainership with Jazzband

Hi @rconradharris,

I noticed that there's a number of hanging issues and PRs nobody paid attention to in 3 years.

Have you considered finding another pair of hands to help you maintain envparse?

Better yet โ€” there's a project called @jazzband which could be a new home for this repo. It's a community of maintainers where multiple interested parties can collaborate on moving forward the projects that the original authors/maintainers have no resources to maintain anymore.

For more info, please read more at https://jazzband.co/about. I hope that it'll help reduce the frustration of many folks who'd like to see a couple of improvements to this project.

Have a nice day :)

Merge with the environs library?

Thank you for envparse. I liked its API so much that I implemented a successor library, environs, which uses marshmallow to do the heavy lifting for casting, validation, and serialization.

environ's API is near-identical to envparse, with a few differences:

environs was mostly written as a proof-of-concept, though at this point it is stable enough to use (it's only ~100SLOC after all).

I wonder if we could reduce duplication of effort by merging these two libraries. I haven't yet thought about the particulars; just wanted to open the table for discussion first.

Thoughts?

Can't access a full list of all variables

I would like to be able to access a full list of variables or just their names in order to log the configuration of the app at startup.
Is there some way to do this already? If not, can we add it?

Documentation needed for using `cast` for comma separated lists

Using envparse 0.16 on Python 2.7:

$ export foo="abc,def"
$ python
...
>>> from envparse import env
>>> env("foo", cast=list)
['a', 'b', 'c', ',', 'd', 'e', 'f']

Whereas I would have expected:
['abc', 'def']

Am I doing something wrong, or is this a bug?

read_envfile() recurses up the dir tree if path given, but file not found

When using read_envfile with path defined, the function still recurses up the directory tree if the given path is not found.

Consider the following code:

import envparse
envparse.env.read_envfile('myenv.conf')

The app runs from /home/test/code, which doesn't have myenv.conf file. The following debug log:

DEBUG:envfile not found at myenv.conf, looking in parent dir.
DEBUG:envfile not found at /home/test/myenv.conf, looking in parent dir.
DEBUG:envfile not found at /home/myenv.conf, looking in parent dir.
DEBUG:envfile not found at /myenv.conf, looking in parent dir.
UserWarning: Could not any envfile.

This is contrary to the documentation of the function. The function should not recurse if path is given, but file missing, or if it does this needs to be documented.

Adding a description about env vars

It would be helpful to add some description parameter to env vars so that on printing warning/exceptions we can show more details on env vars

Name your logger with a consistent name

I'm trying to raise the warning level of the envparse module but the logger is named after the file and so doesn't have a consistent name. Maybe just call it "envparse"?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.