Exemplo n.º 1
0
 def do_auth(self, args):
     """Authenticate with a faraday server"""
     faraday_url = args.faraday_url
     user = args.user
     password = args.password
     ignore_ssl = args.ignore_ssl
     if not faraday_url:
         faraday_url = utils.validate_url(
             click.prompt("Faraday url", default=active_config.faraday_url))
         url_data = urlparse(faraday_url)
         if url_data.scheme == "https":
             ignore_ssl = (click.prompt(
                 f"Validate SSL certificate for [{faraday_url}]",
                 type=click.Choice(choices=["Y", "N"],
                                   case_sensitive=False),
                 default="Y",
             ) == "N")
     else:
         faraday_url = utils.validate_url(faraday_url)
     if not user:
         user = click.prompt("User")
     if not password:
         password = click.prompt("Password", hide_input=True)
     try:
         api_client = FaradayApi(faraday_url, ignore_ssl=ignore_ssl)
         login_ok = api_client.login(user, password)
         if login_ok is None or login_ok is True:
             if login_ok is None:
                 # 2FA Required
                 second_factor = click.prompt("2FA")
             else:
                 second_factor = None
             token = api_client.get_token(user, password, second_factor)
             active_config.faraday_url = faraday_url
             active_config.ignore_ssl = args.ignore_ssl
             active_config.token = token
             active_config.workspace = None
             active_config.save()
             self.api_client = FaradayApi(faraday_url,
                                          ignore_ssl=ignore_ssl,
                                          token=token)
             self.poutput(style("Saving config", fg="green"))
             self.poutput(
                 style(
                     f"{self.emojis['check']} Authenticated with faraday: {faraday_url}",
                     fg="green",
                 ))
             self.update_prompt()
         else:
             self.perror("Invalid credentials")
     except Invalid2FA:
         self.perror("Invalid 2FA")
     except InvalidCredentials:
         self.perror("Invalid credentials")
     except ClientError:
         self.perror("Invalid credentials")
     except ClientConnectionError as e:
         self.perror(f"Connection refused: {e}")
     except Exception as e:
         self.perror(f"{e}")
Exemplo n.º 2
0
 def _onchange_custom_plugins_path(self, param_name, old, new):
     custom_plugins_path = Path(new)
     if custom_plugins_path.is_dir():
         active_config.custom_plugins_path = new
         active_config.save()
         self.custom_plugins_path = new
         self._create_plugin_manager()
     else:
         self.perror(f"Invalid Path: {new}")
         self.custom_plugins_path = old
Exemplo n.º 3
0
 def do_select_ws(self, args):
     """Select active Workspace"""
     if self._cmd.api_client.is_workspace_valid(args.workspace_name):
         active_config.workspace = args.workspace_name
         active_config.save()
         self._cmd.poutput(
             style(
                 f"{self._cmd.emojis['check']} "
                 f"Selected workspace: {args.workspace_name}",
                 fg="green",
             ))
         self._cmd.update_prompt()
     else:
         self._cmd.perror(f"{self._cmd.emojis['cross']} "
                          f"Invalid workspace: {args.workspace_name}")
Exemplo n.º 4
0
 def select_ws(self, args: argparse.Namespace):
     """Select active Workspace"""
     if self._cmd.api_client.is_workspace_available(args.workspace_name):
         active_config.workspace = args.workspace_name
         active_config.save()
         self._cmd.poutput(
             cmd2.style(
                 f"{self._cmd.emojis['check']} "
                 f"Selected workspace: {args.workspace_name}",
                 fg=COLORS.GREEN,
             ))
         self._cmd.update_prompt()
     else:
         self._cmd.perror(f"{self._cmd.emojis['cross']} "
                          f"Invalid workspace: {args.workspace_name}")
Exemplo n.º 5
0
 def do_delete_ws(self, args):
     """Delete Workspace"""
     workspaces = self._cmd.api_client.get_workspaces()
     workspace_choices = [ws for ws in map(lambda x: x["name"], workspaces)]
     workspace_name = args.workspace_name
     if workspace_name not in workspace_choices:
         self._cmd.perror(f"Invalid workspace: {workspace_name}")
         return
     self._cmd.poutput(f"Deleting workspace: {workspace_name}")
     self._cmd.api_client.delete_workspace(workspace_name)
     self._cmd.poutput(
         style(f"Deleted workspace: {args.workspace_name}", fg="green"))
     if active_config.workspace == workspace_name:
         active_config.workspace = None
         active_config.save()
     self._cmd.update_prompt()
