dayhoff-tools 1.1.14__py3-none-any.whl → 1.1.15__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.
@@ -6,7 +6,6 @@ import shutil
6
6
  import subprocess
7
7
  import sys
8
8
  from pathlib import Path
9
- from typing import Optional
10
9
 
11
10
  import toml
12
11
  import typer
@@ -15,6 +14,44 @@ import yaml
15
14
  # Import cloud helper lazily inside functions to avoid heavy deps at module load
16
15
 
17
16
 
17
+ def _warn_if_gcp_default_sa(force_prompt: bool = False) -> None:
18
+ """Warn the user when the active gcloud principal is the default VM service
19
+ account. See detailed docstring later in file (duplicate for early
20
+ availability)."""
21
+
22
+ from dayhoff_tools.cli import cloud_commands as _cc
23
+
24
+ try:
25
+ impersonation = _cc._get_current_gcp_impersonation()
26
+ user = _cc._get_current_gcp_user()
27
+ active = impersonation if impersonation != "None" else user
28
+ short = _cc._get_short_name(active)
29
+ except Exception:
30
+ return
31
+
32
+ if short != "default VM service account":
33
+ return
34
+
35
+ YELLOW = getattr(_cc, "YELLOW", "\033[0;33m")
36
+ BLUE = getattr(_cc, "BLUE", "\033[0;36m")
37
+ RED = getattr(_cc, "RED", "\033[0;31m")
38
+ NC = getattr(_cc, "NC", "\033[0m")
39
+
40
+ print(
41
+ f"{YELLOW}⚠ You are currently authenticated as the *default VM service account*.{NC}\n"
42
+ f"{YELLOW} This will block gsutil/DVC access to private buckets (e.g. warehouse).{NC}\n"
43
+ f"{YELLOW} Run {BLUE}dh gcp login{YELLOW} or {BLUE}dh gcp use-devcon{YELLOW} before retrying.{NC}",
44
+ file=sys.stderr,
45
+ )
46
+
47
+ if force_prompt and sys.stdin.isatty() and sys.stdout.isatty():
48
+ import questionary
49
+
50
+ if not questionary.confirm("Proceed anyway?", default=False).ask():
51
+ print(f"{RED}Aborted due to unsafe GCP credentials.{NC}", file=sys.stderr)
52
+ raise SystemExit(1)
53
+
54
+
18
55
  def test_github_actions_locally():
19
56
  """Run the script test_pytest_in_github_actions_container.sh.sh."""
20
57
  script_path = ".devcontainer/scripts/test_pytest_in_github_actions_container.sh"
@@ -571,63 +608,3 @@ def update_dependencies(
571
608
  # ----------------------
572
609
  # Cloud credential guard
573
610
  # ----------------------
574
-
575
-
576
- def _warn_if_gcp_default_sa(force_prompt: bool = False) -> None:
577
- """Warn the user when the active gcloud principal is the default VM service
578
- account.
579
-
580
- This situation prevents gsutil/DVC from accessing private buckets and is
581
- almost never what we want when interacting with the warehouse. The
582
- function prints a coloured warning and, when *force_prompt* is *True* and
583
- the session is interactive, asks the user whether to continue or abort the
584
- command.
585
-
586
- Parameters
587
- ----------
588
- force_prompt : bool, default False
589
- When *True* and running in an interactive shell (stdin & stdout are
590
- TTYs), display a yes/no prompt (via *questionary.confirm*) asking the
591
- user whether to proceed. If the user declines, ``SystemExit(1)`` is
592
- raised to stop the CLI command immediately. In non-interactive
593
- contexts the function merely prints the warning without prompting.
594
- """
595
-
596
- # Delay heavy import until the function is actually needed
597
- from dayhoff_tools.cli import cloud_commands as _cc # local import to ease testing
598
-
599
- try:
600
- impersonation = _cc._get_current_gcp_impersonation()
601
- user = _cc._get_current_gcp_user()
602
- active = impersonation if impersonation != "None" else user
603
- short_name = _cc._get_short_name(active)
604
- except Exception:
605
- # If gcloud is missing or some other unexpected error occurs, fail
606
- # gracefully by doing nothing.
607
- return
608
-
609
- if short_name != "default VM service account":
610
- # All good – nothing to warn about
611
- return
612
-
613
- # Colour constants – fall back to empty strings if not available
614
- RED = getattr(_cc, "RED", "\033[0;31m")
615
- YELLOW = getattr(_cc, "YELLOW", "\033[0;33m")
616
- BLUE = getattr(_cc, "BLUE", "\033[0;36m")
617
- NC = getattr(_cc, "NC", "\033[0m")
618
-
619
- warning_msg = (
620
- f"{YELLOW}⚠ You are currently authenticated as the *default VM service account*.{NC}\n"
621
- f"{YELLOW} This will block gsutil/DVC access to private buckets (e.g. warehouse).{NC}\n"
622
- f"{YELLOW} Run {BLUE}dh gcp login{YELLOW} or {BLUE}dh gcp use-devcon{YELLOW} before retrying.{NC}"
623
- )
624
- print(warning_msg, file=sys.stderr)
625
-
626
- interactive = sys.stdin.isatty() and sys.stdout.isatty()
627
- if force_prompt and interactive:
628
- import questionary
629
-
630
- proceed = questionary.confirm("Proceed anyway?", default=False).ask()
631
- if not proceed:
632
- print(f"{RED}Aborted due to unsafe GCP credentials.{NC}", file=sys.stderr)
633
- raise SystemExit(1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dayhoff-tools
3
- Version: 1.1.14
3
+ Version: 1.1.15
4
4
  Summary: Common tools for all the repos at Dayhoff Labs
5
5
  Author: Daniel Martin-Alarcon
6
6
  Author-email: dma@dayhofflabs.com
@@ -5,7 +5,7 @@ dayhoff_tools/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
5
5
  dayhoff_tools/cli/cloud_commands.py,sha256=KiYEuD3nSg8QPWBYfrhdze2La_CJe4iqK-8uOAHyS8U,35827
6
6
  dayhoff_tools/cli/main.py,sha256=Ae0Bee2VjRzUge1I2DJoDVqoXpQnKfxGhdiMSmIWJwo,3788
7
7
  dayhoff_tools/cli/swarm_commands.py,sha256=5EyKj8yietvT5lfoz8Zx0iQvVaNgc3SJX1z2zQR6o6M,5614
8
- dayhoff_tools/cli/utility_commands.py,sha256=3cLL4821liLsKRWkEP4VZZ60rMjdvGWoyejHS-TxnnU,24093
8
+ dayhoff_tools/cli/utility_commands.py,sha256=yProTaVGV28oWY383GHAFGbnf9wiEmWIXxxfiGB1elk,22956
9
9
  dayhoff_tools/deployment/base.py,sha256=u-AjbtHnFLoLt33dhYXHIpV-6jcieMEHHGBGN_U9Hm0,15626
10
10
  dayhoff_tools/deployment/deploy_aws.py,sha256=O0gQxHioSU_sNU8T8MD4wSOPvWc--V8eRRZzlRu035I,16446
11
11
  dayhoff_tools/deployment/deploy_gcp.py,sha256=DxBM4sUzwPK9RWLP9bSfr38n1HHl-TVrp4TsbdN8pUA,5795
@@ -26,7 +26,7 @@ dayhoff_tools/intake/uniprot.py,sha256=BZYJQF63OtPcBBnQ7_P9gulxzJtqyorgyuDiPeOJq
26
26
  dayhoff_tools/logs.py,sha256=DKdeP0k0kliRcilwvX0mUB2eipO5BdWUeHwh-VnsICs,838
27
27
  dayhoff_tools/sqlite.py,sha256=jV55ikF8VpTfeQqqlHSbY8OgfyfHj8zgHNpZjBLos_E,18672
28
28
  dayhoff_tools/warehouse.py,sha256=TqV8nex1AluNaL4JuXH5zuu9P7qmE89lSo6f_oViy6U,14965
29
- dayhoff_tools-1.1.14.dist-info/METADATA,sha256=qaH1l5HdQMoQq4SAcXucEKpOe8ajX5Ng0isGrdmkiFg,2225
30
- dayhoff_tools-1.1.14.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
31
- dayhoff_tools-1.1.14.dist-info/entry_points.txt,sha256=iAf4jteNqW3cJm6CO6czLxjW3vxYKsyGLZ8WGmxamSc,49
32
- dayhoff_tools-1.1.14.dist-info/RECORD,,
29
+ dayhoff_tools-1.1.15.dist-info/METADATA,sha256=Ovnl_9EjBDAvaUZyAXvx0BpY5AReviFjk51TSPZqNFI,2225
30
+ dayhoff_tools-1.1.15.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
31
+ dayhoff_tools-1.1.15.dist-info/entry_points.txt,sha256=iAf4jteNqW3cJm6CO6czLxjW3vxYKsyGLZ8WGmxamSc,49
32
+ dayhoff_tools-1.1.15.dist-info/RECORD,,