-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.py
executable file
·99 lines (87 loc) · 2.54 KB
/
checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/python3
import shutil
import subprocess
import json
import os
HOME_DIR=str(os.getenv('HOME'))
NUGET_PASSWORD=str(os.getenv('PTM_NUGET_PASSWORD'))
DEBUG = str(os.getenv('DEBUG', 'false')).lower() == 'true'
# Check if executable exists
def check_command(command, description):
if shutil.which(command):
print(f"{description}: OK")
else:
print(f"{description}: Fail")
def cleanup():
subprocess.run(
["rm", "-rf", "/tmp/ptm-tools"]
)
# a dict of executable/description
exec_check_commands = {
"git": "Git",
"docker": "Docker",
"gcloud": "Google Cloud CLI",
"ptm-tools": "PTM-Tools CLI",
"dbeaver": "DBeaver",
"cloud-sql-proxy": "CloudSQL Proxy"
}
# a tuple with commands to check if env is setup
env_commands = [
(
["gcloud", "auth", "list", "--format", "json"],
"Login do gcloud",
True
),
(
["cat", HOME_DIR+"/.config/gcloud/application_default_credentials.json"],
"GCloud ADC",
False
),
(
["git", "clone", "--depth", "1", "git@github.com:PortalTelemedicina/ptm-tools", "/tmp/ptm-tools"],
"Chave pública configurada no GitHub",
False
),
(
["grep", "ptm-iac-dev", HOME_DIR+"/.kube/config"],
"Credenciais do cluster de desenvolvimento",
False
),
(
["curl", "-s", "--fail", "-u", "appsettings:"+NUGET_PASSWORD, "https://nuget.ptmdev.com.br/v3/index.json"],
"Senha do servidor NUGET",
False
),
]
# Function to run a command and check its output and exit code
def run_command(command, description, jsonOutputValidation):
try:
result = subprocess.run(
command,
text=True,
capture_output=True,
check=False
)
if result.returncode == 0:
if jsonOutputValidation:
parsed_json = json.loads(result.stdout)
len(parsed_json) > 0
print(f"{description}: OK")
else:
print(f"{description}: Fail")
if DEBUG:
print(f"Error: {result.stderr.strip()}")
print(f"Exit Code: {result.returncode}")
except FileNotFoundError:
print(f"{description}: Command not found")
print("=== Verificando executáveis disponíveis na máquina ===")
for cmd, desc in exec_check_commands.items():
check_command(cmd, desc)
print("Feito!")
print("\n=== Verificando configurações do ambiente ===")
for cmd, desc, validation in env_commands:
run_command(cmd, desc, validation)
print("Feito!")
print("\nAnálise finalizada!")
print("Limpando...")
cleanup()