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