Skip to content

Commit 2a8a3a5

Browse files
author
Théo LAGACHE
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents ec61d7c + 9ef7abb commit 2a8a3a5

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

commands/agent.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def agent(
7272
if polling == 5:
7373
polling = IntPrompt.ask("Polling frequency (seconds)", default=5)
7474

75+
add_host_gateway = Confirm.ask(
76+
"Add extra_hosts mapping (localhost -> host-gateway)?", default=False
77+
)
78+
7579
raw_template = fetch_template("agent.yml")
7680

7781
if "{{EXTRA_SERVICES}}" not in raw_template:
@@ -192,7 +196,11 @@ def agent(
192196
),
193197
)
194198
user = Prompt.ask("Username")
195-
password = Prompt.ask("Password", password=True)
199+
password = questionary.password(
200+
"Password", style=questionary_style
201+
).ask()
202+
if password is None:
203+
raise typer.Exit()
196204

197205
add_db_to_json(
198206
path,
@@ -691,6 +699,14 @@ def agent(
691699
" - ./databases.json:/config/config.json", vols_str
692700
)
693701

702+
if add_host_gateway:
703+
final_compose = final_compose.replace(
704+
" image: portabase/agent:latest\n",
705+
' image: portabase/agent:latest\n'
706+
' extra_hosts:\n'
707+
' - "localhost:host-gateway"\n',
708+
)
709+
694710
summary = Table(show_header=False, box=None, padding=(0, 2))
695711
summary.add_column("Property", style="bold cyan")
696712
summary.add_column("Value", style="white")
@@ -700,6 +716,7 @@ def agent(
700716
summary.add_row("Edge Key", f"{key[:10]}...{key[-10:]}" if len(key) > 20 else key)
701717
summary.add_row("Timezone", tz)
702718
summary.add_row("Polling", f"{polling}s")
719+
summary.add_row("Host Gateway", "Yes" if add_host_gateway else "No")
703720

704721
db_config = load_db_config(path)
705722
dbs = db_config.get("databases", [])

commands/dashboard.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import secrets
33
from pathlib import Path
4+
from urllib.parse import quote
45

56
import questionary
67
import typer
@@ -84,7 +85,7 @@ def dashboard(
8485
"POSTGRES_USER": "portabase",
8586
"POSTGRES_PASSWORD": pg_pass,
8687
"POSTGRES_HOST": "db",
87-
"DATABASE_URL": f"postgresql://portabase:{pg_pass}@db:5432/portabase?schema=public",
88+
"DATABASE_URL": f"postgresql://portabase:{quote(pg_pass, safe='')}@db:5432/portabase?schema=public",
8889
"PG_PORT": str(pg_port),
8990
}
9091
)
@@ -95,35 +96,41 @@ def dashboard(
9596
db_port = IntPrompt.ask("Port", default=5432)
9697
db_name = Prompt.ask("Database Name", default="portabase")
9798
db_user = Prompt.ask("Username")
98-
db_pass = Prompt.ask("Password", password=True)
99+
db_pass = questionary.password("Password", style=questionary_style).ask()
100+
if db_pass is None:
101+
raise typer.Exit()
99102

100103
env_vars.update(
101104
{
102105
"POSTGRES_DB": db_name,
103106
"POSTGRES_USER": db_user,
104107
"POSTGRES_PASSWORD": db_pass,
105108
"POSTGRES_HOST": db_host,
106-
"DATABASE_URL": f"postgresql://{db_user}:{db_pass}@{db_host}:{db_port}/{db_name}?schema=public",
109+
"DATABASE_URL": f"postgresql://{quote(db_user, safe='')}:{quote(db_pass, safe='')}@{db_host}:{db_port}/{db_name}?schema=public",
107110
"PG_PORT": str(db_port),
108111
}
109112
)
110113

111114
final_compose = re.sub(
112-
r"[ ]{8}depends_on:.*?service_healthy\n", "", raw_template, flags=re.DOTALL
115+
r"[ ]{4}depends_on:\n[ ]{6}db:\n[ ]{8}condition: service_healthy\n",
116+
"",
117+
raw_template,
113118
)
114119
final_compose = re.sub(
115-
r"[ ]{4}db:.*?retries: 5\n", "", final_compose, flags=re.DOTALL
120+
r"[ ]{2}db:.*?retries: 5\n", "", final_compose, flags=re.DOTALL
116121
)
117-
final_compose = re.sub(r"[ ]{4}postgres-data:\n", "", final_compose)
122+
final_compose = re.sub(r"[ ]{2}postgres-data:\n", "", final_compose)
118123
final_compose = final_compose.replace("${PROJECT_NAME}", project_name)
119124
else:
120125
final_compose = re.sub(
121-
r"[ ]{8}depends_on:.*?service_healthy\n", "", raw_template, flags=re.DOTALL
126+
r"[ ]{4}depends_on:\n[ ]{6}db:\n[ ]{8}condition: service_healthy\n",
127+
"",
128+
raw_template,
122129
)
123130
final_compose = re.sub(
124-
r"[ ]{4}db:.*?retries: 5\n", "", final_compose, flags=re.DOTALL
131+
r"[ ]{2}db:.*?retries: 5\n", "", final_compose, flags=re.DOTALL
125132
)
126-
final_compose = re.sub(r"[ ]{4}postgres-data:\n", "", final_compose)
133+
final_compose = re.sub(r"[ ]{2}postgres-data:\n", "", final_compose)
127134
final_compose = final_compose.replace("${PROJECT_NAME}", project_name)
128135

129136
summary = Table(show_header=False, box=None, padding=(0, 2))

commands/db.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def add_db(name: str = typer.Argument(..., help="Name of the agent")):
146146
),
147147
)
148148
user = Prompt.ask("Username")
149-
password = Prompt.ask("Password", password=True)
149+
password = questionary.password(
150+
"Password", style=questionary_style
151+
).ask()
152+
if password is None:
153+
raise typer.Exit()
150154

151155
entry = {
152156
"name": friendly_name,

0 commit comments

Comments
 (0)