diff --git a/rattail_corepos/corepos/office/commands.py b/rattail_corepos/corepos/office/commands.py index 11c5d11..2f023c6 100644 --- a/rattail_corepos/corepos/office/commands.py +++ b/rattail_corepos/corepos/office/commands.py @@ -26,10 +26,14 @@ CORE Office commands import sys +import requests +from requests.auth import HTTPDigestAuth + from rattail import commands from rattail_corepos import __version__ from rattail.util import load_object from rattail_corepos.corepos.office.util import get_fannie_config_value +from rattail_corepos.config import core_office_url def main(*args): @@ -129,3 +133,26 @@ class ImportSelf(commands.ImportSubcommand): name = 'import-self' description = __doc__.strip() handler_key = 'to_self.from_corepos_db_office_op.import' + + +class PingInstall(commands.Subcommand): + """ + Ping the /install URL in CORE Office (for DB setup) + """ + name = 'ping-install' + description = __doc__.strip() + + def run(self, args): + url = core_office_url(self.config, require=True) + url = f'{url}/install/' + + # TODO: hacky re-using credentials from API config.. + username = self.config.get('corepos.api', 'htdigest.username') + password = self.config.get('corepos.api', 'htdigest.password') + + session = requests.Session() + if username and password: + session.auth = HTTPDigestAuth(username, password) + + response = session.get(url) + response.raise_for_status() diff --git a/setup.cfg b/setup.cfg index 0ca4969..2b7d01f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,6 +45,7 @@ core_office.commands = import-csv = rattail_corepos.corepos.office.commands:ImportCSV import-self = rattail_corepos.corepos.office.commands:ImportSelf get-config-value = rattail_corepos.corepos.office.commands:GetConfigValue + ping-install = rattail_corepos.corepos.office.commands:PingInstall crepes.commands = export-core = rattail_corepos.corepos.commands:ExportCore