Coverage for scripts / remove_customer.py: 0%
46 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 18:08 -0500
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 18:08 -0500
1#!/usr/bin/env python3
2"""
3Remove customers from a JSM service desk.
5Usage:
6 python remove_customer.py SD-1 --account-id 5b10ac8d82e05b22cc7d4ef5 --yes
7 python remove_customer.py SD-1 --account-id "id1,id2" --yes
8 python remove_customer.py SD-1 --account-id id1 --dry-run
9"""
11import sys
12import os
13import argparse
14from pathlib import Path
16sys.path.insert(0, str(Path(__file__).parent.parent.parent / 'shared' / 'scripts' / 'lib'))
18from config_manager import get_jira_client
19from error_handler import print_error, JiraError
20from formatters import print_success
23def parse_account_ids(account_id_string: str) -> list:
24 """
25 Parse comma-separated account IDs.
27 Args:
28 account_id_string: Comma-separated account IDs
30 Returns:
31 List of account IDs
32 """
33 return [id.strip() for id in account_id_string.split(',') if id.strip()]
36def remove_customer_from_service_desk(service_desk_id: str, account_ids: list,
37 profile: str = None) -> None:
38 """
39 Remove customers from a service desk.
41 Args:
42 service_desk_id: Service desk ID or key
43 account_ids: List of customer account IDs
44 profile: JIRA profile to use
45 """
46 with get_jira_client(profile) as client:
47 client.remove_customers_from_service_desk(service_desk_id, account_ids)
50def main():
51 """Main entry point."""
52 parser = argparse.ArgumentParser(
53 description='Remove customers from a JSM service desk',
54 formatter_class=argparse.RawDescriptionHelpFormatter,
55 epilog="""
56Examples:
57 Remove single customer (with confirmation skip):
58 %(prog)s SD-1 --account-id 5b10ac8d82e05b22cc7d4ef5 --yes
60 Remove multiple customers:
61 %(prog)s SD-1 --account-id "id1,id2" --yes
63 Dry-run:
64 %(prog)s SD-1 --account-id id1 --dry-run
65 """
66 )
68 parser.add_argument('service_desk_id',
69 help='Service desk ID or key (e.g., SD-1)')
70 parser.add_argument('--account-id', required=True,
71 help='Customer account ID(s) (comma-separated)')
72 parser.add_argument('--yes', '-y', action='store_true',
73 help='Skip confirmation prompt')
74 parser.add_argument('--dry-run', action='store_true',
75 help='Show what would be removed without removing')
76 parser.add_argument('--profile',
77 help='JIRA profile to use from config')
79 args = parser.parse_args()
81 try:
82 account_ids = parse_account_ids(args.account_id)
84 if not account_ids:
85 print_error("Invalid or empty account IDs")
86 return 1
88 if args.dry_run:
89 print("DRY RUN MODE - No changes will be made\n")
90 print(f"Would remove {len(account_ids)} customer(s) from service desk {args.service_desk_id}:")
91 for account_id in account_ids:
92 print(f" - {account_id}")
93 return 0
95 if not args.yes:
96 print_error("Confirmation required. Use --yes flag to confirm removal.")
97 return 1
99 remove_customer_from_service_desk(
100 service_desk_id=args.service_desk_id,
101 account_ids=account_ids,
102 profile=args.profile
103 )
105 print_success(f"Successfully removed {len(account_ids)} customer(s) from service desk {args.service_desk_id}")
107 return 0
109 except JiraError as e:
110 print_error(f"Failed to remove customer(s): {e}")
111 return 1
112 except Exception as e:
113 print_error(f"Unexpected error: {e}")
114 return 1
117if __name__ == '__main__':
118 sys.exit(main())