handle missing variable in python way

This commit is contained in:
Verry Yann 2019-05-08 15:46:43 +02:00
parent f1ea651479
commit 8c3531880a
Signed by: yann
GPG key ID: 19754E8692B8416C

View file

@ -8,23 +8,7 @@
# - http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
# - https://gist.github.com/corny/8264b74a130eb663dbf3d3f0fe0e0ec9
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import hvac
import time, os
@ -136,30 +120,21 @@ formats = {
if __name__ == "__main__":
import sys
error = 0
vault_var = dict()
if os.environ['VAULT_SSHSIGNPATH']:
try:
vault_var['VAULT_SSHSIGNPATH'] = os.environ['VAULT_SSHSIGNPATH']
error = error + 1
if os.environ['VAULT_ADDR']:
vault_var['VAULT_ADDR'] = os.environ['VAULT_ADDR']
error = error + 1
except KeyError as e:
print('Error ' + str(e) + ' variable is missing')
try:
vault_var['VAULT_TOKEN'] = os.environ['VAULT_TOKEN']
error = error + 1
except KeyError:
from os.path import expanduser
home = expanduser("~")
o = open(home + '/.vault-token','r')
vault_var['VAULT_TOKEN'] = o.read().splitlines()[0]
error = error + 1
if error != 3:
print("Variable missing")
exit(1)
if len(sys.argv) > 1:
try: