dayhoff-tools 1.0.5__py3-none-any.whl → 1.0.7__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.
@@ -129,19 +129,25 @@ def _get_env_var(variable: str) -> Optional[str]:
129
129
 
130
130
  # --- GCP Functions ---
131
131
  def _is_gcp_user_authenticated() -> bool:
132
- """Check if a user is authenticated with GCP (not a compute service account)."""
133
- gcloud_path = _find_executable("gcloud")
134
- cmd = [
135
- gcloud_path,
136
- "auth",
137
- "list",
138
- "--filter=status:ACTIVE",
139
- "--format=value(account)",
140
- ]
141
- _, stdout, _ = _run_command(cmd, capture=True, check=False)
132
+ """Check if the current gcloud user authentication is valid and non-interactive.
142
133
 
143
- account = stdout.strip()
144
- return bool(account) and "compute@developer.gserviceaccount.com" not in account
134
+ Returns:
135
+ True if `gcloud auth print-access-token --quiet` succeeds (exit code 0),
136
+ False otherwise (indicating potential need for interactive login).
137
+ """
138
+ try:
139
+ gcloud_path = _find_executable("gcloud")
140
+ # Attempt to get a token silently. If this fails, login is likely expired or needs interaction.
141
+ returncode, _, _ = _run_command(
142
+ [gcloud_path, "auth", "print-access-token", "--quiet"],
143
+ capture=True, # We don't need the token, just the exit code
144
+ check=False, # Don't raise on failure
145
+ suppress_output=True, # Hide any potential output/errors from this check
146
+ )
147
+ return returncode == 0
148
+ except FileNotFoundError:
149
+ # If gcloud isn't found, they are definitely not authenticated.
150
+ return False
145
151
 
146
152
 
147
153
  def _get_current_gcp_user() -> str:
@@ -350,49 +356,62 @@ def gcp_use_devcon(
350
356
  export: bool = typer.Option(
351
357
  False, "--export", "-x", help="Print export commands for the current shell."
352
358
  ),
353
- auth_first: bool = typer.Option(
354
- False, "--auth", "-a", help="Authenticate user first if needed."
355
- ),
356
359
  ):
357
- """Switch to devcon service account impersonation mode."""
360
+ """Configure gcloud CLI to impersonate the devcon SA by setting RC file variables.
361
+
362
+ NOTE: This command DOES NOT automatically update Application Default Credentials (ADC).
363
+ After running this, or after sourcing the export commands, you may need to run:
364
+ 'gcloud auth application-default login --impersonate-service-account=...' manually
365
+ if you need libraries (like DVC) to use these credentials.
366
+
367
+ Ensures the primary user login is valid first to allow potential impersonation.
368
+ """
358
369
  if not _is_gcp_user_authenticated():
359
- if auth_first:
360
- print(
361
- f"{YELLOW}You need to authenticate first. Running authentication...{NC}",
362
- file=sys.stderr,
363
- )
364
- _run_gcloud_login()
365
- else:
366
- print(
367
- f"{RED}Error: Not authenticated with GCP. Run 'dh gcp login' first or use --auth flag.{NC}",
368
- file=sys.stderr,
369
- )
370
- sys.exit(1)
370
+ print(
371
+ f"{RED}Error: GCP user authentication is invalid or requires interactive login.{NC}",
372
+ file=sys.stderr,
373
+ )
374
+ print(
375
+ f"{YELLOW}Please run 'gcloud auth login' interactively first, then try this command again.{NC}",
376
+ file=sys.stderr,
377
+ )
378
+ sys.exit(1)
371
379
 
372
- # Modify RC files to persist across sessions
380
+ # Set gcloud CLI impersonation (persisted to RC files)
373
381
  _modify_rc_files("CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT", f"'{GCP_DEVCON_SA}'")
374
382
  _modify_rc_files("GOOGLE_CLOUD_PROJECT", f"'{GCP_PROJECT_ID}'")
375
383
 
376
384
  if export:
377
- # Print export commands for the current shell to stdout
385
+ # Print export commands for the current shell (for gcloud CLI)
378
386
  print(f"export CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT='{GCP_DEVCON_SA}'")
379
387
  print(f"export GOOGLE_CLOUD_PROJECT='{GCP_PROJECT_ID}'")
380
388
 
