cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
component-tests/util.py
27lines · modecode
| 1 | import logging |
| 2 | import os |
| 3 | import subprocess |
| 4 | import yaml |
| 5 | |
| 6 | LOGGER = logging.getLogger(__name__) |
| 7 | |
| 8 | def get_cloudflared(): |
| 9 | cfd_binary = os.getenv('CFD_BINARY') |
| 10 | return "cloudflared" if cfd_binary is None else cfd_binary |
| 11 | |
| 12 | |
| 13 | def write_config(path, config): |
| 14 | config_path = path / "config.yaml" |
| 15 | with open(config_path, 'w') as outfile: |
| 16 | yaml.dump(config, outfile) |
| 17 | return config_path |
| 18 | |
| 19 | |
| 20 | def start_cloudflared(path, config, args, pre_args=[]): |
| 21 | config_path = write_config(path, config) |
| 22 | cmd = [get_cloudflared()] |
| 23 | cmd += pre_args |
| 24 | cmd += ["--config", config_path] |
| 25 | cmd += args |
| 26 | LOGGER.info(f"Run cmd {cmd} with config {config}") |
| 27 | return subprocess.run(cmd, capture_output=True) |