pkgmgr-kunrunic 0.1.2.dev2__py3-none-any.whl → 0.1.2.dev5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pkgmgr/__init__.py +2 -1
- pkgmgr/cli.py +122 -2
- pkgmgr/config.py +340 -9
- pkgmgr/detection.py +1001 -0
- pkgmgr/release.py +77 -58
- pkgmgr/templates/pkgmgr.yaml.sample +55 -0
- pkgmgr/watch.py +1289 -2
- {pkgmgr_kunrunic-0.1.2.dev2.dist-info → pkgmgr_kunrunic-0.1.2.dev5.dist-info}/METADATA +120 -12
- pkgmgr_kunrunic-0.1.2.dev5.dist-info/RECORD +26 -0
- {pkgmgr_kunrunic-0.1.2.dev2.dist-info → pkgmgr_kunrunic-0.1.2.dev5.dist-info}/WHEEL +1 -1
- plugin/export_cksum.py +53 -31
- plugin/export_pkgstore.py +493 -47
- plugin/export_source_review.py +582 -59
- plugin/export_trivy_sbom.py +263 -0
- pkgmgr_kunrunic-0.1.2.dev2.dist-info/RECORD +0 -24
- {pkgmgr_kunrunic-0.1.2.dev2.dist-info → pkgmgr_kunrunic-0.1.2.dev5.dist-info}/entry_points.txt +0 -0
- {pkgmgr_kunrunic-0.1.2.dev2.dist-info → pkgmgr_kunrunic-0.1.2.dev5.dist-info}/licenses/LICENSE +0 -0
- {pkgmgr_kunrunic-0.1.2.dev2.dist-info → pkgmgr_kunrunic-0.1.2.dev5.dist-info}/top_level.txt +0 -0
pkgmgr/__init__.py
CHANGED
pkgmgr/cli.py
CHANGED
|
@@ -3,13 +3,17 @@ from __future__ import print_function
|
|
|
3
3
|
|
|
4
4
|
import os
|
|
5
5
|
import sys
|
|
6
|
+
import io
|
|
7
|
+
import time
|
|
8
|
+
import hashlib
|
|
9
|
+
from contextlib import redirect_stdout
|
|
6
10
|
|
|
7
11
|
try:
|
|
8
12
|
import argparse
|
|
9
13
|
except Exception:
|
|
10
14
|
argparse = None
|
|
11
15
|
|
|
12
|
-
from . import config, snapshot, release, watch, __version__
|
|
16
|
+
from . import config, snapshot, release, watch, detection, __version__
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
def _add_make_config(sub):
|
|
@@ -35,7 +39,7 @@ def _add_install(sub):
|
|
|
35
39
|
|
|
36
40
|
def _add_snapshot(sub):
|
|
37
41
|
p = sub.add_parser(
|
|
38
|
-
"snapshot", help="take a snapshot (
|
|
42
|
+
"snapshot", help="take a standalone snapshot (does not modify baseline)"
|
|
39
43
|
)
|
|
40
44
|
p.add_argument(
|
|
41
45
|
"--config",
|
|
@@ -55,6 +59,41 @@ def _add_actions(sub):
|
|
|
55
59
|
p.set_defaults(func=_handle_actions)
|
|
56
60
|
|
|
57
61
|
|
|
62
|
+
def _add_detect(sub):
|
|
63
|
+
p = sub.add_parser("detect", help="detect unmanaged or not-yet-updated changes")
|
|
64
|
+
p.add_argument(
|
|
65
|
+
"--config",
|
|
66
|
+
default=None,
|
|
67
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
68
|
+
)
|
|
69
|
+
p.set_defaults(func=_handle_detect)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _add_telegram(sub):
|
|
73
|
+
p = sub.add_parser("telegram", help="telegram registration/approval helpers")
|
|
74
|
+
p.add_argument(
|
|
75
|
+
"--config",
|
|
76
|
+
default=None,
|
|
77
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
78
|
+
)
|
|
79
|
+
tsp = p.add_subparsers(dest="telegram_cmd")
|
|
80
|
+
|
|
81
|
+
p_poll = tsp.add_parser("poll", help="poll telegram bot updates and process registration commands")
|
|
82
|
+
p_poll.add_argument("--once", action="store_true", help="process one poll cycle then exit")
|
|
83
|
+
p_poll.set_defaults(func=_handle_telegram_poll)
|
|
84
|
+
|
|
85
|
+
p_list = tsp.add_parser("list", help="show approved/pending telegram subscribers")
|
|
86
|
+
p_list.set_defaults(func=_handle_telegram_list)
|
|
87
|
+
|
|
88
|
+
p_ap = tsp.add_parser("approve", help="approve pending subscriber")
|
|
89
|
+
p_ap.add_argument("chat_id", help="target chat id")
|
|
90
|
+
p_ap.set_defaults(func=_handle_telegram_approve)
|
|
91
|
+
|
|
92
|
+
p_rj = tsp.add_parser("reject", help="reject pending subscriber")
|
|
93
|
+
p_rj.add_argument("chat_id", help="target chat id")
|
|
94
|
+
p_rj.set_defaults(func=_handle_telegram_reject)
|
|
95
|
+
|
|
96
|
+
|
|
58
97
|
def _add_create_pkg(sub):
|
|
59
98
|
p = sub.add_parser("create-pkg", help="create a pkg folder and template")
|
|
60
99
|
p.add_argument("pkg_id", help="package identifier (e.g. 20240601)")
|
|
@@ -204,11 +243,15 @@ def build_parser():
|
|
|
204
243
|
|
|
205
244
|
_add_make_config(sub)
|
|
206
245
|
_add_install(sub)
|
|
246
|
+
_add_snapshot(sub)
|
|
207
247
|
_add_create_pkg(sub)
|
|
208
248
|
_add_update_pkg(sub)
|
|
209
249
|
_add_close_pkg(sub)
|
|
210
250
|
_add_delete_pkg(sub)
|
|
251
|
+
_add_watch(sub)
|
|
211
252
|
_add_actions(sub)
|
|
253
|
+
_add_detect(sub)
|
|
254
|
+
_add_telegram(sub)
|
|
212
255
|
return parser
|
|
213
256
|
|
|
214
257
|
|
|
@@ -250,6 +293,7 @@ def _handle_create_pkg(args):
|
|
|
250
293
|
cfg = config.load_main(args.config)
|
|
251
294
|
release.create_pkg(cfg, args.pkg_id)
|
|
252
295
|
_run_auto_actions(cfg, "create_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "create_pkg"})
|
|
296
|
+
watch.notify_lifecycle_event(cfg, "create_pkg", pkg_id=args.pkg_id)
|
|
253
297
|
return 0
|
|
254
298
|
|
|
255
299
|
def _handle_update_pkg(args):
|
|
@@ -306,6 +350,12 @@ def _handle_update_pkg(args):
|
|
|
306
350
|
config_path=args.config,
|
|
307
351
|
context={"pkg_id": args.pkg_id, "event": "cancel_pkg_release", "release": args.cancel},
|
|
308
352
|
)
|
|
353
|
+
watch.notify_lifecycle_event(
|
|
354
|
+
cfg,
|
|
355
|
+
"cancel_pkg_release",
|
|
356
|
+
pkg_id=args.pkg_id,
|
|
357
|
+
details={"release": args.cancel, "root": args.root or "all"},
|
|
358
|
+
)
|
|
309
359
|
return 0
|
|
310
360
|
if args.release:
|
|
311
361
|
active_roots = release.list_active_release_roots(cfg, args.pkg_id)
|
|
@@ -330,9 +380,13 @@ def _handle_update_pkg(args):
|
|
|
330
380
|
return 0
|
|
331
381
|
release.finalize_pkg_release(cfg, args.pkg_id, roots=roots)
|
|
332
382
|
_run_auto_actions(cfg, "update_pkg_release", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "update_pkg_release"})
|
|
383
|
+
watch.notify_lifecycle_event(
|
|
384
|
+
cfg, "update_pkg_release", pkg_id=args.pkg_id, details={"roots": ",".join(roots)}
|
|
385
|
+
)
|
|
333
386
|
return 0
|
|
334
387
|
release.update_pkg(cfg, args.pkg_id)
|
|
335
388
|
_run_auto_actions(cfg, "update_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "update_pkg"})
|
|
389
|
+
watch.notify_lifecycle_event(cfg, "update_pkg", pkg_id=args.pkg_id)
|
|
336
390
|
return 0
|
|
337
391
|
|
|
338
392
|
|
|
@@ -340,6 +394,7 @@ def _handle_close_pkg(args):
|
|
|
340
394
|
cfg = config.load_main(args.config)
|
|
341
395
|
release.close_pkg(cfg, args.pkg_id)
|
|
342
396
|
_run_auto_actions(cfg, "close_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "close_pkg"})
|
|
397
|
+
watch.notify_lifecycle_event(cfg, "close_pkg", pkg_id=args.pkg_id)
|
|
343
398
|
return 0
|
|
344
399
|
|
|
345
400
|
|
|
@@ -347,6 +402,7 @@ def _handle_delete_pkg(args):
|
|
|
347
402
|
cfg = config.load_main(args.config)
|
|
348
403
|
release.delete_pkg(cfg, args.pkg_id)
|
|
349
404
|
_run_auto_actions(cfg, "delete_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "delete_pkg"})
|
|
405
|
+
watch.notify_lifecycle_event(cfg, "delete_pkg", pkg_id=args.pkg_id)
|
|
350
406
|
return 0
|
|
351
407
|
|
|
352
408
|
|
|
@@ -383,6 +439,70 @@ def _handle_actions(args):
|
|
|
383
439
|
return 0
|
|
384
440
|
|
|
385
441
|
|
|
442
|
+
def _handle_detect(args):
|
|
443
|
+
cfg = config.load_main(args.config)
|
|
444
|
+
buf = io.StringIO()
|
|
445
|
+
with redirect_stdout(buf):
|
|
446
|
+
result = detection.run(cfg)
|
|
447
|
+
text = buf.getvalue()
|
|
448
|
+
if text:
|
|
449
|
+
sys.stdout.write(text)
|
|
450
|
+
if not text.endswith("\n"):
|
|
451
|
+
sys.stdout.write("\n")
|
|
452
|
+
_save_detect_report(cfg, text)
|
|
453
|
+
return int(result.get("exit_code", 0))
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def _handle_telegram_poll(args):
|
|
457
|
+
cfg = config.load_main(args.config)
|
|
458
|
+
return watch.telegram_poll(cfg, run_once=bool(args.once))
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def _handle_telegram_list(args):
|
|
462
|
+
cfg = config.load_main(args.config)
|
|
463
|
+
return watch.telegram_list(cfg)
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def _handle_telegram_approve(args):
|
|
467
|
+
cfg = config.load_main(args.config)
|
|
468
|
+
return watch.telegram_approve(cfg, args.chat_id)
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def _handle_telegram_reject(args):
|
|
472
|
+
cfg = config.load_main(args.config)
|
|
473
|
+
return watch.telegram_reject(cfg, args.chat_id)
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def _save_detect_report(cfg, text):
|
|
477
|
+
detection_cfg = cfg.get("detection") if isinstance(cfg.get("detection"), dict) else {}
|
|
478
|
+
report_path = detection_cfg.get("report_file")
|
|
479
|
+
if not report_path:
|
|
480
|
+
return
|
|
481
|
+
out_path = os.path.abspath(os.path.expanduser(str(report_path)))
|
|
482
|
+
parent = os.path.dirname(out_path)
|
|
483
|
+
if parent and not os.path.exists(parent):
|
|
484
|
+
os.makedirs(parent)
|
|
485
|
+
existing = None
|
|
486
|
+
if os.path.isfile(out_path):
|
|
487
|
+
try:
|
|
488
|
+
with open(out_path, "r", encoding="utf-8", errors="replace") as f:
|
|
489
|
+
existing = f.read()
|
|
490
|
+
except Exception:
|
|
491
|
+
existing = None
|
|
492
|
+
if existing == text:
|
|
493
|
+
return
|
|
494
|
+
if existing is not None:
|
|
495
|
+
ts = time.strftime("%Y%m%d_%H%M%S", time.localtime())
|
|
496
|
+
backup_path = out_path + ".bak_" + ts
|
|
497
|
+
with open(backup_path, "w", encoding="utf-8") as bf:
|
|
498
|
+
bf.write(existing)
|
|
499
|
+
digest = hashlib.sha256(existing.encode("utf-8")).hexdigest()[:12]
|
|
500
|
+
print("[detect] backup saved: %s (sha256=%s)" % (backup_path, digest))
|
|
501
|
+
with open(out_path, "w", encoding="utf-8") as f:
|
|
502
|
+
f.write(text or "")
|
|
503
|
+
print("[detect] report saved: %s" % out_path)
|
|
504
|
+
|
|
505
|
+
|
|
386
506
|
def _run_auto_actions(cfg, event, config_path=None, context=None):
|
|
387
507
|
auto_actions = cfg.get("auto_actions") or {}
|
|
388
508
|
names = auto_actions.get(event) or []
|
pkgmgr/config.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import print_function
|
|
|
3
3
|
|
|
4
4
|
import glob
|
|
5
5
|
import os
|
|
6
|
+
import re
|
|
6
7
|
import sys
|
|
7
8
|
import textwrap
|
|
8
9
|
|
|
@@ -60,6 +61,46 @@ artifacts:
|
|
|
60
61
|
watch:
|
|
61
62
|
interval_sec: 60
|
|
62
63
|
on_change: [] # optional list of action names to run on change (poller)
|
|
64
|
+
detect: true
|
|
65
|
+
telegram:
|
|
66
|
+
enabled: false
|
|
67
|
+
bot_token: ""
|
|
68
|
+
tls_verify: true
|
|
69
|
+
ca_file: null
|
|
70
|
+
subscribers_file: ~/pkgmgr/config/telegram-subscribers.yaml
|
|
71
|
+
admin_chat_ids: []
|
|
72
|
+
chat_id: "" # fallback only (read-only compatibility)
|
|
73
|
+
chat_ids: [] # fallback only (read-only compatibility)
|
|
74
|
+
message_prefix: "[pkgmgr]"
|
|
75
|
+
notify_on: [fail, warn]
|
|
76
|
+
dedup: true
|
|
77
|
+
registration:
|
|
78
|
+
enabled: true
|
|
79
|
+
auto_reply: true
|
|
80
|
+
notify_admin_on_start: true
|
|
81
|
+
channels:
|
|
82
|
+
detect:
|
|
83
|
+
enabled: true
|
|
84
|
+
message_file: null
|
|
85
|
+
max_chars: 3800
|
|
86
|
+
wrap_width: 72
|
|
87
|
+
message_file_max_lines: 120
|
|
88
|
+
lifecycle:
|
|
89
|
+
enabled: false
|
|
90
|
+
events: [create_pkg, update_pkg, update_pkg_release, cancel_pkg_release, close_pkg, delete_pkg]
|
|
91
|
+
git:
|
|
92
|
+
enabled: false
|
|
93
|
+
repo_root: null
|
|
94
|
+
branches: []
|
|
95
|
+
jenkins:
|
|
96
|
+
enabled: false
|
|
97
|
+
notify_on: [started, failed, success]
|
|
98
|
+
notify_on_first_seen: false
|
|
99
|
+
jobs: []
|
|
100
|
+
file_watch:
|
|
101
|
+
enabled: false
|
|
102
|
+
max_chars: 3000
|
|
103
|
+
files: []
|
|
63
104
|
|
|
64
105
|
collectors:
|
|
65
106
|
enabled: ["checksums"]
|
|
@@ -84,7 +125,17 @@ auto_actions:
|
|
|
84
125
|
create_pkg: []
|
|
85
126
|
update_pkg: []
|
|
86
127
|
update_pkg_release: []
|
|
128
|
+
cancel_pkg_release: []
|
|
129
|
+
delete_pkg: []
|
|
87
130
|
close_pkg: []
|
|
131
|
+
|
|
132
|
+
detection:
|
|
133
|
+
enabled: true
|
|
134
|
+
system: null
|
|
135
|
+
report_file: ~/pkgmgr/local/state/detect/detect-report.txt
|
|
136
|
+
ignore: []
|
|
137
|
+
fail_on: [TRACKED_CHANGED_NOT_IN_PKG, UNTRACKED_NOT_IN_PKG, AMBIGUOUS_PKG]
|
|
138
|
+
warn_on: [CHANGED_NOT_UPDATED, DELETED_NOT_UPDATED]
|
|
88
139
|
"""
|
|
89
140
|
|
|
90
141
|
PKG_TEMPLATE = """\
|
|
@@ -112,7 +163,57 @@ MAIN_DEFAULTS = {
|
|
|
112
163
|
"sources": [],
|
|
113
164
|
"source": {"exclude": []},
|
|
114
165
|
"artifacts": {"root": None, "targets": [], "exclude": []},
|
|
115
|
-
"watch": {
|
|
166
|
+
"watch": {
|
|
167
|
+
"interval_sec": 60,
|
|
168
|
+
"on_change": [],
|
|
169
|
+
"detect": True,
|
|
170
|
+
"telegram": {
|
|
171
|
+
"enabled": False,
|
|
172
|
+
"bot_token": "",
|
|
173
|
+
"tls_verify": True,
|
|
174
|
+
"ca_file": None,
|
|
175
|
+
"subscribers_file": os.path.join(DEFAULT_CONFIG_DIR, "telegram-subscribers.yaml"),
|
|
176
|
+
"admin_chat_ids": [],
|
|
177
|
+
"chat_id": "",
|
|
178
|
+
"chat_ids": [],
|
|
179
|
+
"message_prefix": "[pkgmgr]",
|
|
180
|
+
"notify_on": ["fail", "warn"],
|
|
181
|
+
"dedup": True,
|
|
182
|
+
"registration": {
|
|
183
|
+
"enabled": True,
|
|
184
|
+
"auto_reply": True,
|
|
185
|
+
"notify_admin_on_start": True,
|
|
186
|
+
},
|
|
187
|
+
"channels": {
|
|
188
|
+
"detect": {
|
|
189
|
+
"enabled": True,
|
|
190
|
+
"message_file": None,
|
|
191
|
+
"max_chars": 3800,
|
|
192
|
+
"wrap_width": 72,
|
|
193
|
+
"message_file_max_lines": 120,
|
|
194
|
+
},
|
|
195
|
+
"lifecycle": {
|
|
196
|
+
"enabled": False,
|
|
197
|
+
"events": [
|
|
198
|
+
"create_pkg",
|
|
199
|
+
"update_pkg",
|
|
200
|
+
"update_pkg_release",
|
|
201
|
+
"cancel_pkg_release",
|
|
202
|
+
"close_pkg",
|
|
203
|
+
"delete_pkg",
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
"git": {"enabled": False, "repo_root": None, "branches": []},
|
|
207
|
+
"jenkins": {
|
|
208
|
+
"enabled": False,
|
|
209
|
+
"notify_on": ["started", "failed", "success"],
|
|
210
|
+
"notify_on_first_seen": False,
|
|
211
|
+
"jobs": [],
|
|
212
|
+
},
|
|
213
|
+
"file_watch": {"enabled": False, "max_chars": 3000, "files": []},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
116
217
|
"collectors": {"enabled": ["checksums"]},
|
|
117
218
|
"actions": {},
|
|
118
219
|
"auto_actions": {
|
|
@@ -123,6 +224,18 @@ MAIN_DEFAULTS = {
|
|
|
123
224
|
"close_pkg": [],
|
|
124
225
|
"delete_pkg": [],
|
|
125
226
|
},
|
|
227
|
+
"detection": {
|
|
228
|
+
"enabled": True,
|
|
229
|
+
"system": None,
|
|
230
|
+
"report_file": os.path.join(DEFAULT_STATE_DIR, "detect", "detect-report.txt"),
|
|
231
|
+
"ignore": [],
|
|
232
|
+
"fail_on": [
|
|
233
|
+
"TRACKED_CHANGED_NOT_IN_PKG",
|
|
234
|
+
"UNTRACKED_NOT_IN_PKG",
|
|
235
|
+
"AMBIGUOUS_PKG",
|
|
236
|
+
],
|
|
237
|
+
"warn_on": ["CHANGED_NOT_UPDATED", "DELETED_NOT_UPDATED"],
|
|
238
|
+
},
|
|
126
239
|
}
|
|
127
240
|
|
|
128
241
|
|
|
@@ -183,7 +296,150 @@ def _validate_watch(watch_cfg):
|
|
|
183
296
|
except Exception:
|
|
184
297
|
interval = MAIN_DEFAULTS["watch"]["interval_sec"]
|
|
185
298
|
on_change = _ensure_list_of_strings(watch.get("on_change"), "watch.on_change")
|
|
186
|
-
|
|
299
|
+
detect_enabled = watch.get("detect", MAIN_DEFAULTS["watch"]["detect"])
|
|
300
|
+
telegram_cfg = watch.get("telegram") if isinstance(watch.get("telegram"), dict) else {}
|
|
301
|
+
notify_on = _ensure_list_of_strings(
|
|
302
|
+
telegram_cfg.get("notify_on", MAIN_DEFAULTS["watch"]["telegram"]["notify_on"]),
|
|
303
|
+
"watch.telegram.notify_on",
|
|
304
|
+
)
|
|
305
|
+
subscribers_file = str(
|
|
306
|
+
telegram_cfg.get("subscribers_file", MAIN_DEFAULTS["watch"]["telegram"]["subscribers_file"]) or ""
|
|
307
|
+
)
|
|
308
|
+
admin_chat_ids = _ensure_list_of_strings(
|
|
309
|
+
telegram_cfg.get("admin_chat_ids", MAIN_DEFAULTS["watch"]["telegram"]["admin_chat_ids"]),
|
|
310
|
+
"watch.telegram.admin_chat_ids",
|
|
311
|
+
)
|
|
312
|
+
registration_cfg = telegram_cfg.get("registration") if isinstance(telegram_cfg.get("registration"), dict) else {}
|
|
313
|
+
chat_ids = _ensure_list_of_strings(
|
|
314
|
+
telegram_cfg.get("chat_ids", MAIN_DEFAULTS["watch"]["telegram"]["chat_ids"]),
|
|
315
|
+
"watch.telegram.chat_ids",
|
|
316
|
+
)
|
|
317
|
+
chat_id_single = str(telegram_cfg.get("chat_id") or "")
|
|
318
|
+
if chat_id_single and chat_id_single not in chat_ids:
|
|
319
|
+
chat_ids.append(chat_id_single)
|
|
320
|
+
channels_cfg = telegram_cfg.get("channels") if isinstance(telegram_cfg.get("channels"), dict) else {}
|
|
321
|
+
lifecycle_cfg = channels_cfg.get("lifecycle") if isinstance(channels_cfg.get("lifecycle"), dict) else {}
|
|
322
|
+
git_channel_cfg = channels_cfg.get("git") if isinstance(channels_cfg.get("git"), dict) else {}
|
|
323
|
+
jenkins_cfg = channels_cfg.get("jenkins") if isinstance(channels_cfg.get("jenkins"), dict) else {}
|
|
324
|
+
file_watch_cfg = channels_cfg.get("file_watch") if isinstance(channels_cfg.get("file_watch"), dict) else {}
|
|
325
|
+
detect_chan_cfg = channels_cfg.get("detect") if isinstance(channels_cfg.get("detect"), dict) else {}
|
|
326
|
+
jenkins_jobs = jenkins_cfg.get("jobs") if isinstance(jenkins_cfg.get("jobs"), list) else []
|
|
327
|
+
normalized_jobs = []
|
|
328
|
+
for idx, job in enumerate(jenkins_jobs):
|
|
329
|
+
if isinstance(job, str):
|
|
330
|
+
normalized_jobs.append({"name": str(job), "url": str(job), "user": "", "api_token": ""})
|
|
331
|
+
continue
|
|
332
|
+
if not isinstance(job, dict):
|
|
333
|
+
raise RuntimeError("watch.telegram.channels.jenkins.jobs[%d] must be string or mapping" % idx)
|
|
334
|
+
normalized_jobs.append(
|
|
335
|
+
{
|
|
336
|
+
"name": str(job.get("name") or job.get("url") or ""),
|
|
337
|
+
"url": str(job.get("url") or ""),
|
|
338
|
+
"user": str(job.get("user") or ""),
|
|
339
|
+
"api_token": str(job.get("api_token") or ""),
|
|
340
|
+
}
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
file_specs = file_watch_cfg.get("files") if isinstance(file_watch_cfg.get("files"), list) else []
|
|
344
|
+
normalized_files = []
|
|
345
|
+
for idx, item in enumerate(file_specs):
|
|
346
|
+
if isinstance(item, str):
|
|
347
|
+
normalized_files.append({"path": str(item), "encoding": "utf-8"})
|
|
348
|
+
continue
|
|
349
|
+
if not isinstance(item, dict):
|
|
350
|
+
raise RuntimeError("watch.telegram.channels.file_watch.files[%d] must be string or mapping" % idx)
|
|
351
|
+
normalized_files.append(
|
|
352
|
+
{
|
|
353
|
+
"path": str(item.get("path") or ""),
|
|
354
|
+
"encoding": str(item.get("encoding") or "utf-8"),
|
|
355
|
+
}
|
|
356
|
+
)
|
|
357
|
+
return {
|
|
358
|
+
"interval_sec": interval,
|
|
359
|
+
"on_change": on_change,
|
|
360
|
+
"detect": bool(detect_enabled),
|
|
361
|
+
"telegram": {
|
|
362
|
+
"enabled": bool(telegram_cfg.get("enabled", MAIN_DEFAULTS["watch"]["telegram"]["enabled"])),
|
|
363
|
+
"bot_token": str(telegram_cfg.get("bot_token") or ""),
|
|
364
|
+
"tls_verify": bool(telegram_cfg.get("tls_verify", MAIN_DEFAULTS["watch"]["telegram"]["tls_verify"])),
|
|
365
|
+
"ca_file": str(telegram_cfg.get("ca_file") or "") or None,
|
|
366
|
+
"subscribers_file": subscribers_file or MAIN_DEFAULTS["watch"]["telegram"]["subscribers_file"],
|
|
367
|
+
"admin_chat_ids": admin_chat_ids,
|
|
368
|
+
"chat_id": str(telegram_cfg.get("chat_id") or ""),
|
|
369
|
+
"chat_ids": chat_ids,
|
|
370
|
+
"message_prefix": str(
|
|
371
|
+
telegram_cfg.get("message_prefix", MAIN_DEFAULTS["watch"]["telegram"]["message_prefix"]) or ""
|
|
372
|
+
),
|
|
373
|
+
"notify_on": [n.lower() for n in notify_on if n],
|
|
374
|
+
"dedup": bool(telegram_cfg.get("dedup", MAIN_DEFAULTS["watch"]["telegram"]["dedup"])),
|
|
375
|
+
"registration": {
|
|
376
|
+
"enabled": bool(
|
|
377
|
+
registration_cfg.get(
|
|
378
|
+
"enabled",
|
|
379
|
+
MAIN_DEFAULTS["watch"]["telegram"]["registration"]["enabled"],
|
|
380
|
+
)
|
|
381
|
+
),
|
|
382
|
+
"auto_reply": bool(
|
|
383
|
+
registration_cfg.get(
|
|
384
|
+
"auto_reply",
|
|
385
|
+
MAIN_DEFAULTS["watch"]["telegram"]["registration"]["auto_reply"],
|
|
386
|
+
)
|
|
387
|
+
),
|
|
388
|
+
"notify_admin_on_start": bool(
|
|
389
|
+
registration_cfg.get(
|
|
390
|
+
"notify_admin_on_start",
|
|
391
|
+
MAIN_DEFAULTS["watch"]["telegram"]["registration"]["notify_admin_on_start"],
|
|
392
|
+
)
|
|
393
|
+
),
|
|
394
|
+
},
|
|
395
|
+
"channels": {
|
|
396
|
+
"detect": {
|
|
397
|
+
"enabled": bool(detect_chan_cfg.get("enabled", True)),
|
|
398
|
+
"message_file": str(detect_chan_cfg.get("message_file") or "") or None,
|
|
399
|
+
"max_chars": int(detect_chan_cfg.get("max_chars", 3800) or 3800),
|
|
400
|
+
"wrap_width": int(detect_chan_cfg.get("wrap_width", 72) or 72),
|
|
401
|
+
"message_file_max_lines": int(detect_chan_cfg.get("message_file_max_lines", 120) or 120),
|
|
402
|
+
},
|
|
403
|
+
"lifecycle": {
|
|
404
|
+
"enabled": bool(lifecycle_cfg.get("enabled", False)),
|
|
405
|
+
"events": _ensure_list_of_strings(
|
|
406
|
+
lifecycle_cfg.get("events", MAIN_DEFAULTS["watch"]["telegram"]["channels"]["lifecycle"]["events"]),
|
|
407
|
+
"watch.telegram.channels.lifecycle.events",
|
|
408
|
+
),
|
|
409
|
+
},
|
|
410
|
+
"git": {
|
|
411
|
+
"enabled": bool(git_channel_cfg.get("enabled", False)),
|
|
412
|
+
"repo_root": str(git_channel_cfg.get("repo_root") or "") or None,
|
|
413
|
+
"branches": _ensure_list_of_strings(
|
|
414
|
+
git_channel_cfg.get("branches", MAIN_DEFAULTS["watch"]["telegram"]["channels"]["git"]["branches"]),
|
|
415
|
+
"watch.telegram.channels.git.branches",
|
|
416
|
+
),
|
|
417
|
+
},
|
|
418
|
+
"jenkins": {
|
|
419
|
+
"enabled": bool(jenkins_cfg.get("enabled", False)),
|
|
420
|
+
"notify_on": [
|
|
421
|
+
n.lower()
|
|
422
|
+
for n in _ensure_list_of_strings(
|
|
423
|
+
jenkins_cfg.get("notify_on", MAIN_DEFAULTS["watch"]["telegram"]["channels"]["jenkins"]["notify_on"]),
|
|
424
|
+
"watch.telegram.channels.jenkins.notify_on",
|
|
425
|
+
)
|
|
426
|
+
],
|
|
427
|
+
"notify_on_first_seen": bool(
|
|
428
|
+
jenkins_cfg.get(
|
|
429
|
+
"notify_on_first_seen",
|
|
430
|
+
MAIN_DEFAULTS["watch"]["telegram"]["channels"]["jenkins"]["notify_on_first_seen"],
|
|
431
|
+
)
|
|
432
|
+
),
|
|
433
|
+
"jobs": normalized_jobs,
|
|
434
|
+
},
|
|
435
|
+
"file_watch": {
|
|
436
|
+
"enabled": bool(file_watch_cfg.get("enabled", False)),
|
|
437
|
+
"max_chars": int(file_watch_cfg.get("max_chars", MAIN_DEFAULTS["watch"]["telegram"]["channels"]["file_watch"]["max_chars"]) or 3000),
|
|
438
|
+
"files": normalized_files,
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
}
|
|
187
443
|
|
|
188
444
|
|
|
189
445
|
def _validate_auto_actions(auto_actions):
|
|
@@ -239,6 +495,19 @@ def _validate_main_config(data):
|
|
|
239
495
|
|
|
240
496
|
cfg["actions"] = _validate_actions(cfg.get("actions"))
|
|
241
497
|
cfg["auto_actions"] = _validate_auto_actions(cfg.get("auto_actions"))
|
|
498
|
+
detection_cfg = cfg.get("detection") if isinstance(cfg.get("detection"), dict) else {}
|
|
499
|
+
enabled = detection_cfg.get("enabled", True)
|
|
500
|
+
cfg["detection"] = {
|
|
501
|
+
"enabled": bool(enabled),
|
|
502
|
+
"system": str(detection_cfg.get("system") or "") or None,
|
|
503
|
+
"report_file": str(
|
|
504
|
+
detection_cfg.get("report_file", MAIN_DEFAULTS["detection"]["report_file"]) or ""
|
|
505
|
+
)
|
|
506
|
+
or None,
|
|
507
|
+
"ignore": _ensure_list_of_strings(detection_cfg.get("ignore"), "detection.ignore"),
|
|
508
|
+
"fail_on": _ensure_list_of_strings(detection_cfg.get("fail_on"), "detection.fail_on"),
|
|
509
|
+
"warn_on": _ensure_list_of_strings(detection_cfg.get("warn_on"), "detection.warn_on"),
|
|
510
|
+
}
|
|
242
511
|
|
|
243
512
|
return cfg
|
|
244
513
|
|
|
@@ -313,15 +582,58 @@ def write_pkg_template(path, pkg_id=None, pkg_root=None, include_releases=None,
|
|
|
313
582
|
print("[create-pkg] wrote pkg config to %s" % target)
|
|
314
583
|
|
|
315
584
|
|
|
316
|
-
def
|
|
317
|
-
"""Load a pkg.yaml file."""
|
|
585
|
+
def _load_yaml_with_fallback(path, encodings=None):
|
|
318
586
|
if yaml is None:
|
|
319
587
|
raise RuntimeError("PyYAML not installed; cannot read %s" % path)
|
|
588
|
+
encs = []
|
|
589
|
+
for enc in (encodings or ["utf-8", "euc-kr", "cp949"]):
|
|
590
|
+
norm = str(enc).strip().lower()
|
|
591
|
+
if norm and norm not in encs:
|
|
592
|
+
encs.append(norm)
|
|
593
|
+
with open(path, "rb") as f:
|
|
594
|
+
raw = f.read()
|
|
595
|
+
last_decode_error = None
|
|
596
|
+
for enc in encs:
|
|
597
|
+
try:
|
|
598
|
+
text = raw.decode(enc)
|
|
599
|
+
except UnicodeDecodeError as exc:
|
|
600
|
+
last_decode_error = exc
|
|
601
|
+
continue
|
|
602
|
+
try:
|
|
603
|
+
return yaml.safe_load(text) or {}
|
|
604
|
+
except Exception:
|
|
605
|
+
repaired = _repair_common_yaml_issues(text)
|
|
606
|
+
if repaired != text:
|
|
607
|
+
try:
|
|
608
|
+
return yaml.safe_load(repaired) or {}
|
|
609
|
+
except Exception:
|
|
610
|
+
pass
|
|
611
|
+
if last_decode_error:
|
|
612
|
+
raise RuntimeError(
|
|
613
|
+
"failed to decode YAML file: %s (tried: %s)" % (path, ", ".join(encs))
|
|
614
|
+
)
|
|
615
|
+
raise RuntimeError("failed to parse YAML file: %s" % path)
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
def _repair_common_yaml_issues(text):
|
|
619
|
+
"""
|
|
620
|
+
Best-effort repair for frequently observed malformed flow lists, e.g.
|
|
621
|
+
releases: ["A/bin" "A/lib"]
|
|
622
|
+
-> inserts missing commas between adjacent quoted items.
|
|
623
|
+
"""
|
|
624
|
+
if not text:
|
|
625
|
+
return text
|
|
626
|
+
repaired = re.sub(r'"\s+"', '", "', text)
|
|
627
|
+
repaired = re.sub(r"'\s+'", "', '", repaired)
|
|
628
|
+
return repaired
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
def load_pkg_config(path):
|
|
632
|
+
"""Load a pkg.yaml file."""
|
|
320
633
|
abs_path = os.path.abspath(os.path.expanduser(path))
|
|
321
634
|
if not os.path.exists(abs_path):
|
|
322
635
|
raise RuntimeError("pkg config not found: %s" % abs_path)
|
|
323
|
-
|
|
324
|
-
return yaml.safe_load(f) or {}
|
|
636
|
+
return _load_yaml_with_fallback(abs_path)
|
|
325
637
|
|
|
326
638
|
|
|
327
639
|
def discover_main_configs(base_dir=None):
|
|
@@ -410,8 +722,7 @@ def load_main(path=None, base_dir=None, allow_interactive=True):
|
|
|
410
722
|
abs_path = os.path.abspath(path)
|
|
411
723
|
if not os.path.exists(abs_path):
|
|
412
724
|
raise RuntimeError("config not found: %s" % abs_path)
|
|
413
|
-
|
|
414
|
-
data = yaml.safe_load(f) or {}
|
|
725
|
+
data = _load_yaml_with_fallback(abs_path)
|
|
415
726
|
return _validate_main_config(data)
|
|
416
727
|
|
|
417
728
|
|
|
@@ -426,12 +737,32 @@ def describe_expected_fields():
|
|
|
426
737
|
artifacts.exclude: glob patterns for dirs/files to skip (supports **, *.ext)
|
|
427
738
|
watch.interval_sec: poll interval for the watcher
|
|
428
739
|
watch.on_change: action names to run when changes are detected
|
|
740
|
+
watch.detect: run detection during watch tick (default: true)
|
|
741
|
+
watch.telegram.enabled: send watch/detection summary to Telegram
|
|
742
|
+
watch.telegram.bot_token: Telegram bot token
|
|
743
|
+
watch.telegram.tls_verify: verify Telegram API TLS certificate (default: true)
|
|
744
|
+
watch.telegram.ca_file: optional custom CA bundle path for Telegram TLS verification
|
|
745
|
+
watch.telegram.subscribers_file: telegram subscriber registry YAML path
|
|
746
|
+
watch.telegram.admin_chat_ids: admin chat ids allowed to approve/reject subscribers
|
|
747
|
+
watch.telegram.chat_id/chat_ids: fallback recipients (read-only compatibility)
|
|
748
|
+
watch.telegram.registration.enabled: enable /start approval workflow for telegram poller
|
|
749
|
+
watch.telegram.registration.auto_reply: auto send 안내 message for start/approve/reject commands
|
|
750
|
+
watch.telegram.registration.notify_admin_on_start: notify admins when a new /start request arrives
|
|
751
|
+
watch.telegram.message_prefix: message prefix text
|
|
752
|
+
watch.telegram.notify_on: one or more of fail/warn/changes/all
|
|
753
|
+
watch.telegram.dedup: suppress duplicate message bodies
|
|
429
754
|
collectors.enabled: default collectors to run per pkg
|
|
430
755
|
actions: mapping action_name -> list of command entries with:
|
|
431
756
|
- cmd: shell command string (required, often relative to cwd)
|
|
432
757
|
- cwd: working directory (optional)
|
|
433
758
|
- env: key/value env overrides for that command only (optional)
|
|
434
|
-
auto_actions: mapping of lifecycle events to action names (create_pkg/update_pkg/update_pkg_release/close_pkg/delete_pkg)
|
|
759
|
+
auto_actions: mapping of lifecycle events to action names (create_pkg/update_pkg/update_pkg_release/cancel_pkg_release/close_pkg/delete_pkg)
|
|
760
|
+
detection.enabled: enable detection flow
|
|
761
|
+
detection.system: system/equipment label included in detection report
|
|
762
|
+
detection.report_file: detect text report output path (auto backup on changed content)
|
|
763
|
+
detection.ignore: path patterns to skip during detection
|
|
764
|
+
detection.fail_on: status codes that should fail CI/command
|
|
765
|
+
detection.warn_on: status codes that should be warning-only
|
|
435
766
|
git.repo_root: override repo root for git scanning (optional)
|
|
436
767
|
git.repo_url: base repository URL for commit links (per system)
|
|
437
768
|
git.keyword_prefix: commit prefix used with git.keywords (e.g. "DEV-CODE:")
|