mirror of
https://github.com/craigerl/aprsd.git
synced 2025-08-06 07:12:32 -04:00
Removed requirement for aprs.fi key
This removed the requirement of running APRSD for specifying the aprs.fi key in the config file. The plugins that need the key have been updated to set enabled = False when the key is missing.
This commit is contained in:
parent
10e34d8634
commit
7787dc1be4
@ -327,12 +327,6 @@ def parse_config(config_file):
|
|||||||
"ham.callsign",
|
"ham.callsign",
|
||||||
default_fail=DEFAULT_CONFIG_DICT["ham"]["callsign"],
|
default_fail=DEFAULT_CONFIG_DICT["ham"]["callsign"],
|
||||||
)
|
)
|
||||||
|
|
||||||
check_option(
|
|
||||||
config,
|
|
||||||
["services", "aprs.fi", "apiKey"],
|
|
||||||
default_fail=DEFAULT_CONFIG_DICT["services"]["aprs.fi"]["apiKey"],
|
|
||||||
)
|
|
||||||
check_option(
|
check_option(
|
||||||
config,
|
config,
|
||||||
"aprs.login",
|
"aprs.login",
|
||||||
|
@ -241,11 +241,24 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
|||||||
if result:
|
if result:
|
||||||
self.tx_inc()
|
self.tx_inc()
|
||||||
else:
|
else:
|
||||||
LOG.warning(f"{self.__class__} isn't enabled.")
|
result = f"{self.__class__.__name__} isn't enabled"
|
||||||
|
LOG.warning(result)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class APRSFIKEYMixin:
|
||||||
|
"""Mixin class to enable checking the existence of the aprs.fi apiKey."""
|
||||||
|
|
||||||
|
def ensure_aprs_fi_key(self):
|
||||||
|
try:
|
||||||
|
self.config.check_option(["services", "aprs.fi", "apiKey"])
|
||||||
|
self.enabled = True
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.error(f"Failed to find config aprs.fi:apikey {ex}")
|
||||||
|
self.enabled = False
|
||||||
|
|
||||||
|
|
||||||
class HelpPlugin(APRSDRegexCommandPluginBase):
|
class HelpPlugin(APRSDRegexCommandPluginBase):
|
||||||
"""Help Plugin that is always enabled.
|
"""Help Plugin that is always enabled.
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@ class FortunePlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
command_regex = "^[fF]"
|
command_regex = "^[fF]"
|
||||||
command_name = "fortune"
|
command_name = "fortune"
|
||||||
|
|
||||||
|
fortune_path = None
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.fortune_path = shutil.which("fortune")
|
||||||
|
if not self.fortune_path:
|
||||||
|
self.enabled = False
|
||||||
|
|
||||||
@trace.trace
|
@trace.trace
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
LOG.info("FortunePlugin")
|
LOG.info("FortunePlugin")
|
||||||
@ -25,13 +32,8 @@ class FortunePlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
|
|
||||||
reply = None
|
reply = None
|
||||||
|
|
||||||
fortune_path = shutil.which("fortune")
|
|
||||||
if not fortune_path:
|
|
||||||
reply = "Fortune command not installed"
|
|
||||||
return reply
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmnd = [fortune_path, "-s", "-n 60"]
|
cmnd = [self.fortune_path, "-s", "-n 60"]
|
||||||
command = " ".join(cmnd)
|
command = " ".join(cmnd)
|
||||||
output = subprocess.check_output(
|
output = subprocess.check_output(
|
||||||
command,
|
command,
|
||||||
|
@ -8,13 +8,16 @@ from aprsd import plugin, plugin_utils, trace
|
|||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
|
||||||
|
|
||||||
class LocationPlugin(plugin.APRSDRegexCommandPluginBase):
|
class LocationPlugin(plugin.APRSDRegexCommandPluginBase, plugin.APRSFIKEYMixin):
|
||||||
"""Location!"""
|
"""Location!"""
|
||||||
|
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
command_regex = "^[lL]"
|
command_regex = "^[lL]"
|
||||||
command_name = "location"
|
command_name = "location"
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.ensure_aprs_fi_key()
|
||||||
|
|
||||||
@trace.trace
|
@trace.trace
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
LOG.info("Location Plugin")
|
LOG.info("Location Plugin")
|
||||||
@ -22,13 +25,6 @@ class LocationPlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
message = packet.get("message_text", None)
|
message = packet.get("message_text", None)
|
||||||
# ack = packet.get("msgNo", "0")
|
# ack = packet.get("msgNo", "0")
|
||||||
|
|
||||||
# get last location of a callsign, get descriptive name from weather service
|
|
||||||
try:
|
|
||||||
self.config.check_option(["services", "aprs.fi", "apiKey"])
|
|
||||||
except Exception as ex:
|
|
||||||
LOG.error(f"Failed to find config aprs.fi:apikey {ex}")
|
|
||||||
return "No aprs.fi apikey found"
|
|
||||||
|
|
||||||
api_key = self.config["services"]["aprs.fi"]["apiKey"]
|
api_key = self.config["services"]["aprs.fi"]["apiKey"]
|
||||||
|
|
||||||
# optional second argument is a callsign to search
|
# optional second argument is a callsign to search
|
||||||
|
@ -49,26 +49,22 @@ class TimePlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
return self.build_date_str(localzone)
|
return self.build_date_str(localzone)
|
||||||
|
|
||||||
|
|
||||||
class TimeOpenCageDataPlugin(TimePlugin):
|
class TimeOpenCageDataPlugin(TimePlugin, plugin.APRSFIKEYMixin):
|
||||||
"""geocage based timezone fetching."""
|
"""geocage based timezone fetching."""
|
||||||
|
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
command_regex = "^[tT]"
|
command_regex = "^[tT]"
|
||||||
command_name = "time"
|
command_name = "time"
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.ensure_aprs_fi_key()
|
||||||
|
|
||||||
@trace.trace
|
@trace.trace
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
fromcall = packet.get("from")
|
fromcall = packet.get("from")
|
||||||
message = packet.get("message_text", None)
|
message = packet.get("message_text", None)
|
||||||
# ack = packet.get("msgNo", "0")
|
# ack = packet.get("msgNo", "0")
|
||||||
|
|
||||||
# get last location of a callsign, get descriptive name from weather service
|
|
||||||
try:
|
|
||||||
self.config.exists(["services", "aprs.fi", "apiKey"])
|
|
||||||
except Exception as ex:
|
|
||||||
LOG.error(f"Failed to find config aprs.fi:apikey {ex}")
|
|
||||||
return "No aprs.fi apikey found"
|
|
||||||
|
|
||||||
api_key = self.config["services"]["aprs.fi"]["apiKey"]
|
api_key = self.config["services"]["aprs.fi"]["apiKey"]
|
||||||
|
|
||||||
# optional second argument is a callsign to search
|
# optional second argument is a callsign to search
|
||||||
@ -115,26 +111,22 @@ class TimeOpenCageDataPlugin(TimePlugin):
|
|||||||
return self.build_date_str(localzone)
|
return self.build_date_str(localzone)
|
||||||
|
|
||||||
|
|
||||||
class TimeOWMPlugin(TimePlugin):
|
class TimeOWMPlugin(TimePlugin, plugin.APRSFIKEYMixin):
|
||||||
"""OpenWeatherMap based timezone fetching."""
|
"""OpenWeatherMap based timezone fetching."""
|
||||||
|
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
command_regex = "^[tT]"
|
command_regex = "^[tT]"
|
||||||
command_name = "time"
|
command_name = "time"
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.ensure_aprs_fi_key()
|
||||||
|
|
||||||
@trace.trace
|
@trace.trace
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
fromcall = packet.get("from")
|
fromcall = packet.get("from")
|
||||||
message = packet.get("message_text", None)
|
message = packet.get("message_text", None)
|
||||||
# ack = packet.get("msgNo", "0")
|
# ack = packet.get("msgNo", "0")
|
||||||
|
|
||||||
# get last location of a callsign, get descriptive name from weather service
|
|
||||||
try:
|
|
||||||
self.config.exists(["services", "aprs.fi", "apiKey"])
|
|
||||||
except Exception as ex:
|
|
||||||
LOG.error(f"Failed to find config aprs.fi:apikey {ex}")
|
|
||||||
return "No aprs.fi apikey found"
|
|
||||||
|
|
||||||
# optional second argument is a callsign to search
|
# optional second argument is a callsign to search
|
||||||
a = re.search(r"^.*\s+(.*)", message)
|
a = re.search(r"^.*\s+(.*)", message)
|
||||||
if a is not None:
|
if a is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user