New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make twine get password from an env variable #144

Closed
jankatins opened this Issue Oct 22, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@jankatins
Contributor

jankatins commented Oct 22, 2015

I used twine with AppVoyer/travis and had to call it with --password %PYPI_PASS%, but this leaks the Password to the log :-(

I found a way not to leak it (calling it as @twine ... in batch files and set+x; twine ...; set -x in bash scripts), but it would be much easier if twine could get the things from environment variables...

@sigmavirus24 sigmavirus24 modified the milestone: next Oct 28, 2015

@jankatins jankatins changed the title from Make twine get password form a env variable to Make twine get password from an env variable Nov 5, 2015

@johnnoone

This comment has been minimized.

Show comment
Hide comment
@johnnoone

johnnoone Feb 3, 2016

It would be a nice improvement for any CI. For example it would let create specialized docker containers for building / publishing or let define masked variables into .travis.yml.

It is easy to implement this directly into argparse. here is a snippet that will fetch a value from --my-param cli parameter or a MY_PARAM environment variable:

import argparse


class EnvDefault(argparse.Action):
    """Get default from environment variable
    """

    def __init__(self, env, required=True, default=None, **kwargs):
        default = os.environ.get(env, default)
        self.env = env
        if default:
            required = False
        super().__init__(default=default, required=required, **kwargs)

    def __call__(self, parser, namespace, values, option_string=None):
        setattr(namespace, self.dest, values)


parser = argparse.ArgumentParser()
parser.add_argument('--my-param', action=EnvDefault, env='MY_PARAM',
                    help=('can also be specified using %(env)s '
                          'environment variable'))

johnnoone commented Feb 3, 2016

It would be a nice improvement for any CI. For example it would let create specialized docker containers for building / publishing or let define masked variables into .travis.yml.

It is easy to implement this directly into argparse. here is a snippet that will fetch a value from --my-param cli parameter or a MY_PARAM environment variable:

import argparse


class EnvDefault(argparse.Action):
    """Get default from environment variable
    """

    def __init__(self, env, required=True, default=None, **kwargs):
        default = os.environ.get(env, default)
        self.env = env
        if default:
            required = False
        super().__init__(default=default, required=required, **kwargs)

    def __call__(self, parser, namespace, values, option_string=None):
        setattr(namespace, self.dest, values)


parser = argparse.ArgumentParser()
parser.add_argument('--my-param', action=EnvDefault, env='MY_PARAM',
                    help=('can also be specified using %(env)s '
                          'environment variable'))
@jankatins

This comment has been minimized.

Show comment
Hide comment
@jankatins

jankatins Feb 3, 2016

Contributor

@johnnoone you should add this to the argparse directly, this is great!

I'll will to to make a PR for this and #143 ...

Contributor

jankatins commented Feb 3, 2016

@johnnoone you should add this to the argparse directly, this is great!

I'll will to to make a PR for this and #143 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment