From 2d671025fe6576ac5973ee14dbaf432d4bcc7e57 Mon Sep 17 00:00:00 2001 From: NextGenEng <58440325+THOR300@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:39:33 +0100 Subject: [PATCH] Feature/pla 162 make vespa search adapter code in the sdk not require certs (#103) * Adding a failing test. * Bumping the cpr_sdk version. * Adding fix. * Update src/cpr_sdk/vespa.py Co-authored-by: Jesse Claven * Adding import for Optional. * Return no cert path if we can't find application name. * Minor bug fix to find certs function. * Adding the conditional for finding vespa certs. * Bumping the cpr_sdk version. * Precommit fix. * Updating to continue if we can't find config file. * Refactoring to continue on not finding certs. --------- Co-authored-by: Mark Co-authored-by: Jesse Claven --- src/cpr_sdk/version.py | 2 +- src/cpr_sdk/vespa.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cpr_sdk/version.py b/src/cpr_sdk/version.py index e5f46df..9393761 100644 --- a/src/cpr_sdk/version.py +++ b/src/cpr_sdk/version.py @@ -1,6 +1,6 @@ _MAJOR = "1" _MINOR = "4" -_PATCH = "3" +_PATCH = "4" _SUFFIX = "" VERSION_SHORT = "{0}.{1}".format(_MAJOR, _MINOR) diff --git a/src/cpr_sdk/vespa.py b/src/cpr_sdk/vespa.py index 7534df9..7e3ba9e 100644 --- a/src/cpr_sdk/vespa.py +++ b/src/cpr_sdk/vespa.py @@ -1,3 +1,4 @@ +import logging from pathlib import Path from typing import Any, List, Optional @@ -12,6 +13,7 @@ from cpr_sdk.yql_builder import YQLBuilder SENSITIVE_QUERY_TERMS = load_sensitive_query_terms() +_LOGGER = logging.getLogger(__name__) def split_document_id(document_id: str) -> tuple[str, str, str]: @@ -46,15 +48,22 @@ def find_vespa_cert_paths() -> tuple[Optional[str], Optional[str]]: """ vespa_directory = Path.home() / ".vespa/" if not vespa_directory.exists(): - raise FileNotFoundError( - "Could not find .vespa directory in home directory. " - "Please specify a cert_directory." + _LOGGER.warning( + "Could not find .vespa directory in home directory when looking for certs." ) + return None, None + + vespa_config = vespa_directory / "config.yaml" + if not vespa_config.exists(): + _LOGGER.warning( + "Could not find config.yaml file in .vespa directory when looking for certs." + ) + return None, None # read the config.yaml file to find the application name with open(vespa_directory / "config.yaml", "r", encoding="utf-8") as yaml_file: data = yaml.safe_load(yaml_file) - if "application" not in data: + if not data or "application" not in data: return None, None application_name = data["application"]