-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
79 lines (63 loc) · 2.46 KB
/
cli.py
File metadata and controls
79 lines (63 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Command-line interface for OSLC Sync Adapter."""
import argparse
import logging
import sys
from src.config_loader import load_config, get_gcm_config
from src.oslc_client import OSLCClient
from src.doors_connector import DoorsNextConnector
from src.jira_connector import JiraConnector
from src.sync_engine import SyncEngine, DoorsAdapter, JiraAdapter
from src.health_check import HealthCheck
from src.utils.logging_config import setup_logging
log = logging.getLogger(__name__)
def cmd_sync(args, config):
"""Run synchronization based on config rules."""
client = OSLCClient(
config["jazz_server"]["url"],
config["jazz_server"]["username"],
config["jazz_server"]["password"],
verify_ssl=config["jazz_server"].get("verify_ssl", True),
)
client.authenticate()
doors = DoorsNextConnector(client, config["doors_next"]["project_area"])
jira_cfg = config.get("jira", {})
jira = JiraConnector(
jira_cfg["base_url"], jira_cfg["username"],
jira_cfg["api_token"], jira_cfg["project_key"],
)
engine = SyncEngine(config)
for rule in config["sync_rules"]:
source_adapter = DoorsAdapter(doors)
target_adapter = JiraAdapter(jira)
results = engine.run_sync(source_adapter, target_adapter, rule)
log.info(f"Rule complete: {len(results)} operations")
def cmd_health(args, config):
"""Run health checks."""
client = OSLCClient(
config["jazz_server"]["url"],
config["jazz_server"]["username"],
config["jazz_server"]["password"],
)
hc = HealthCheck(client)
report = hc.run_all_checks()
print(f"Status: {report['overall']}")
for check in report["checks"]:
print(f" {check['check']}: {check['status']}")
def main():
parser = argparse.ArgumentParser(description="OSLC Sync Adapter")
parser.add_argument("--config", default="config.yaml", help="Config file path")
parser.add_argument("--verbose", "-v", action="store_true")
sub = parser.add_subparsers(dest="command")
sub.add_parser("sync", help="Run synchronization")
sub.add_parser("health", help="Run health checks")
args = parser.parse_args()
setup_logging(level=logging.DEBUG if args.verbose else logging.INFO)
config = load_config(args.config)
if args.command == "sync":
cmd_sync(args, config)
elif args.command == "health":
cmd_health(args, config)
else:
parser.print_help()
if __name__ == "__main__":
main()