Skip to content

Commit

Permalink
Feature/pla 162 make vespa search adapter code in the sdk not require…
Browse files Browse the repository at this point in the history
… certs (#103)

* Adding a failing test.

* Bumping the cpr_sdk version.

* Adding fix.

* Update src/cpr_sdk/vespa.py

Co-authored-by: Jesse Claven <jesse.claven@me.com>

* 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 <mark@climatepolicyradar.org>
Co-authored-by: Jesse Claven <jesse.claven@me.com>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent 0ec5d0c commit 2d67102
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cpr_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_MAJOR = "1"
_MINOR = "4"
_PATCH = "3"
_PATCH = "4"
_SUFFIX = ""

VERSION_SHORT = "{0}.{1}".format(_MAJOR, _MINOR)
Expand Down
17 changes: 13 additions & 4 deletions src/cpr_sdk/vespa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from pathlib import Path
from typing import Any, List, Optional

Expand All @@ -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]:
Expand Down Expand Up @@ -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"]

Expand Down

0 comments on commit 2d67102

Please sign in to comment.