Skip to content

Commit

Permalink
Add debug messages to meshdb client
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Dickinson committed Nov 22, 2024
1 parent eccea83 commit 2d83f79
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mesh-database-client/mesh_database_client/meshdb_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import print_function

import logging
import os
from venv import logger

from dotenv import load_dotenv

Expand All @@ -15,48 +17,69 @@ class MeshDBDatabaseClient(DatabaseClient):
def __init__(self, mesh_db_auth_token):
self.requests_sesssion = requests.Session()
self.requests_sesssion.headers['Authorization'] = f"Token {mesh_db_auth_token}"
self.logger = logging.Logger("MeshDBClient")

def _member_id_to_nn(self, member_id):
self.logger.info(f"Converting member ID: {member_id} to NN")
install_query_response = self.requests_sesssion.get(
endpoints.INSTALL_LOOKUP_ENDPOINT,
params={"member": member_id, "status": "Active"},
)
self.logger.debug(
f"Got response for member ID {member_id}: "
f"HTTP {install_query_response.status_code}: {install_query_response.text}"
)
install_query_response.raise_for_status()
install_query_json = install_query_response.json()

if not install_query_json["results"]:
self.logger.debug(
f"Found no active installs for member ID {member_id}"
)
return None

# If there are multiple active installs for this member, arbitrary select the first one
install = install_query_json["results"][0]

if not install["node"]["network_number"]:
self.logger.debug(
f"Install #{install['install_number']} does not have a network number for member ID {member_id}"
)
return None

self.logger.debug(
f"Found network number: {install['node']['network_number']} for member ID {member_id}"
)
return install["node"]["network_number"]

def name_to_nn(self, name):
self.logger.info(f"Querying for name {name}")
member_query_response = self.requests_sesssion.get(
endpoints.MEMBER_LOOKUP_ENDPOINT, params={"name": name}
)
self.logger.debug(f"Got response for name {name}: HTTP {member_query_response.status_code}: {member_query_response.text}")
member_query_response.raise_for_status()
member_query_json = member_query_response.json()

if not member_query_json["results"]:
self.logger.debug("No results found when searching by name")
return None

# If there are multiple members with this name, arbitrary select the first member
member_id = member_query_json["results"][0]["id"]
return self._member_id_to_nn(member_id)

def email_to_nn(self, email):
self.logger.info(f"Querying for email address {email}")
member_query_response = self.requests_sesssion.get(
endpoints.MEMBER_LOOKUP_ENDPOINT, params={"email_address": email}
)
self.logger.debug(f"Got response for email {email}: HTTP {member_query_response.status_code}: {member_query_response.text}")
member_query_response.raise_for_status()
member_query_json = member_query_response.json()

if not member_query_json["results"]:
self.logger.debug("No results found when searching by email")
return None

# If there are multiple members with this email, arbitrary select the first member. This
Expand Down

0 comments on commit 2d83f79

Please sign in to comment.