Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/fts context #10245

Merged
merged 8 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions openlibrary/core/fulltext.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import web

from infogami import config
from openlibrary.core.lending import get_availability_of_ocaids
from openlibrary.core.lending import (
config_fts_context,
config_ia_ol_metadata_write_s3,
get_availability_of_ocaids,
)
from openlibrary.plugins.openlibrary.home import format_book_data

logger = logging.getLogger("openlibrary.inside")
Expand All @@ -17,10 +21,20 @@ def fulltext_search_api(params):
return {'error': 'Unable to prepare search engine'}
search_endpoint = config.plugin_inside['search_endpoint']
search_select = search_endpoint + '?' + urlencode(params, 'utf-8')
headers = {
"x-preferred-client-id": web.ctx.env.get('HTTP_X_FORWARDED_FOR', 'ol-internal'),
"x-application-id": "openlibrary",
"x-search-request-context": config_fts_context,
}
# Try adding s3 keys?
mekarpeles marked this conversation as resolved.
Show resolved Hide resolved
if config_ia_ol_metadata_write_s3:
headers["authorization"] = "LOW {s3_key}:{s3_secret}".format(
**config_ia_ol_metadata_write_s3
)

logger.debug('URL: ' + search_select)
try:
response = requests.get(search_select, timeout=30)
response = requests.get(search_select, headers=headers, timeout=30)
response.raise_for_status()
return response.json()
except requests.HTTPError:
Expand Down
4 changes: 3 additions & 1 deletion openlibrary/core/lending.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, message="Access to this item is temporarily locked."):
config_loanstatus_url = None
config_bookreader_host = None
config_internal_tests_api_key = None
config_fts_context = None


def setup(config):
Expand All @@ -78,7 +79,7 @@ def setup(config):
global config_ia_availability_api_v2_url, config_ia_ol_metadata_write_s3
global config_ia_xauth_api_url, config_http_request_timeout, config_ia_s3_auth_url
global config_ia_users_loan_history, config_ia_loan_api_developer_key
global config_ia_domain
global config_ia_domain, config_fts_context

config_loanstatus_url = config.get('loanstatus_url')
config_bookreader_host = config.get('bookreader_host', 'archive.org')
Expand All @@ -98,6 +99,7 @@ def setup(config):
config_ia_loan_api_developer_key = config.get('ia_loan_api_developer_key')
config_internal_tests_api_key = config.get('internal_tests_api_key')
config_http_request_timeout = config.get('http_request_timeout')
config_fts_context = config.get('fts_context')


@public
Expand Down
Loading