Skip to content

Commit

Permalink
Tunneling command prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
miroberts committed Feb 13, 2024
1 parent bf82b0d commit 21f0e3c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions keepercommander/commands/discoveryrotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ def execute(self, params, **kwargs):

############################################## TUNNELING ###############################################################
class PAMTunnelListCommand(Command):
pam_cmd_parser = argparse.ArgumentParser(prog='dr-tunnel-list-command')
pam_cmd_parser = argparse.ArgumentParser(prog='pam tunnel list')

def get_parser(self):
return PAMTunnelListCommand.pam_cmd_parser
Expand Down Expand Up @@ -1648,7 +1648,7 @@ def clean_up_tunnel(params, convo_id):


class PAMTunnelStopCommand(Command):
pam_cmd_parser = argparse.ArgumentParser(prog='dr-tunnel-stop-command')
pam_cmd_parser = argparse.ArgumentParser(prog='pam tunnel stop')
pam_cmd_parser.add_argument('uid', type=str, action='store', help='The Tunnel UID')

def get_parser(self):
Expand All @@ -1668,7 +1668,7 @@ def execute(self, params, **kwargs):


class PAMTunnelTailCommand(Command):
pam_cmd_parser = argparse.ArgumentParser(prog='dr-tunnel-tail-command')
pam_cmd_parser = argparse.ArgumentParser(prog='pam tunnel tail')
pam_cmd_parser.add_argument('uid', type=str, action='store', help='The Tunnel UID')

def get_parser(self):
Expand Down Expand Up @@ -1737,7 +1737,7 @@ def retrieve_gateway_public_key(gateway_uid, params, api, utils) -> bytes:


class PAMTunnelEnableCommand(Command):
pam_cmd_parser = argparse.ArgumentParser(prog='dr-tunnel-enable-command')
pam_cmd_parser = argparse.ArgumentParser(prog='pam tunnel enable')
pam_cmd_parser.add_argument('uid', type=str, action='store', help='The Record UID of the PAM '
'resource record with network information to use '
'for tunneling')
Expand Down Expand Up @@ -1829,7 +1829,7 @@ def execute(self, params, **kwargs):


class PAMTunnelDisableCommand(Command):
pam_cmd_parser = argparse.ArgumentParser(prog='dr-tunnel-disable-command')
pam_cmd_parser = argparse.ArgumentParser(prog='pam tunnel disable')
pam_cmd_parser.add_argument('uid', type=str, action='store', help='The Record UID of the PAM '
'resource record with network information to use '
'for tunneling')
Expand Down Expand Up @@ -1859,10 +1859,10 @@ def execute(self, params, **kwargs):


class PAMTunnelStartCommand(Command):
pam_cmd_parser = argparse.ArgumentParser(prog='dr-port-forward-command')
pam_cmd_parser.add_argument('--record', '-r', required=True, dest='record_uid', action='store',
help='The Record UID of the PAM resource record with network information to use for '
'tunneling')
pam_cmd_parser = argparse.ArgumentParser(prog='pam tunnel start')
pam_cmd_parser.add_argument('uid', type=str, action='store', help='The Record UID of the PAM resource '
'record with network information to use for '
'tunneling')
pam_cmd_parser.add_argument('--host', '-o', required=False, dest='host', action='store',
default="127.0.0.1",
help='The address on which the server will be accepting connections. It could be an '
Expand Down Expand Up @@ -2062,7 +2062,7 @@ def execute(self, params, **kwargs):
f"You are using {major_version}.{minor_version}.{micro_version}.{bcolors.ENDC}")
return

record_uid = kwargs.get('record_uid')
record_uid = kwargs.get('uid')
convo_id = GatewayAction.generate_conversation_id()
params.tunnel_threads[convo_id] = {}
host = kwargs.get('host')
Expand All @@ -2087,14 +2087,17 @@ def execute(self, params, **kwargs):

pam_settings = record.get_typed_field('pamSettings')
if not pam_settings:
print(f"{bcolors.FAIL}PAM Settings not enabled for record {record_uid}.{bcolors.ENDC}")
print(f"{bcolors.FAIL}PAM Settings not enabled for record {record_uid}'.{bcolors.ENDC}")
print(f"{bcolors.WARNING}This is done by running 'pam tunnel enable {record_uid} "
f"--config [ConfigUID]' The ConfigUID can be found by running 'pam config list'{bcolors.ENDC}.")
return

try:
pam_info = pam_settings.value[0]
enabled_port_forward = pam_info.get("portForward", {}).get("enabled", False)
if not enabled_port_forward:
print(f"{bcolors.FAIL}PAM Settings not enabled for record {record_uid}.{bcolors.ENDC}")
print(f"{bcolors.FAIL}PAM Settings not enabled for record {record_uid}. "
f"{bcolors.WARNING}This is done by running 'pam tunnel enable {record_uid}'.{bcolors.ENDC}")
return
except Exception as e:
print(f"{bcolors.FAIL}Error parsing PAM Settings for record {record_uid}: {e}{bcolors.ENDC}")
Expand Down

0 comments on commit 21f0e3c

Please sign in to comment.