From 5048f679ee81af6dc9eb6ba62977eb99db6066ce Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 15 Dec 2022 22:38:11 -0800 Subject: [PATCH] Remove old teststation sections --- scripts/wk/cfg/osticket.py | 30 ------------------------------ scripts/wk/osticket.py | 27 +++++++++++---------------- 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/scripts/wk/cfg/osticket.py b/scripts/wk/cfg/osticket.py index e2337360..e10361c6 100644 --- a/scripts/wk/cfg/osticket.py +++ b/scripts/wk/cfg/osticket.py @@ -12,36 +12,6 @@ STAFF = { 'ID': '23', 'Name': 'Wizard Kit', } -TEST_STATIONS = { - # Domain will be stripped from the FQDN so the initial '.' is included - 'Domain': '.1201.com', - 'Known Names': { - 'anaconda': 'Anaconda', - 'ash': 'Ash', - 'bender': 'Bender', - 'combine': 'Combine', - 'control': 'Control', - 'cortana': 'Cortana', - 'daftpunk': 'DaftPunk', - 'data': 'Data', - 'deepmind': 'DeepMind', - 'diamondback': 'Diamondback', - 'glados': 'GLaDOS', - 'hal': 'HAL', - 'locutus': 'Locutus', - 'lore': 'Lore', - 'macos-dev': 'macOS-Dev', - 'neuromancer': 'Neuromancer', - 'sex-robot': 'Sex-Robot', - 'shodan': 'Shodan', - 'six': 'Six', - 'skynet': 'Skynet', - 'smith': 'Smith', - 'sovereign': 'Sovereign', - 'supremo': 'Supremo', - 'unicron': 'Unicron', - }, - } if __name__ == '__main__': print("This file is not meant to be called directly.") diff --git a/scripts/wk/osticket.py b/scripts/wk/osticket.py index 684c865f..da542140 100644 --- a/scripts/wk/osticket.py +++ b/scripts/wk/osticket.py @@ -3,13 +3,14 @@ import atexit import logging -import socket +import pathlib import time import mariadb from wk import std -from wk.cfg.osticket import SQL, STAFF, TEST_STATIONS +from wk.cfg.hw import TESTSTATION_FILE +from wk.cfg.osticket import SQL, STAFF # STATIC_VARIABLES @@ -388,23 +389,17 @@ class osTicket(): # pylint: disable=invalid-name # Functions def get_test_station_name(): - """Get test station name from hostname, returns str. + """Get test station name, returns str.""" + hostname_file = pathlib.Path(TESTSTATION_FILE) - NOTES: This is quite broad and may include false-positives. - If not a test station then an empty string is returned. - """ - hostname = socket.getfqdn() - - # Check if this is a test station - if TEST_STATIONS['Domain'] in hostname: - hostname = hostname.replace(TEST_STATIONS['Domain'], '') - if hostname.lower() in TEST_STATIONS['Known Names']: - hostname = TEST_STATIONS['Known Names'][hostname.lower()] - else: - hostname = '' + # Bail early + if not hostname_file.exists(): + return '' + if not hostname_file.read_text(encoding='utf-8'): + return '' # Done - return hostname + return hostname_file.read_text(encoding='utf-8').splitlines()[0] def pad_with_dots(text, pad_right=False):