Skip to content

Commit

Permalink
fix: Improve encryption key change error message (#416)
Browse files Browse the repository at this point in the history
* * Add docker host info to prompt svc
* Run platform svc on all interfaces
* Try docker compose pull again on low speed networks

* Improve enc key change err handling

* Update err msg

* * Allow python version file check in
* Lock python version to 3.9.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Neha <[email protected]>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent 746949d commit 6df8032
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ modules.xml
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.0
1 change: 1 addition & 0 deletions backend/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.0
8 changes: 8 additions & 0 deletions backend/adapter_processor/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class InValidAdapterId(APIException):
default_detail = "Adapter ID is not Valid."


class InvalidEncryptionKey(APIException):
status_code = 403
default_detail = (
"Platform encryption key for storing adapter credentials has changed! "
"Please inform the organization admin to contact support."
)


class InternalServiceError(APIException):
status_code = 500
default_detail = "Internal Service error"
Expand Down
8 changes: 6 additions & 2 deletions backend/adapter_processor/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from account.serializer import UserSerializer
from adapter_processor.adapter_processor import AdapterProcessor
from adapter_processor.constants import AdapterKeys
from cryptography.fernet import Fernet
from adapter_processor.exceptions import InvalidEncryptionKey
from cryptography.fernet import Fernet, InvalidToken
from django.conf import settings
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
Expand Down Expand Up @@ -62,7 +63,10 @@ def to_representation(self, instance: AdapterInstance) -> dict[str, str]:

rep.pop(AdapterKeys.ADAPTER_METADATA_B)

adapter_metadata = instance.get_adapter_meta_data()
try:
adapter_metadata = instance.get_adapter_meta_data()
except InvalidToken:
raise InvalidEncryptionKey
rep[AdapterKeys.ADAPTER_METADATA] = adapter_metadata
# Retrieve context window if adapter is a LLM
# For other adapter types, context_window is not relevant.
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ services:
- ../prompt-service/.env
labels:
- traefik.enable=false
extra_hosts:
# "host-gateway" is a special string that translates to host docker0 i/f IP.
- "host.docker.internal:host-gateway"

x2text-service:
image: unstract/x2text-service:${VERSION}
Expand Down
2 changes: 1 addition & 1 deletion platform-service/src/unstract/platform_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,4 @@ def handle_custom_exception(error: Any) -> tuple[Response, Any]:

if __name__ == "__main__":
# Start the server
app.run()
app.run(host="0.0.0.0", port="3001")
1 change: 1 addition & 0 deletions prompt-service/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.0
2 changes: 2 additions & 0 deletions run-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ build_services() {
}
elif [ "$first_setup" = true ] || [ "$opt_upgrade" = true ]; then
echo -e "$blue_text""Pulling""$default_text"" docker images tag ""$blue_text""$opt_version""$default_text""."
# Try again on a slow network.
VERSION=$opt_version $docker_compose_cmd -f $script_dir/docker/docker-compose.yaml pull ||
VERSION=$opt_version $docker_compose_cmd -f $script_dir/docker/docker-compose.yaml pull || {
echo -e "$red_text""Failed to pull docker images.""$default_text"
echo -e "$red_text""Either version not found or docker is not running.""$default_text"
Expand Down

0 comments on commit 6df8032

Please sign in to comment.