def test_prefix(self): secrets = secrets_store_from_config( {"secrets.path": "/tmp/test", "test_secrets.path": "/tmp/secrets"}, prefix="test_secrets.", ) self.assertIsInstance(secrets, SecretsStore) self.assertEqual(secrets._filewatcher._path, "/tmp/secrets")
def main() -> None: arg_parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__) arg_parser.add_argument( "--debug", default=False, action="store_true", help="enable debug logging" ) arg_parser.add_argument( "config_file", type=argparse.FileType("r"), help="path to a configuration file" ) arg_parser.add_argument("source", type=argparse.FileType("rb"), help="file to upload") arg_parser.add_argument("dest", help="path in zookeeper") args = arg_parser.parse_args() if args.debug: level = logging.DEBUG else: level = logging.INFO logging.basicConfig(level=level, format="%(message)s") # quiet kazoo's verbose logs a bit logging.getLogger("kazoo").setLevel(logging.WARNING) parser = configparser.RawConfigParser(interpolation=EnvironmentInterpolation()) parser.read_file(args.config_file) watcher_config = dict(parser.items("live-data")) secrets = secrets_store_from_config(watcher_config) zookeeper = zookeeper_client_from_config(secrets, watcher_config) zookeeper.start() try: write_file_to_zookeeper(zookeeper, args.source, args.dest) except WriterError as exc: print(exc, file=sys.stderr) sys.exit(1) finally: zookeeper.stop()
def main() -> NoReturn: arg_parser = argparse.ArgumentParser( description=sys.modules[__name__].__doc__) arg_parser.add_argument("config_file", type=argparse.FileType("r"), help="path to a configuration file") arg_parser.add_argument("--debug", default=False, action="store_true", help="enable debug logging") args = arg_parser.parse_args() if args.debug: level = logging.DEBUG else: level = logging.INFO logging.basicConfig(level=level, format="%(message)s") # quiet kazoo's verbose logs a bit logging.getLogger("kazoo").setLevel(logging.WARNING) parser = configparser.RawConfigParser( interpolation=EnvironmentInterpolation()) parser.read_file(args.config_file) watcher_config = dict(parser.items("live-data")) cfg = config.parse_config( watcher_config, { "nodes": config.DictOf( { "source": config.String, "dest": config.String, "owner": config.Optional(config.UnixUser), "group": config.Optional(config.UnixGroup), "mode": config.Optional(config.Integer(base=8), default=0o400), # type: ignore }) }, ) # pylint: disable=maybe-no-member nodes = cfg.nodes.values() secrets = secrets_store_from_config(watcher_config, timeout=30) zookeeper = zookeeper_client_from_config(secrets, watcher_config, read_only=True) zookeeper.start() try: watch_zookeeper_nodes(zookeeper, nodes) finally: zookeeper.stop()
def test_make_store(self): secrets = secrets_store_from_config({ "secrets.path": "/tmp", "secrets.provider": "vault_csi" }) self.assertIsInstance(secrets, DirectorySecretsStore)
def test_make_store(self): secrets = secrets_store_from_config({"secrets.path": "/tmp/test"}) self.assertIsInstance(secrets, SecretsStore)