Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import os
import pickle
from json import loads
from rich.console import Console
from test_junkie.cli.config.Config import Config
console = Console()
class Agent:
def __init__(self):
pass
@staticmethod
def get_agent(host):
return f"{Config.get_agents_root_dir()}{os.sep}{Agent.md5(host)}.pickle"
@staticmethod
def md5(host):
import hashlib
m = hashlib.md5()
def test_output_console(self):
"""Test Formatting Output as console"""
console = Console(file=self.mock_file)
output_console(self.MOCK_OUTPUT, console=console)
expected_output = "│ vendorname0 │ productname0 │ 1.0 │ CVE-1234-1234 │ MEDIUM │\n│ vendorname0 │ productname0 │ 1.0 │ CVE-1234-9876 │ LOW │\n│ vendorname0 │ productname0 │ 2.8.6 │ CVE-1234-1111 │ LOW │\n│ vendorname1 │ productname1 │ 3.2.1.0 │ CVE-1234-5678 │ HIGH │\n└──────────────┴───────────────┴──────────┴────────────────┴──────────┘\n"
self.mock_file.seek(0) # reset file position
self.assertIn(expected_output, self.mock_file.read())
from rich.console import Console
import sys
import time
# external lib
import arrow
from starlette.config import Config
# yeoboseyo
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_FOLDER = os.path.dirname(PROJECT_DIR)
sys.path.append(PARENT_FOLDER)
from yeoboseyo.models import Trigger
from yeoboseyo import Joplin, Rss
console = Console()
config = Config('.env')
async def _update_date(trigger_id) -> None:
"""
update the database table with the execution date
:param trigger_id: id to update
:return: nothing
"""
now = arrow.utcnow().to(config('TIME_ZONE')).format('YYYY-MM-DD HH:mm:ssZZ')
trigger = await Trigger.objects.get(id=trigger_id)
await trigger.update(date_triggered=now)
def get_published(entry) -> datetime:
from starlette.config import Config
from starlette.responses import JSONResponse
from starlette.routing import Mount, Route, Router
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates
# uvicorn
import uvicorn
# yeoboseyo
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_FOLDER = os.path.dirname(PROJECT_DIR)
sys.path.append(PARENT_FOLDER)
from yeoboseyo.forms import TriggerSchema
from yeoboseyo.models import Trigger
console = Console()
templates = Jinja2Templates(directory="templates")
statics = StaticFiles(directory="static")
config = Config('.env')
main_app = Starlette()
main_app.debug = config('', default=False)
async def homepage(request):
MY_NOTES_FOLDER = config.get('MY_NOTES_FOLDER')
context = {"request": request, 'MY_NOTES_FOLDER': MY_NOTES_FOLDER}
return templates.TemplateResponse("base.html", context)
async def get_all(request):
# coding: utf-8
import argparse
import arrow
import asyncio
import os
import sys
from starlette.config import Config
from rich.console import Console
from rich.table import Table
console = Console()
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_FOLDER = os.path.dirname(PROJECT_DIR)
sys.path.append(PARENT_FOLDER)
from yeoboseyo.models import Trigger
from yeoboseyo.go import go
config = Config('.env')
async def report():
triggers = await Trigger.objects.all()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("ID")
table.add_column("Name")
table.add_column("Md Folder")
def setup_console(self):
if self.headless:
self.console = Console(record=True)
if self.os == 'Windows':
window = windll.kernel32.GetConsoleWindow()
if window:
windll.user32.ShowWindow(window, 0)
elif 'WINDIR' in os.environ and 'WT_SESSION' not in os.environ:
set_terminal_size(100, 50)
windll.kernel32.SetConsoleScreenBufferSize(windll.kernel32.GetStdHandle(-11), wintypes._COORD(100, 200))
self.console = Console(width=97)
elif self.os == 'Darwin':
set_terminal_size(100, 50)
self.console = Console()
else:
self.console = Console()
def output_console(self, console=Console()):
""" Output list of CVEs in a tabular format with color support """
# table instance
table = Table()
# Add Head Columns to the Table
table.add_column("Vendor")
table.add_column("Product")
table.add_column("Version")
table.add_column("CVE Number")
table.add_column("Severity")
# colors provide color name according to the severity
colors = {"CRITICAL": "red", "HIGH": "blue", "MEDIUM": "yellow", "LOW": "green"}
# Add CVEData to the table
def setup_console(self):
if self.headless:
self.console = Console(record=True)
if self.os == 'Windows':
window = windll.kernel32.GetConsoleWindow()
if window:
windll.user32.ShowWindow(window, 0)
elif 'WINDIR' in os.environ and 'WT_SESSION' not in os.environ:
set_terminal_size(100, 50)
windll.kernel32.SetConsoleScreenBufferSize(windll.kernel32.GetStdHandle(-11), wintypes._COORD(100, 200))
self.console = Console(width=97)
elif self.os == 'Darwin':
set_terminal_size(100, 50)
self.console = Console()
else:
self.console = Console()