utils_devops 0.1.149__tar.gz → 0.1.151__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.
- {utils_devops-0.1.149 → utils_devops-0.1.151}/PKG-INFO +1 -1
- {utils_devops-0.1.149 → utils_devops-0.1.151}/pyproject.toml +1 -1
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/ssh_ops.py +47 -7
- {utils_devops-0.1.149 → utils_devops-0.1.151}/README.md +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/__init__.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/__init__.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/datetimes.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/envs.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/files.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/logs.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/script_helpers.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/strings.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/core/systems.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/__init__.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/aws_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/docker_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/git_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/interaction_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/metrics_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/network_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/nginx_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/notification_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/performance_ops.py +0 -0
- {utils_devops-0.1.149 → utils_devops-0.1.151}/src/utils_devops/extras/vault_ops.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: utils_devops
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.151
|
|
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,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "utils_devops"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.151" # Bumped for new string features + diffing
|
|
4
4
|
description = "Lightweight DevOps utilities for automation scripts: config editing (YAML/JSON/INI/.env), templating, diffing, and CLI tools"
|
|
5
5
|
authors = ["Hamed Sheikhan <sh.sheikhan.m@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -530,28 +530,28 @@ def _resolve_ssh_key(key_input: Optional[Union[str, Path]]) -> Tuple[Optional[Pa
|
|
|
530
530
|
|
|
531
531
|
def _inject_environment_variables(
|
|
532
532
|
environment: Optional[Dict[str, str]] = None,
|
|
533
|
-
base_command: str = ""
|
|
533
|
+
base_command: str = "",
|
|
534
|
+
remote_os: str = "linux"
|
|
534
535
|
) -> str:
|
|
535
536
|
"""
|
|
536
537
|
Creates a command string that safely injects environment variables.
|
|
537
|
-
Works for both Windows and Linux remote targets.
|
|
538
538
|
"""
|
|
539
539
|
if not environment:
|
|
540
540
|
return base_command
|
|
541
541
|
|
|
542
|
-
# Create a temporary script to set environment and run the command
|
|
543
542
|
env_lines = []
|
|
544
|
-
if
|
|
543
|
+
if remote_os is "linux":
|
|
545
544
|
# Linux syntax: export VAR='value'
|
|
546
545
|
for key, value in environment.items():
|
|
546
|
+
print(f"DEBUG _inject_environment_variables: key='{key}', value='{value}', type={type(value)}") # DEBUG
|
|
547
547
|
escaped_value = value.replace("'", "'\"'\"'")
|
|
548
548
|
env_lines.append(f"export {key}='{escaped_value}'")
|
|
549
549
|
env_setup = " && ".join(env_lines)
|
|
550
550
|
prefix = f"{env_setup} && "
|
|
551
|
-
elif
|
|
551
|
+
elif remote_os is "windows":
|
|
552
552
|
# Windows syntax (PowerShell)
|
|
553
553
|
for key, value in environment.items():
|
|
554
|
-
|
|
554
|
+
print(f"DEBUG _inject_environment_variables: key='{key}', value='{value}', type={type(value)}") # DEBUG
|
|
555
555
|
escaped_value = value.replace("'", "''").replace("`", "``")
|
|
556
556
|
env_lines.append(f"$env:{key}='{escaped_value}'")
|
|
557
557
|
env_setup = "; ".join(env_lines)
|
|
@@ -559,6 +559,41 @@ def _inject_environment_variables(
|
|
|
559
559
|
|
|
560
560
|
return f"{prefix}{base_command}"
|
|
561
561
|
|
|
562
|
+
def _detect_remote_os(client) -> str:
|
|
563
|
+
"""
|
|
564
|
+
Detect the operating system of the remote SSH host.
|
|
565
|
+
Returns: "linux", "windows", or "unknown"
|
|
566
|
+
"""
|
|
567
|
+
try:
|
|
568
|
+
# Try Linux command first
|
|
569
|
+
stdin, stdout, stderr = client.exec_command("uname -s", timeout=5)
|
|
570
|
+
output = stdout.read().decode('utf-8', errors='ignore').strip().lower()
|
|
571
|
+
if "linux" in output or "darwin" in output:
|
|
572
|
+
return "linux"
|
|
573
|
+
except:
|
|
574
|
+
pass
|
|
575
|
+
|
|
576
|
+
try:
|
|
577
|
+
# Try Windows command
|
|
578
|
+
stdin, stdout, stderr = client.exec_command("ver", timeout=5)
|
|
579
|
+
output = stdout.read().decode('utf-8', errors='ignore').strip().lower()
|
|
580
|
+
if "windows" in output or "microsoft" in output:
|
|
581
|
+
return "windows"
|
|
582
|
+
except:
|
|
583
|
+
pass
|
|
584
|
+
|
|
585
|
+
# Try PowerShell (Windows)
|
|
586
|
+
try:
|
|
587
|
+
stdin, stdout, stderr = client.exec_command("Get-Host", timeout=5)
|
|
588
|
+
output = stdout.read().decode('utf-8', errors='ignore').strip().lower()
|
|
589
|
+
if "powershell" in output or "windows" in output:
|
|
590
|
+
return "windows"
|
|
591
|
+
except:
|
|
592
|
+
pass
|
|
593
|
+
|
|
594
|
+
# Default to linux (backward compatibility)
|
|
595
|
+
return "linux"
|
|
596
|
+
|
|
562
597
|
def ssh_execute_command(
|
|
563
598
|
host: str,
|
|
564
599
|
command: Union[str, List[str]],
|
|
@@ -600,10 +635,15 @@ def ssh_execute_command(
|
|
|
600
635
|
else:
|
|
601
636
|
command_str = command
|
|
602
637
|
|
|
638
|
+
with ssh_connect(
|
|
639
|
+
host, username, password, key_file, port, **kwargs
|
|
640
|
+
) as client:
|
|
641
|
+
# 1. DETECT REMOTE OS
|
|
642
|
+
remote_os = _detect_remote_os(client)
|
|
603
643
|
|
|
604
644
|
# Add environment variables
|
|
605
645
|
if environment:
|
|
606
|
-
command_str = _inject_environment_variables(environment, command_str)
|
|
646
|
+
command_str = _inject_environment_variables(environment, command_str,remote_os=remote_os)
|
|
607
647
|
|
|
608
648
|
# Add sudo
|
|
609
649
|
if sudo:
|
|
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
|
|
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
|
|
File without changes
|