In keep, make environment variables the defaults of several args
This commit is contained in:
41
keep
41
keep
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from barbicanclient import client
|
||||
|
||||
@@ -23,15 +24,23 @@ class Keep:
|
||||
choices=["order", "secret"],
|
||||
help="type to operate on")
|
||||
parser.add_argument('--auth_endpoint', '-A',
|
||||
help='the URL to authenticate against')
|
||||
parser.add_argument('--user', '-U', help='the user to authenticate as')
|
||||
parser.add_argument('--password', '-P',
|
||||
help='the API key or password to '
|
||||
'authenticate with')
|
||||
parser.add_argument('--tenant', '-T', help='the tenant ID')
|
||||
parser.add_argument('--endpoint', '-E',
|
||||
help='the URL of the barbican server')
|
||||
parser.add_argument('--token', '-K', help='the authentication token')
|
||||
default=env('OS_AUTH_URL'),
|
||||
help='the URL to authenticate against (default: '
|
||||
'%(default)s)')
|
||||
parser.add_argument('--user', '-U', default=env('OS_USERNAME'),
|
||||
help='the user to authenticate as (default: %(de'
|
||||
'fault)s)')
|
||||
parser.add_argument('--password', '-P', default=env('OS_PASSWORD'),
|
||||
help='the API key or password to authenticate with'
|
||||
' (default: %(default)s)')
|
||||
parser.add_argument('--tenant', '-T', default=env('OS_TENANT_NAME'),
|
||||
help='the tenant ID (default: %(default)s)')
|
||||
parser.add_argument('--endpoint', '-E', default=env('SERVICE_ENDPOINT')
|
||||
, help='the URL of the barbican server (default: %'
|
||||
'(default)s)')
|
||||
parser.add_argument('--token', '-K', default=env('SERVICE_TOKEN'),
|
||||
help='the authentication token (default: %(default'
|
||||
')s)')
|
||||
return parser
|
||||
|
||||
def add_create_args(self):
|
||||
@@ -152,6 +161,20 @@ class Keep:
|
||||
args.func(args)
|
||||
|
||||
|
||||
def env(*vars, **kwargs):
|
||||
"""Search for the first defined of possibly many env vars
|
||||
|
||||
Returns the first environment variable defined in vars, or
|
||||
returns the default defined in kwargs.
|
||||
|
||||
"""
|
||||
for v in vars:
|
||||
value = os.environ.get(v, None)
|
||||
if value:
|
||||
return value
|
||||
return kwargs.get('default', '')
|
||||
|
||||
|
||||
def main():
|
||||
k = Keep()
|
||||
k.execute()
|
||||
|
||||
Reference in New Issue
Block a user