381
- # Print confirmation to stderr so it doesn't affect eval
389
+ # Print confirmation and instructions for ADC to stderr
382
390
  print(
383
- f"{GREEN}GCP service account impersonation for '{GCP_DEVCON_SA}' set up successfully.{NC}",
391
+ f"{GREEN}GCP gcloud CLI impersonation for '{GCP_DEVCON_SA}' exported.{NC}",
384
392
  file=sys.stderr,
385
393
  )
386
- print(f"{GREEN}You now have standard devcon permissions.{NC}", file=sys.stderr)
387
- else:
388
- # Just print confirmation
389
394
  print(
390
- f"{GREEN}Switched to devcon service account impersonation. You now have standard devcon permissions.{NC}"
395
+ f"{YELLOW}NOTE: ADC file not updated by export. To update ADC for libraries, run:{NC}",
396
+ file=sys.stderr,
391
397
  )
392
398
  print(
393
- f"Changes will take effect in new shell sessions. To apply in current shell, run:"
399
+ f"{YELLOW} gcloud auth application-default login --impersonate-service-account={GCP_DEVCON_SA}{NC}",
400
+ file=sys.stderr,
394
401
  )
402
+ else:
403
+ # Print confirmation
404
+ print(
405
+ f"{GREEN}RC files updated to use devcon SA for future gcloud CLI sessions.{NC}"
406
+ )
407
+ print(f"To apply gcloud CLI settings in current shell, run:")
395
408
  print(f' {YELLOW}eval "$(dh gcp use-devcon --export)"{NC}')
409
+ print(
410
+ f"{YELLOW}NOTE: ADC file not updated. To update ADC for libraries, run:{NC}"
411
+ )
412
+ print(
413
+ f"{YELLOW} gcloud auth application-default login --impersonate-service-account={GCP_DEVCON_SA}{NC}"
414
+ )
396
415
 
397
416
 
398
417
  @gcp_app.command("use-user")
@@ -400,48 +419,60 @@ def gcp_use_user(
400
419
  export: bool = typer.Option(
401
420
  False, "--export", "-x", help="Print export commands for the current shell."
402
421
  ),
403
- auth_first: bool = typer.Option(
404
- False, "--auth", "-a", help="Authenticate user first if needed."
405
- ),
406
422
  ):
407
- """Switch to personal account mode (no impersonation)."""
423
+ """Configure gcloud CLI to use the personal user account by setting RC file variables.
424
+
425
+ NOTE: This command DOES NOT automatically update Application Default Credentials (ADC).
426
+ After running this, or after sourcing the export commands, you may need to run:
427
+ 'gcloud auth application-default login' manually
428
+ if you need libraries (like DVC) to use your personal credentials.
429
+
430
+ Ensures the primary user login is valid first.
431
+ """
408
432
  if not _is_gcp_user_authenticated():
409
- if auth_first:
410
- print(
411
- f"{YELLOW}You need to authenticate first. Running authentication...{NC}",
412
- file=sys.stderr,
413
- )
414
- _run_gcloud_login()
415
- else:
416
- print(
417
- f"{RED}Error: Not authenticated with GCP. Run 'dh gcp login' first or use --auth flag.{NC}",
418
- file=sys.stderr,
419
- )
420
- sys.exit(1)
433
+ print(
434
+ f"{RED}Error: GCP user authentication is invalid or requires interactive login.{NC}",
435
+ file=sys.stderr,
436
+ )
437
+ print(
438
+ f"{YELLOW}Please run 'gcloud auth login' interactively first, then try this command again.{NC}",
439
+ file=sys.stderr,
440
+ )
441
+ sys.exit(1)
421
442
 
422
- # Modify RC files to persist across sessions
443
+ # Unset gcloud CLI impersonation (persisted to RC files)
423
444
  _modify_rc_files("CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT", None)
424
445
  _modify_rc_files("GOOGLE_CLOUD_PROJECT", f"'{GCP_PROJECT_ID}'")
425
446
 
426
447
  if export:
427
- # Print export commands for the current shell to stdout
448
+ # Print export commands for the current shell (for gcloud CLI)
428
449
  print(f"unset CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT")
429
450
  print(f"export GOOGLE_CLOUD_PROJECT='{GCP_PROJECT_ID}'")
430
451
 
431
- # Print confirmation to stderr so it doesn't affect eval
452
+ # Print confirmation and instructions for ADC to stderr
432
453
  print(
433
- f"{GREEN}Switched to personal account mode. You are now using your own permissions.{NC}",
454
+ f"{GREEN}GCP gcloud CLI impersonation unset and exported.{NC}",
434
455
  file=sys.stderr,
435
456
  )
