Skip to content

Commit

Permalink
allow unknown cfs in queries (#62)
Browse files Browse the repository at this point in the history
* allow unknown cfs in queries

* fix

* .

* .
  • Loading branch information
bentheiii authored Aug 28, 2022
1 parent 9d14e40 commit e507eb0
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 460 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install dependencies
run: poetry install
- name: setup-docker
uses: docker-practice/actions-setup-docker@0.0.1
uses: docker-practice/actions-setup-docker@1.0.11
- name: Linting
run: poetry run sh scripts/lint.sh
- name: Run unittests + app tests
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Heksher Changelog
## 0.5.2
### Changed
* sending unknown context features in a query is no longer an error
* httpx is now a dev-dependency
* Docker container now runs with a limited user
## 0.5.1
### Added
* Added a generic handler for unhandled errors
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ RUN export APP_VERSION=$(poetry version | cut -d' ' -f2) && echo "__version__ =
ENV PYTHONPATH=${PYTHONPATH}:/usr/src/app/heksher
ENV PYTHONOPTIMIZE=1

RUN useradd --uid 10000 runner
USER 10000

CMD ["uvicorn", "heksher.main:app", "--host", "0.0.0.0", "--port", "80"]
9 changes: 7 additions & 2 deletions heksher/api/v1/query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from logging import getLogger
from typing import Any, Dict, List, Optional, Tuple, Union

from fastapi import Query
Expand All @@ -14,6 +15,8 @@
from heksher.db_logic.rule import db_query_rules
from heksher.db_logic.setting import db_get_canonical_names, db_get_settings

logger = getLogger(__name__)


# https://github.com/tiangolo/fastapi/issues/2724
class QueryRulesOutput_Rule(ORJSONModel):
Expand Down Expand Up @@ -117,8 +120,10 @@ async def query_rules(request: Request, app: HeksherApp = application,

not_context_features = await db_get_not_found_context_features(conn, context_features_options)
if not_context_features:
return PlainTextResponse(f'the following are not valid context features: {not_context_features}',
status_code=status.HTTP_404_NOT_FOUND)
logger.info("unknown context features included in query",
extra={'unknown_context_features': list(not_context_features)})
for cf in not_context_features:
del context_features_options[cf]
results = await db_query_rules(conn, settings, context_features_options, include_metadata)
if include_metadata:
ret: Union[QueryRulesOutputWithMetadata, QueryRulesOutput] = QueryRulesOutputWithMetadata(
Expand Down
Loading

0 comments on commit e507eb0

Please sign in to comment.