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

Include SSH key as an interaction item when configuring parameters #464

Merged
merged 2 commits into from
Oct 9, 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
22 changes: 20 additions & 2 deletions common/config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,23 @@ def build_configuration(self):
ob_cluster_name = self.get_cluster_name()
self.stdio.print("\033[33mPlease enter the following configuration !!!\033[0m")
global_ssh_username = self.input_with_default("oceanbase host ssh username", "")
global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "")
use_password_tag = self.input_choice_by_nu("use password or key file (0:use password; 1:use key file) default: 0", 0)
global_ssh_password = ""
global_ssh_key_file = ""
if use_password_tag == 0:
global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "")
elif use_password_tag == 1:
global_ssh_key_file = self.input_with_default("oceanbase host ssh key file", "~/.ssh/id_rsa")
else:
self.stdio.warn("Invalid input, use default: use password")
global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "")
global_ssh_port = self.input_with_default("oceanbase host ssh_port", "22")
global_home_path = self.input_with_default("oceanbase install home_path", const.OB_INSTALL_DIR_DEFAULT)
default_data_dir = os.path.join(global_home_path, "store")
global_data_dir = default_data_dir
global_redo_dir = default_data_dir
tenant_sys_config = {"user": self.sys_tenant_user, "password": self.sys_tenant_password}
global_config = {"ssh_username": global_ssh_username, "ssh_password": global_ssh_password, "ssh_port": global_ssh_port, "ssh_key_file": "", "home_path": global_home_path, "data_dir": global_data_dir, "redo_dir": global_redo_dir}
global_config = {"ssh_username": global_ssh_username, "ssh_password": global_ssh_password, "ssh_port": global_ssh_port, "ssh_key_file": global_ssh_key_file, "home_path": global_home_path, "data_dir": global_data_dir, "redo_dir": global_redo_dir}
new_config = {"obcluster": {"ob_cluster_name": ob_cluster_name, "db_host": self.db_host, "db_port": self.db_port, "tenant_sys": tenant_sys_config, "servers": {"nodes": nodes_config, "global": global_config}}}
YamlUtils.write_yaml_data(new_config, self.config_path)
need_config_obproxy = self.input_choice_default("need config obproxy [y/N]", "N")
Expand Down Expand Up @@ -170,3 +179,12 @@ def input_choice_default(self, prompt, default):
return True
else:
return False

def input_choice_by_nu(self, prompt, default):
value = input("\033[32mEnter your {0}: \033[0m".format(prompt)).strip()
if value == '':
return int(default)
if not value.isdigit():
self.stdio.error("The number is invalid! Please re-enter.")
return self.input_choice_by_nu(prompt, default)
return int(value)
Loading