436
- else:
437
- # Just print confirmation
438
457
  print(
439
- f"{GREEN}Switched to personal account mode. You are now using your own permissions.{NC}"
458
+ f"{YELLOW}NOTE: ADC file not updated by export. To update ADC for libraries, run:{NC}",
459
+ file=sys.stderr,
440
460
  )
441
461
  print(
442
- f"Changes will take effect in new shell sessions. To apply in current shell, run:"
462
+ f"{YELLOW} gcloud auth application-default login{NC}",
463
+ file=sys.stderr,
443
464
  )
465
+ else:
466
+ # Print confirmation
467
+ print(
468
+ f"{GREEN}RC files updated to use personal account for future gcloud CLI sessions.{NC}"
469
+ )
470
+ print(f"To apply gcloud CLI settings in current shell, run:")
444
471
  print(f' {YELLOW}eval "$(dh gcp use-user --export)"{NC}')
472
+ print(
473
+ f"{YELLOW}NOTE: ADC file not updated. To update ADC for libraries, run:{NC}"
474
+ )
475
+ print(f"{YELLOW} gcloud auth application-default login{NC}")
445
476
 
446
477
 
447
478
  # --- AWS Commands ---
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dayhoff-tools
3
- Version: 1.0.5
3
+ Version: 1.0.7
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
@@ -2,7 +2,7 @@ dayhoff_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  dayhoff_tools/chemistry/standardizer.py,sha256=uMn7VwHnx02nc404eO6fRuS4rsl4dvSPf2ElfZDXEpY,11188
3
3
  dayhoff_tools/chemistry/utils.py,sha256=jt-7JgF-GeeVC421acX-bobKbLU_X94KNOW24p_P-_M,2257
4
4
  dayhoff_tools/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- dayhoff_tools/cli/cloud_commands.py,sha256=rt8bcNo73zhCwNwcb8zTGmx2xxcGejhKEEl-d9HH2yM,20889
5
+ dayhoff_tools/cli/cloud_commands.py,sha256=Z_zCtZYH0thljiOSkr1fjFZal7a8DZtY-dH7uZEa4YI,22571
6
6
  dayhoff_tools/cli/main.py,sha256=E1-3rZ26LMgJVKBz6CdJwsHs9fJsSGa2_9tot3hNgz4,3604
7
7
  dayhoff_tools/cli/swarm_commands.py,sha256=5EyKj8yietvT5lfoz8Zx0iQvVaNgc3SJX1z2zQR6o6M,5614
8
8
  dayhoff_tools/cli/utility_commands.py,sha256=AsZMpvUNP2xjn5cZ9_BrBNHggfuy6PLwlHw1WP0d7o0,9602
@@ -25,7 +25,7 @@ dayhoff_tools/sqlite.py,sha256=jV55ikF8VpTfeQqqlHSbY8OgfyfHj8zgHNpZjBLos_E,18672
25
25
  dayhoff_tools/structure.py,sha256=ufN3gAodQxhnt7psK1VTQeu9rKERmo_PhoxIbB4QKMw,27660
26
26
  dayhoff_tools/uniprot.py,sha256=BZYJQF63OtPcBBnQ7_P9gulxzJtqyorgyuDiPeOJqE4,16456
27
27
  dayhoff_tools/warehouse.py,sha256=TqV8nex1AluNaL4JuXH5zuu9P7qmE89lSo6f_oViy6U,14965
28
- dayhoff_tools-1.0.5.dist-info/METADATA,sha256=LE_AxsDAgFzG6oW_i2YL3sZOfbC0V1JDpAidC40Yfek,1930
29
- dayhoff_tools-1.0.5.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
30
- dayhoff_tools-1.0.5.dist-info/entry_points.txt,sha256=iAf4jteNqW3cJm6CO6czLxjW3vxYKsyGLZ8WGmxamSc,49
31
- dayhoff_tools-1.0.5.dist-info/RECORD,,
28
+ dayhoff_tools-1.0.7.dist-info/METADATA,sha256=bR_2zwNuqx_7L8WMJJUGgc-dvXrn69PAM8ppjBMh6-8,1930
29
+ dayhoff_tools-1.0.7.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
30
+ dayhoff_tools-1.0.7.dist-info/entry_points.txt,sha256=iAf4jteNqW3cJm6CO6czLxjW3vxYKsyGLZ8WGmxamSc,49
31
+ dayhoff_tools-1.0.7.dist-info/RECORD,,