Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
faf40a42
Unverified
Commit
faf40a42
authored
Jan 04, 2024
by
takatost
Committed by
GitHub
Jan 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: optimize memory & invoke error output (#1931)
parent
97c972f1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
11 deletions
+3
-11
invoke.py
api/core/model_runtime/errors/invoke.py
+3
-0
rsa.py
api/libs/rsa.py
+0
-11
No files found.
api/core/model_runtime/errors/invoke.py
View file @
faf40a42
...
@@ -8,6 +8,9 @@ class InvokeError(Exception):
...
@@ -8,6 +8,9 @@ class InvokeError(Exception):
def
__init__
(
self
,
description
:
Optional
[
str
]
=
None
)
->
None
:
def
__init__
(
self
,
description
:
Optional
[
str
]
=
None
)
->
None
:
self
.
description
=
description
self
.
description
=
description
def
__str__
(
self
):
return
self
.
description
or
self
.
__class__
.
__name__
class
InvokeConnectionError
(
InvokeError
):
class
InvokeConnectionError
(
InvokeError
):
"""Raised when the Invoke returns connection error."""
"""Raised when the Invoke returns connection error."""
...
...
api/libs/rsa.py
View file @
faf40a42
...
@@ -5,7 +5,6 @@ from Crypto.Cipher import PKCS1_OAEP, AES
...
@@ -5,7 +5,6 @@ from Crypto.Cipher import PKCS1_OAEP, AES
from
Crypto.PublicKey
import
RSA
from
Crypto.PublicKey
import
RSA
from
Crypto.Random
import
get_random_bytes
from
Crypto.Random
import
get_random_bytes
from
core.helper.lru_cache
import
LRUCache
from
extensions.ext_redis
import
redis_client
from
extensions.ext_redis
import
redis_client
from
extensions.ext_storage
import
storage
from
extensions.ext_storage
import
storage
...
@@ -46,15 +45,7 @@ def encrypt(text, public_key):
...
@@ -46,15 +45,7 @@ def encrypt(text, public_key):
return
prefix_hybrid
+
encrypted_data
return
prefix_hybrid
+
encrypted_data
tenant_rsa_keys
=
LRUCache
(
capacity
=
1000
)
def
get_decrypt_decoding
(
tenant_id
):
def
get_decrypt_decoding
(
tenant_id
):
rsa_key
=
tenant_rsa_keys
.
get
(
tenant_id
)
if
rsa_key
:
cipher_rsa
=
PKCS1_OAEP
.
new
(
rsa_key
)
return
rsa_key
,
cipher_rsa
filepath
=
"privkeys/{tenant_id}"
.
format
(
tenant_id
=
tenant_id
)
+
"/private.pem"
filepath
=
"privkeys/{tenant_id}"
.
format
(
tenant_id
=
tenant_id
)
+
"/private.pem"
cache_key
=
'tenant_privkey:{hash}'
.
format
(
hash
=
hashlib
.
sha3_256
(
filepath
.
encode
())
.
hexdigest
())
cache_key
=
'tenant_privkey:{hash}'
.
format
(
hash
=
hashlib
.
sha3_256
(
filepath
.
encode
())
.
hexdigest
())
...
@@ -70,8 +61,6 @@ def get_decrypt_decoding(tenant_id):
...
@@ -70,8 +61,6 @@ def get_decrypt_decoding(tenant_id):
rsa_key
=
RSA
.
import_key
(
private_key
)
rsa_key
=
RSA
.
import_key
(
private_key
)
cipher_rsa
=
PKCS1_OAEP
.
new
(
rsa_key
)
cipher_rsa
=
PKCS1_OAEP
.
new
(
rsa_key
)
tenant_rsa_keys
.
put
(
tenant_id
,
rsa_key
)
return
rsa_key
,
cipher_rsa
return
rsa_key
,
cipher_rsa
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment