def build_option_parser(self, description, version): parser = super(PythonSecretsApp, self).build_option_parser(description, version) # Global options _env = SecretsEnvironment() parser.add_argument('-d', '--secrets-basedir', metavar='<secrets-basedir>', dest='secrets_basedir', default=_env.secrets_basedir(), help="Root directory for holding secrets " + "(Env: D2_SECRETS_BASEDIR; default: {})".format( _env.secrets_basedir())) parser.add_argument( '-e', '--environment', metavar='<environment>', dest='environment', default=_env.environment(), help="Deployment environment selector " + "(Env: D2_ENVIRONMENT; default: {})".format(_env.environment())) parser.add_argument('-s', '--secrets-file', metavar='<secrets-file>', dest='secrets_file', default=_env.secrets_basename(), help="Secrets file (default: {})".format( _env.secrets_basename())) parser.add_argument('-P', '--env-var-prefix', metavar='<prefix>', dest='env_var_prefix', default=None, help="Prefix string for environment variables " + "(default: None)") parser.add_argument('-E', '--export-env-vars', action='store_true', dest='export_env_vars', default=False, help="Export secrets as environment variables " + "(default: False)") parser.add_argument('--init', action='store_true', dest='init', default=False, help="Initialize directory for holding secrets.") return parser
class Test_SecretsEnvironment_with_env_vars(unittest.TestCase): def setUp(self): self.cwd = os.getcwd() self.host = HOST self.keys_subdir = KEYS_SUBDIR self.envname = TESTENV self.basedir = os.path.join( HOME, SECRETS_SUBDIR if sys.platform.startswith('win') else '.' + SECRETS_SUBDIR) self.secrets_env = None with patch.dict('os.environ'): os.environ['D2_ENVIRONMENT'] = self.envname os.environ['D2_SECRETS_BASEDIR'] = self.basedir self.secrets_dir = secrets_dir(env=self.envname, basedir=self.basedir) self.keys_dir = keys_dir(secrets_dir=self.secrets_dir) self.keys_with_host_dir = keys_with_host_dir( keys_dir=self.keys_dir, host=self.host) self.secrets_env = SecretsEnvironment() def tearDown(self): pass def test_environment(self): self.assertEqual(self.secrets_env.environment(), self.envname) def test_environment_path(self): self.assertEqual(self.secrets_env.environment_path(), self.secrets_dir) def test_environment_path_subdir(self): self.assertEqual(self.secrets_env.environment_path(subdir=KEYS_SUBDIR), self.keys_dir) def test_environment_path_subdir_host(self): self.assertEqual( self.secrets_env.environment_path(subdir=KEYS_SUBDIR, host=HOST), self.keys_with_host_dir)