utils_devops 0.1.147__py3-none-any.whl → 0.1.149__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.
utils_devops/core/envs.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """
2
- Environment operations for utils_devops (env_ops module).
2
+ Environment operations for utils_devops (envs module).
3
3
 
4
4
  Provides utilities to manage .env files and system environment variables,
5
5
  run commands with specific env settings, and safely update env files with
@@ -66,13 +66,13 @@ class EnvOpsError(Exception):
66
66
 
67
67
 
68
68
  def help() -> None:
69
- """Print a short index of the env_ops API for interactive use."""
69
+ """Print a short index of the envs API for interactive use."""
70
70
  print(
71
71
  """
72
72
  DevOps Utils — Environment Operations Module
73
73
  Key functions:
74
74
  EnvOpsError: Custom exception for environment operations failures.
75
- help() -> None: Print a short index of the env_ops API for interactive use.
75
+ help() -> None: Print a short index of the envs API for interactive use.
76
76
 
77
77
  Loading Environment Files:
78
78
  load_env_file(file_path: Union[str, Path], as_dict: bool = True) -> Union[Dict[str, str], List[str]]: Load a .env file and return a dict of key->value or list of lines.
@@ -1871,6 +1871,8 @@ def _try_environment_authentication(registry: str, registry_info: Dict, logger)
1871
1871
  # Registry-specific (e.g., HARBOR_USER, HARBOR_PASSWORD)
1872
1872
  (f"{_registry_to_env(registry)}_USER", f"{_registry_to_env(registry)}_PASSWORD"),
1873
1873
  # Generic (e.g., DOCKER_USERNAME, DOCKER_PASSWORD)
1874
+ ("HARBOR_USERNAME", "HARBOR_PASSWORD"),
1875
+ ("HARBOR_USER", "HARBOR_PASSWORD"),
1874
1876
  ("DOCKER_USERNAME", "DOCKER_PASSWORD"),
1875
1877
  ("REGISTRY_USERNAME", "REGISTRY_PASSWORD"),
1876
1878
  ("CI_REGISTRY_USER", "CI_REGISTRY_PASSWORD"), # GitLab CI
