aic-utils 2.0.6__tar.gz → 2.0.7__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.
- {aic_utils-2.0.6 → aic_utils-2.0.7}/PKG-INFO +1 -1
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils/__init__.py +1 -1
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils/gitlabmanager.py +59 -53
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils.egg-info/PKG-INFO +1 -1
- {aic_utils-2.0.6 → aic_utils-2.0.7}/setup.py +1 -1
- {aic_utils-2.0.6 → aic_utils-2.0.7}/README.md +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils/aic.py +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils/dataset_converter.py +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils/gitlab_init.py +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils/slack_logger.py +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils.egg-info/SOURCES.txt +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils.egg-info/dependency_links.txt +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils.egg-info/requires.txt +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/aic_utils.egg-info/top_level.txt +0 -0
- {aic_utils-2.0.6 → aic_utils-2.0.7}/setup.cfg +0 -0
|
@@ -150,65 +150,71 @@ class GitLabManager:
|
|
|
150
150
|
|
|
151
151
|
def get_token_expiration_date(self):
|
|
152
152
|
"""
|
|
153
|
-
Retrieves the expiration date of the
|
|
153
|
+
Retrieves the expiration date of the GitLab token actually being used
|
|
154
|
+
for this session. Uses GET /personal_access_tokens/self (GitLab 16.0+)
|
|
155
|
+
for an exact match. Falls back to listing all tokens and picking the
|
|
156
|
+
soonest-expiring one only if /self isn't supported by the GitLab
|
|
157
|
+
instance — that fallback is a heuristic and may name the wrong token.
|
|
158
|
+
|
|
154
159
|
Returns None if expiration cannot be determined.
|
|
155
160
|
"""
|
|
161
|
+
def _parse_exp(exp_str):
|
|
162
|
+
if not exp_str:
|
|
163
|
+
return None
|
|
164
|
+
try:
|
|
165
|
+
if 'T' in exp_str:
|
|
166
|
+
return datetime.strptime(exp_str, '%Y-%m-%dT%H:%M:%S.%fZ')
|
|
167
|
+
return datetime.strptime(exp_str, '%Y-%m-%d')
|
|
168
|
+
except ValueError:
|
|
169
|
+
return None
|
|
170
|
+
|
|
156
171
|
try:
|
|
157
|
-
#
|
|
158
|
-
|
|
159
|
-
user_response = requests.get(user_url, headers=self.headers, timeout=30)
|
|
172
|
+
# Validate the token works
|
|
173
|
+
user_response = requests.get(f"{self.gitlab_base}/user", headers=self.headers, timeout=30)
|
|
160
174
|
user_response.raise_for_status()
|
|
175
|
+
username = user_response.json().get('username', 'Unknown')
|
|
161
176
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
# Sort by expiration date (soonest first)
|
|
199
|
-
active_tokens_with_expiry.sort(key=lambda x: x['expires_at'])
|
|
200
|
-
|
|
201
|
-
# Return the soonest expiring token
|
|
202
|
-
# (assumption: user is likely using their most recent/soon-to-expire token)
|
|
203
|
-
token_info = active_tokens_with_expiry[0]
|
|
204
|
-
print(f"Checking expiration for token: '{token_info['name']}'")
|
|
205
|
-
return token_info['expires_at']
|
|
206
|
-
else:
|
|
207
|
-
print(f"✅ Token valid for user '{username}' but no expiration date found")
|
|
208
|
-
return None
|
|
209
|
-
else:
|
|
210
|
-
print(f"✅ Token valid for user '{username}' but cannot access token list")
|
|
177
|
+
# Preferred path: ask GitLab which token we're using right now.
|
|
178
|
+
self_resp = requests.get(
|
|
179
|
+
f"{self.gitlab_base}/personal_access_tokens/self",
|
|
180
|
+
headers=self.headers, timeout=30,
|
|
181
|
+
)
|
|
182
|
+
if self_resp.status_code == 200:
|
|
183
|
+
tok = self_resp.json()
|
|
184
|
+
exp_date = _parse_exp(tok.get('expires_at'))
|
|
185
|
+
if exp_date is not None:
|
|
186
|
+
print(f"Checking expiration for token: '{tok.get('name','Unnamed')}'")
|
|
187
|
+
return exp_date
|
|
188
|
+
print(f"✅ Token '{tok.get('name','Unnamed')}' valid for user '{username}' but has no expiration set")
|
|
189
|
+
return None
|
|
190
|
+
elif self_resp.status_code != 404:
|
|
191
|
+
# Some other error — surface a hint but keep going to fallback
|
|
192
|
+
print(f"⚠️ /personal_access_tokens/self returned {self_resp.status_code}; falling back to list-all heuristic.")
|
|
193
|
+
|
|
194
|
+
# Fallback for GitLab < 16.0: list all tokens and pick soonest-expiring.
|
|
195
|
+
# This is best-effort and may report a different token than the one in use.
|
|
196
|
+
tokens_response = requests.get(
|
|
197
|
+
f"{self.gitlab_base}/personal_access_tokens",
|
|
198
|
+
headers=self.headers, timeout=30,
|
|
199
|
+
)
|
|
200
|
+
if tokens_response.status_code != 200:
|
|
201
|
+
print(f"✅ Token valid for user '{username}' but cannot read token metadata")
|
|
202
|
+
return None
|
|
203
|
+
active = []
|
|
204
|
+
for token in tokens_response.json():
|
|
205
|
+
if token.get('revoked', True):
|
|
206
|
+
continue
|
|
207
|
+
exp_date = _parse_exp(token.get('expires_at'))
|
|
208
|
+
if exp_date is None:
|
|
209
|
+
continue
|
|
210
|
+
active.append((exp_date, token.get('name', 'Unnamed')))
|
|
211
|
+
if not active:
|
|
212
|
+
print(f"✅ Token valid for user '{username}' but no expiration date found")
|
|
211
213
|
return None
|
|
214
|
+
active.sort()
|
|
215
|
+
exp_date, name = active[0]
|
|
216
|
+
print(f"Checking expiration for token: '{name}' (best-guess via list-all fallback)")
|
|
217
|
+
return exp_date
|
|
212
218
|
|
|
213
219
|
except requests.exceptions.RequestException as err:
|
|
214
220
|
print(f"Error checking token: {err}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|