Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:hiding secrets #6

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions run_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"""Olas Modius Quickstart script."""
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
import sys
import tty
import termios
import getpass
import json
import os
Expand Down Expand Up @@ -128,6 +131,33 @@ def estimate_priority_fee(

return values[len(values) // 2]

def get_masked_input(prompt: str) -> str:
"""Get user input while masking it with asterisks."""
password = ""
sys.stdout.write(prompt)
sys.stdout.flush()

fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
while True:
char = sys.stdin.read(1)
if char == '\r' or char == '\n':
break
if char == '\x7f':
if password:
password = password[:-1]
sys.stdout.write('\b \b')
else:
password += char
sys.stdout.write('*')
sys.stdout.flush()
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
sys.stdout.write('\n')
return password

@dataclass
class OptimusConfig(LocalResource):
"""Local configuration."""
Expand Down Expand Up @@ -213,7 +243,6 @@ def ask_confirm_password() -> str:
print("Passwords do not match. Terminating.")
sys.exit(1)


def check_rpc(rpc_url: str) -> None:
spinner = Halo(text=f"Checking RPC...", spinner="dots")
spinner.start()
Expand Down Expand Up @@ -284,22 +313,22 @@ def configure_local_config() -> OptimusConfig:

if optimus_config.tenderly_access_key is None:
print_section("Tenderly API Configuration and Price Data Source")
optimus_config.tenderly_access_key = input(
optimus_config.tenderly_access_key = get_masked_input(
"Please enter your Tenderly API Key. Get one at https://dashboard.tenderly.co/: "
)

if optimus_config.tenderly_account_slug is None:
optimus_config.tenderly_account_slug = input(
optimus_config.tenderly_account_slug = get_masked_input(
"Please enter your Tenderly Account Slug: "
)

if optimus_config.tenderly_project_slug is None:
optimus_config.tenderly_project_slug = input(
optimus_config.tenderly_project_slug = get_masked_input(
"Please enter your Tenderly Project Slug: "
)

if optimus_config.coingecko_api_key is None:
optimus_config.coingecko_api_key = input(
optimus_config.coingecko_api_key = get_masked_input(
"Please enter your CoinGecko API Key. Get one at https://www.coingecko.com/: "
)
print()
Expand Down Expand Up @@ -358,7 +387,7 @@ def configure_local_config() -> OptimusConfig:

if optimus_config.mode_rpc is None:
print_section("Chain RPC")
optimus_config.mode_rpc = input("Please enter a Mode RPC URL: ")
optimus_config.mode_rpc = get_masked_input("Please enter a Mode RPC URL: ")

print()

Expand Down