Exemplo n.º 6
0
 def _select_workspace(selected_workspace):
     workspaces = api_client.get_workspaces()
     workspace_choices = [ws for ws in map(lambda x: x['name'], workspaces)]
     if not selected_workspace:
         selected_workspace = click.prompt(
             f"Select workspace",
             type=click.Choice(choices=workspace_choices,
                               case_sensitive=False),
         )
     else:
         if selected_workspace not in workspace_choices:
             click.secho(f"Invalid worskpace: {selected_workspace}",
                         fg="red")
             return
     click.secho(f"Selected Workspace: {selected_workspace}", fg="green")
     active_config.workspace = selected_workspace
     active_config.save()
Exemplo n.º 7
0
 def do_create_ws(self, args):
     """Create Workspace"""
     workspace_name = args.workspace_name
     try:
         self._cmd.api_client.create_workspace(workspace_name)
     except Exception as e:
         self._cmd.perror(f"{e}")
     else:
         self._cmd.poutput(
             style(
                 f"{self._cmd.emojis['check']} "
                 f"Created workspace: {args.workspace_name}",
                 fg="green",
             ))
         if not args.dont_select:
             active_config.workspace = workspace_name
             active_config.save()
             self._cmd.update_prompt()
Exemplo n.º 8
0
 def create_ws(self, args: argparse.Namespace):
     """Create Workspace"""
     workspace_name = args.workspace_name
     try:
         self._cmd.api_client.create_workspace(workspace_name)
     except Exception as e:
         self._cmd.perror(f"{e}")
     else:
         self._cmd.poutput(
             cmd2.style(
                 f"{self._cmd.emojis['check']} "
                 f"Created workspace: {args.workspace_name}",
                 fg=COLORS.GREEN,
             ))
         if not args.dont_select:
             active_config.workspace = workspace_name
             active_config.save()
             self._cmd.update_prompt()
Exemplo n.º 9
0
def auth(url, user, password):
    url_data = urlparse(url)
    ssl_verify = False
    if url_data.scheme == "https":
        ssl_verify = click.prompt(f"Validate SSL certificate for [{url}]",
                                  type=click.Choice(choices=["Y", "N"],
                                                    case_sensitive=False),
                                  default="Y") == "Y"

    api_client = FaradayApi(url, ssl_verify=ssl_verify)
    try:
        token = api_client.get_token(user, password)
        active_config.faraday_url = url
        active_config.ssl_verify = ssl_verify
        active_config.token = token
        active_config.save()
        click.secho(f"Saving config", fg="green")
    except Exception as e:
        click.secho(f"{e}", fg="red")
Exemplo n.º 10
0
 def _delete_workspace(workspace_to_delete):
     workspaces = api_client.get_workspaces()
     workspace_choices = [ws for ws in map(lambda x: x['name'], workspaces)]
     if not workspace_to_delete:
         workspace_to_delete = click.prompt(
             f"Select workspace",
             type=click.Choice(choices=workspace_choices,
                               case_sensitive=False),
         )
     else:
         if workspace_to_delete not in workspace_choices:
             click.secho(f"Invalid worskpace: {workspace_to_delete}",
                         fg="red")
             return
     response = api_client.delete_workspace(workspace_to_delete)
     click.secho(f"Deleted workspace: {workspace_to_delete}", fg="green")
     if active_config.workspace == workspace_to_delete:
         active_config.workspace = None
         active_config.save()
Exemplo n.º 11
0
 def disable_ws(self, args: argparse.Namespace):
     """Disable Workspace"""
     workspace_name = args.workspace_name
     try:
         self._cmd.api_client.disable_workspace(workspace_name)
     except NotFoundError:
         self._cmd.perror(f"Invalid Workspace: {workspace_name}")
     except Exception as e:
         self._cmd.perror(f"{e}")
     else:
         self._cmd.poutput(
             cmd2.style(
                 f"{self._cmd.emojis['check']} "
                 f"Disabled workspace: {workspace_name}",
                 fg=COLORS.GREEN,
             ))
     if active_config.workspace == workspace_name:
         active_config.workspace = None
         active_config.save()
     self._cmd.update_prompt()
Exemplo n.º 12
0
 def _onchange_auto_command_detection(self, param_name, old, new):
     active_config.auto_command_detection = new
     active_config.save()
     self.auto_command_detection = new
Exemplo n.º 13
0
 def _onchange_ignore_info_severity(self, param_name, old, new):
     active_config.ignore_info_severity = new
     active_config.save()
     self.ignore_info_severity = new
     self._create_plugin_manager()
Exemplo n.º 14
0
 def _onchange_custom_plugins_path(self, param_name, old, new):
     custom_plugins_path = Path(new)
     if custom_plugins_path.is_dir():
         active_config.custom_plugins_path = new
         active_config.save()