@@ -3649,7 +3651,6 @@ def docker_login(
3649
3651
  Success status
3650
3652
  """
3651
3653
  logger = logger or DEFAULT_LOGGER
3652
- logger = logger or DEFAULT_LOGGER
3653
3654
  cmd = ['docker', 'login', registry, '-u', username, '-p', password]
3654
3655
  if email:
3655
3656
  cmd.extend(['--email', email]) # Rare, mostly for old Docker Hub
@@ -528,6 +528,37 @@ def _resolve_ssh_key(key_input: Optional[Union[str, Path]]) -> Tuple[Optional[Pa
528
528
  # **IMPORTANT**: Preserve any newlines in the content
529
529
  return None, key_input_str
530
530
 
531
+ def _inject_environment_variables(
532
+ environment: Optional[Dict[str, str]] = None,
533
+ base_command: str = ""
534
+ ) -> str:
535
+ """
536
+ Creates a command string that safely injects environment variables.
537
+ Works for both Windows and Linux remote targets.
538
+ """
539
+ if not environment:
540
+ return base_command
541
+
542
+ # Create a temporary script to set environment and run the command
543
+ env_lines = []
544
+ if systems.is_linux :
545
+ # Linux syntax: export VAR='value'
546
+ for key, value in environment.items():
547
+ escaped_value = value.replace("'", "'\"'\"'")
548
+ env_lines.append(f"export {key}='{escaped_value}'")
549
+ env_setup = " && ".join(env_lines)
550
+ prefix = f"{env_setup} && "
551
+ elif systems.is_windows :
552
+ # Windows syntax (PowerShell)
553
+ for key, value in environment.items():
554
+ # Escape for PowerShell
555
+ escaped_value = value.replace("'", "''").replace("`", "``")
556
+ env_lines.append(f"$env:{key}='{escaped_value}'")
557
+ env_setup = "; ".join(env_lines)
558
+ prefix = f"{env_setup}; "
559
+
560
+ return f"{prefix}{base_command}"
561
+
531
562
  def ssh_execute_command(
532
563
  host: str,
533
564
  command: Union[str, List[str]],
@@ -569,10 +600,10 @@ def ssh_execute_command(
569
600
  else:
570
601
  command_str = command
571
602
 
603
+
572
604
  # Add environment variables
573
605
  if environment:
574
- env_vars = " ".join([f"export {k}='{v}'" for k, v in environment.items()])
575
- command_str = f"{env_vars}; {command_str}"
606
+ command_str = _inject_environment_variables(environment, command_str)
576
607
 
577
608
  # Add sudo
578
609
  if sudo:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: utils_devops
3
- Version: 0.1.147
3
+ Version: 0.1.149
4
4
  Summary: Lightweight DevOps utilities for automation scripts: config editing (YAML/JSON/INI/.env), templating, diffing, and CLI tools
5
5
  License: MIT
6
6
  Keywords: devops,automation,nginx,cli,jinja2,yaml,config,diff,templating,logging,docker,compose,file-ops
@@ -1,7 +1,7 @@
1
1
  utils_devops/__init__.py,sha256=42Tiwb_Yb_QRKVOFHMRMKf-SDvMCd635LzymXz6iMtg,1958
2
2
  utils_devops/core/__init__.py,sha256=-RYyks8jDj0Yb2ZhbmyUX6L8JMS6AB0kIaKMt44V-pE,353
3
3
  utils_devops/core/datetimes.py,sha256=GPGGvASqof3a48e5fiwpLSO2FRM8TGTeoOO1Q7wsVi0,18049
4
- utils_devops/core/envs.py,sha256=yXHYAjdgNOfCxQdIyauBejSXSGUjK5WCQXj8NIjikz4,30515
4
+ utils_devops/core/envs.py,sha256=oVcYdTxjKGzYJVoiHYqf0zGPVAAPSVSE3PRUfMLDxeQ,30506
5
5
  utils_devops/core/files.py,sha256=WwLkEy83PTyIQT2yhYJhJA6xkrMi2mfKoDT45BswlvQ,50289
6
6
  utils_devops/core/logs.py,sha256=xHVSPLE1a7kivrBqQWQdOYjYfm69e2C9yQ7vBu3U68k,30829
7
7
  utils_devops/core/script_helpers.py,sha256=NcOh1f1X_TYm5uuP5YFCYpNF5tr2NVE8DehLj9DMo3c,31480
@@ -9,7 +9,7 @@ utils_devops/core/strings.py,sha256=8s0GSjcyTKwLjJjsJ_XfOJxPtyb549icDlU9SUxSvHI,
9
9
  utils_devops/core/systems.py,sha256=wNbEFUAvbMPdqWN-iXvTzvj5iE9xaWfjZYYvD0EZAH0,47577
10
10
  utils_devops/extras/__init__.py,sha256=ZXHeVLHO3_qiW9AY-UQ_YA9cQzmkLGv54a2UbyvtlM0,3571
11
11
  utils_devops/extras/aws_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- utils_devops/extras/docker_ops.py,sha256=50JEpvcfWOrx9BoSYNFMa3juzV1yDNUd-Xb3Op-oUZk,180628
12
+ utils_devops/extras/docker_ops.py,sha256=fePpj8XC_QxEAa_MxgsGZpEfBr_qQVztw1-9eQzXGu4,180678
13
13
  utils_devops/extras/git_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  utils_devops/extras/interaction_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  utils_devops/extras/metrics_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -17,9 +17,9 @@ utils_devops/extras/network_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
17
17
  utils_devops/extras/nginx_ops.py,sha256=FcfwGSuvcG5OX7UXPJpSTEMEBGYeT2g_I4kbTf-xY0w,100648
18
18
  utils_devops/extras/notification_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  utils_devops/extras/performance_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- utils_devops/extras/ssh_ops.py,sha256=8I_AF0q76CJOK2qp68w1oro2SVOZ_v7b8OvgDYcE4tg,73741
20
+ utils_devops/extras/ssh_ops.py,sha256=jLbroOoYA_v96eXUkhzj77itpYl2Dr6k5mnD6wGHq2k,74812
21
21
  utils_devops/extras/vault_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- utils_devops-0.1.147.dist-info/METADATA,sha256=8uHoh19vkIePxkuSHTBLxxBMyy3Kt_4WDl4wSiJKmcM,1903
23
- utils_devops-0.1.147.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
24
- utils_devops-0.1.147.dist-info/entry_points.txt,sha256=ei3B6ZL5yu6dOq-U1r8wsBdkXeg63RAyV7m8_ADaE6k,53
25
- utils_devops-0.1.147.dist-info/RECORD,,
22
+ utils_devops-0.1.149.dist-info/METADATA,sha256=iOYqaVIlWWwEnvYvbzw0LVnJrrqGrMrejyPTdDtlRPU,1903
23
+ utils_devops-0.1.149.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
24
+ utils_devops-0.1.149.dist-info/entry_points.txt,sha256=ei3B6ZL5yu6dOq-U1r8wsBdkXeg63RAyV7m8_ADaE6k,53
25
+ utils_devops-0.1.149.dist-info/RECORD,,