salla-gitpuller 1.2.0__tar.gz → 1.2.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: salla_gitpuller
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: A lightweight utility to git pull a repository using SSH deploy keys stored in environment variables
5
5
  Author-email: Mohammed Junaid <safijunaid.ss@gmail.com>, Muhammad Zahid <zahidmuhammad127@gmail.com>
6
6
  License: MIT
@@ -5,7 +5,7 @@ from .slack_notifier import SlackNotifier
5
5
  from .utils import transform_custom, get_repo_path, get_env_base_path
6
6
 
7
7
 
8
- __version__ = "1.2.0"
8
+ __version__ = "1.2.2"
9
9
  __all__ = [
10
10
  "GitPullExecutor",
11
11
  "AlertManager",
@@ -270,8 +270,8 @@ class GitPullExecutor:
270
270
  ``suppression_hours`` caps how often the *same* error is alerted on,
271
271
  avoiding Slack spam when a broken state persists across many runs.
272
272
  """
273
- # webhook_url is a fallback only; CDM_PROD_SLACK_BOT_TOKEN still wins
274
- # so Mage callers that pass CDM_SLACK_WEBHOOK_URL stay on the daily thread.
273
+ # webhook_url is a fallback only; WP_SLACK_DB_ALERTS_TOKEN still wins
274
+ # so Mage callers that pass a webhook stay on the daily thread.
275
275
  if webhook_url and not self.slack_notifier.bot_token:
276
276
  notifier = SlackNotifier(webhook_url=webhook_url)
277
277
  else:
@@ -10,6 +10,7 @@ import requests
10
10
  SLACK_POST_MESSAGE_URL = "https://slack.com/api/chat.postMessage"
11
11
  SLACK_CONVERSATIONS_HISTORY_URL = "https://slack.com/api/conversations.history"
12
12
  DEFAULT_SLACK_CHANNEL = "C05MLHR55JT"
13
+ SLACK_WEBHOOK_MAP_KEY = "db-ops-log"
13
14
 
14
15
  # Unified across every Mage deployment — do not prefix with MAGE_WORKSPACE_NAME.
15
16
  # One hash per channel per day; field = gitpuller workspace, value = Slack thread_ts.
@@ -22,8 +23,33 @@ _redis_client = None
22
23
  _redis_init_attempted = False
23
24
 
24
25
 
26
+ def _env(*names: str, default: str = "") -> str:
27
+ for name in names:
28
+ value = (os.environ.get(name) or "").strip()
29
+ if value:
30
+ return value
31
+ return default
32
+
33
+
34
+ def _resolve_slack_webhook(explicit: Optional[str] = None) -> Optional[str]:
35
+ """Prefer an explicit URL, then CDM_SLACK_WEBHOOKS['db-ops-log']."""
36
+ if explicit and str(explicit).strip():
37
+ return str(explicit).strip()
38
+ raw = os.environ.get("CDM_SLACK_WEBHOOKS")
39
+ if raw and str(raw).strip():
40
+ try:
41
+ webhooks = json.loads(str(raw).strip())
42
+ if isinstance(webhooks, dict):
43
+ entry = webhooks.get(SLACK_WEBHOOK_MAP_KEY)
44
+ if entry and str(entry).strip():
45
+ return str(entry).strip()
46
+ except json.JSONDecodeError as exc:
47
+ print(f"⚠️ CDM_SLACK_WEBHOOKS is not valid JSON ({exc})")
48
+ return _env("CDM_SLACK_WEBHOOK_URL") or None
49
+
50
+
25
51
  def _get_redis_client():
26
- """Mage io_config.yaml first, then REDIS_HOST / REDIS_PORT / REDIS_PASSWORD."""
52
+ """WP_REDIS_* env vars first, then Mage io_config.yaml, then REDIS_*."""
27
53
  global _redis_client, _redis_init_attempted
28
54
  if _redis_client is not None:
29
55
  return _redis_client
@@ -37,27 +63,32 @@ def _get_redis_client():
37
63
  print("⚠️ redis package not installed; Slack thread_ts will not persist across pods")
38
64
  return None
39
65
 
40
- host = None
41
- password = None
42
- port = 6379
43
- try:
44
- from mage_ai.io.config import ConfigFileLoader
45
- from mage_ai.settings.repo import get_repo_path
66
+ host = _env("WP_REDIS_HOST")
67
+ password = _env("WP_REDIS_PASSWORD") or None
68
+ port = int(_env("WP_REDIS_PORT") or "6379")
46
69
 
47
- loader = ConfigFileLoader(os.path.join(get_repo_path(), "io_config.yaml"), "default")
48
- host = loader["REDIS_HOST"]
49
- password = loader["REDIS_PASSWORD"] or None
50
- port = int(loader["REDIS_PORT"])
51
- except Exception:
52
- host = None
70
+ if not host:
71
+ try:
72
+ from mage_ai.io.config import ConfigFileLoader
73
+ from mage_ai.settings.repo import get_repo_path
74
+
75
+ loader = ConfigFileLoader(os.path.join(get_repo_path(), "io_config.yaml"), "default")
76
+ host = loader["REDIS_HOST"]
77
+ password = loader["REDIS_PASSWORD"] or None
78
+ port = int(loader["REDIS_PORT"])
79
+ except Exception:
80
+ host = None
53
81
 
54
82
  if not host:
55
- host = (os.environ.get("REDIS_HOST") or "").strip() or None
56
- password = (os.environ.get("REDIS_PASSWORD") or "").strip() or None
57
- port = int(os.environ.get("REDIS_PORT") or 6379)
83
+ host = _env("REDIS_HOST") or None
84
+ password = _env("REDIS_PASSWORD") or None
85
+ port = int(_env("REDIS_PORT") or "6379")
58
86
 
59
87
  if not host:
60
- print("⚠️ Redis is not configured; Slack thread_ts will not persist across pods")
88
+ print(
89
+ "⚠️ Redis is not configured; Slack thread_ts will not persist across pods "
90
+ "(set WP_REDIS_HOST / WP_REDIS_PORT / WP_REDIS_PASSWORD)"
91
+ )
61
92
  return None
62
93
 
63
94
  try:
@@ -94,22 +125,26 @@ class SlackNotifier:
94
125
  bot_token: Optional[str] = None,
95
126
  channel: Optional[str] = None,
96
127
  ):
97
- self.bot_token = (bot_token or os.environ.get("CDM_PROD_SLACK_BOT_TOKEN") or "").strip() or None
128
+ self.bot_token = (
129
+ bot_token
130
+ or _env("WP_SLACK_DB_ALERTS_TOKEN", "CDM_PROD_SLACK_BOT_TOKEN")
131
+ or None
132
+ )
98
133
  self.channel = (
99
134
  (channel or os.environ.get("CDM_PROD_DB_SLACK_CHANNEL") or "").strip()
100
135
  or DEFAULT_SLACK_CHANNEL
101
136
  )
102
- self.webhook_url = (webhook_url or os.environ.get("CDM_SLACK_WEBHOOK_URL") or "").strip() or None
137
+ self.webhook_url = _resolve_slack_webhook(webhook_url)
103
138
  self._thread_ts_cache: Dict[str, str] = {}
104
139
 
105
140
  if not self.bot_token and not self.webhook_url:
106
141
  print(
107
142
  "⚠️ Slack not configured; skipping alerts "
108
- "(set CDM_PROD_SLACK_BOT_TOKEN, or CDM_SLACK_WEBHOOK_URL as fallback)"
143
+ "(set WP_SLACK_DB_ALERTS_TOKEN, or CDM_SLACK_WEBHOOKS['db-ops-log'])"
109
144
  )
110
145
  elif not self.bot_token:
111
146
  print(
112
- "⚠️ CDM_PROD_SLACK_BOT_TOKEN is not set; using webhook "
147
+ "⚠️ WP_SLACK_DB_ALERTS_TOKEN is not set; using webhook "
113
148
  "(alerts will not be threaded)"
114
149
  )
115
150
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "salla_gitpuller"
7
- version = "1.2.0"
7
+ version = "1.2.2"
8
8
  description = "A lightweight utility to git pull a repository using SSH deploy keys stored in environment variables"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: salla_gitpuller
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: A lightweight utility to git pull a repository using SSH deploy keys stored in environment variables
5
5
  Author-email: Mohammed Junaid <safijunaid.ss@gmail.com>, Muhammad Zahid <zahidmuhammad127@gmail.com>
6
6
  License: MIT
File without changes