Forked from simon-weber/travis-secure-redefine.py
Last active
October 15, 2017 02:26
-
-
Save orf/c36cf78e71b5010561031d470bbd187c to your computer and use it in GitHub Desktop.
Python script to allow use of TravisCI secure arg variables that would normally be defined on each line of a build matrix, but are too large for the key size when combined.See https://github.com/travis-ci/travis-ci/issues/1736 for motivation. If you just need to secure a lot of sample data, do something like https://github.com/travis-ci/travis/i…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
""" | |
./%s 'cmd' <id-argname> <redef-argname> [<redef-argname>...] | |
Given the current environment: | |
IDARG=1 | |
FOO1=foovalue | |
BAR1=barvalue | |
FOO2=foo-unused | |
BAR2=bar-unused | |
The command: | |
./redefine 'ls -l' IDARG FOO BAR GAZ | |
Will run `ls -l` in a subprocess that uses the current environment with: | |
FOO=foovalue | |
BAR=barvalue | |
also included. | |
If cmd was executed, its return code will be used. | |
Code is licensed under the MIT license. | |
""" | |
import os | |
from subprocess import call | |
import sys | |
def redefine(arg_names, id_arg): | |
num = os.environ[id_arg] | |
for arg_name in arg_names: | |
with_num = arg_name + num | |
if with_num in os.environ: | |
os.environ[arg_name] = os.environ[with_num] | |
def show_help_and_exit(): | |
print(sys.modules[__name__].__doc__ % sys.argv[0]) | |
sys.exit(1) | |
if __name__ == '__main__': | |
if len(sys.argv) < 4: | |
show_help_and_exit() | |
redefine(sys.argv[3:], sys.argv[2]) | |
cmd_returncode = call(sys.argv[1].split(' ')) | |
sys.exit(cmd_returncode) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment