itw-python-builder 0.1.40__tar.gz → 0.1.42__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.
Files changed (22) hide show
  1. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/PKG-INFO +1 -1
  2. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/tasks.py +23 -3
  3. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/utils.py +15 -3
  4. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder.egg-info/PKG-INFO +1 -1
  5. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/pyproject.toml +1 -1
  6. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/LICENSE +0 -0
  7. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/README.md +0 -0
  8. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/.pylintrc +0 -0
  9. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/__init__.py +0 -0
  10. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/cli.py +0 -0
  11. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/notify.py +0 -0
  12. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/ssr_tasks.py +0 -0
  13. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/templates/new_version_email.html +0 -0
  14. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/templates/server.sitemap.snippet.ts +0 -0
  15. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/templates/sitemap.routes.ts +0 -0
  16. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder/version.py +0 -0
  17. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder.egg-info/SOURCES.txt +0 -0
  18. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder.egg-info/dependency_links.txt +0 -0
  19. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder.egg-info/entry_points.txt +0 -0
  20. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder.egg-info/requires.txt +0 -0
  21. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/itw_python_builder.egg-info/top_level.txt +0 -0
  22. {itw_python_builder-0.1.40 → itw_python_builder-0.1.42}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: itw_python_builder
3
- Version: 0.1.40
3
+ Version: 0.1.42
4
4
  Summary: Standardized Django deployment pipeline with Docker, testing, and SonarQube integration
5
5
  Author-email: IT-Works <contact@it-works.io>
6
6
  License: MIT
@@ -21,6 +21,7 @@ from itw_python_builder.utils import (
21
21
  load_cached_token,
22
22
  save_token_to_cache,
23
23
  probe_gitlab_token,
24
+ TOKEN_CACHE_PATH,
24
25
  )
25
26
  from itw_python_builder.ssr_tasks import * # noqa: F401,F403 — exposes ssr-init
26
27
 
@@ -66,16 +67,19 @@ def ensure_gitlab_auth(ctx: Context) -> None:
66
67
 
67
68
  cached = load_cached_token()
68
69
  if cached:
69
- status = probe_gitlab_token(_gitlab_api_host(ctx), cached)
70
+ project_type = detect_project_type()
71
+ api_host = _gitlab_api_host(ctx)
72
+ username = get_gitlab_username(ctx)
73
+ status = probe_gitlab_token(ctx, project_type, api_host, username, cached)
70
74
  if status == 'ok':
71
75
  os.environ['GITLAB_TOKEN'] = cached
72
- os.environ.setdefault('GITLAB_USERNAME', get_gitlab_username(ctx))
76
+ os.environ.setdefault('GITLAB_USERNAME', username)
73
77
  print('[itw] Using cached GitLab token.')
74
78
  return
75
79
  if status == 'unreachable':
76
80
  print('[itw] Could not reach GitLab to verify cached token; using it anyway.')
77
81
  os.environ['GITLAB_TOKEN'] = cached
78
- os.environ.setdefault('GITLAB_USERNAME', get_gitlab_username(ctx))
82
+ os.environ.setdefault('GITLAB_USERNAME', username)
79
83
  return
80
84
  print('[itw] Cached GitLab token was rejected (401/403). Please log in again.')
81
85
 
@@ -88,6 +92,22 @@ def login(ctx: Context, username=None):
88
92
  _prompt_and_store_token(ctx, username)
89
93
 
90
94
 
95
+ @task
96
+ def logout(ctx: Context):
97
+ """Forget the cached GitLab token and log out of the container registry."""
98
+ try:
99
+ TOKEN_CACHE_PATH.unlink()
100
+ print(f'[itw] Removed cached token at {TOKEN_CACHE_PATH}.')
101
+ except FileNotFoundError:
102
+ print('[itw] No cached token to remove.')
103
+ except OSError as exc:
104
+ print(f'[itw] Could not remove {TOKEN_CACHE_PATH}: {exc}')
105
+ if detect_project_type() == 'backend':
106
+ ctx.run('podman logout gitreg.it-works.io:443', warn=True)
107
+ os.environ.pop('GITLAB_TOKEN', None)
108
+ os.environ.pop('GITLAB_USERNAME', None)
109
+
110
+
91
111
  def build_frontend(ctx: Context, branch: str, ssr: bool = False) -> None:
92
112
  """Build the Angular app. With ssr=True uses the SSR npm scripts."""
93
113
  if ssr:
@@ -314,12 +314,24 @@ def save_token_to_cache(token: str) -> bool:
314
314
  return False
315
315
 
316
316
 
317
- def probe_gitlab_token(api_host: str, token: str) -> str:
318
- """Probe GET /api/v4/user. Returns 'ok' | 'unauthorized' | 'unreachable'."""
317
+ def probe_gitlab_token(ctx: Context, project_type: str, api_host: str, username: str, token: str) -> str:
318
+ if project_type == 'backend':
319
+ result = ctx.run(
320
+ f'podman login -u {username} --password-stdin gitreg.it-works.io:443 --tls-verify=false',
321
+ in_stream=io.StringIO(token),
322
+ hide=True,
323
+ warn=True,
324
+ )
325
+ if result.ok:
326
+ return 'ok'
327
+ err = (result.stderr or result.stdout or '').lower()
328
+ if 'unauthorized' in err or '401' in err or 'authentication' in err:
329
+ return 'unauthorized'
330
+ return 'unreachable'
331
+
319
332
  import ssl
320
333
  import urllib.error
321
334
  import urllib.request
322
-
323
335
  req = urllib.request.Request(
324
336
  f'https://{api_host}/api/v4/user',
325
337
  headers={'PRIVATE-TOKEN': token},
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: itw_python_builder
3
- Version: 0.1.40
3
+ Version: 0.1.42
4
4
  Summary: Standardized Django deployment pipeline with Docker, testing, and SonarQube integration
5
5
  Author-email: IT-Works <contact@it-works.io>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "itw_python_builder"
7
- version = "0.1.40"
7
+ version = "0.1.42"
8
8
  description = "Standardized Django deployment pipeline with Docker, testing, and SonarQube integration"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"