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

use requests with attested connection pooling #22

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

HernanGatta
Copy link
Contributor

@HernanGatta HernanGatta commented Aug 27, 2023

Overview

This PR updates the PromptGuard client to use the changes proposed to the underlying aTLS package. Namely, this PR modifies the PromptGuard client to use the requests library and to utilize the aTLS adapter in the aforementioned PR to in turn gain support for connection pooling, thereby greatly reducing the per-request latency.

@HernanGatta HernanGatta added the feat New Feature label Aug 27, 2023
@HernanGatta HernanGatta self-assigned this Aug 27, 2023
@HernanGatta HernanGatta marked this pull request as draft August 27, 2023 17:52
@github-actions
Copy link

github-actions bot commented Aug 27, 2023

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ ACTION actionlint 2 0 0.01s
✅ PYTHON black 5 0 0.69s
✅ PYTHON flake8 5 0 0.35s
✅ PYTHON isort 5 0 0.23s
✅ YAML yamllint 9 0 0.26s

See detailed report in MegaLinter reports

You could have the same capabilities but better runtime performances if you use a MegaLinter flavor:

MegaLinter is graciously provided by OX Security

@HernanGatta HernanGatta marked this pull request as ready for review August 28, 2023 00:07
from promptguard.authentication import get_api_key
from promptguard.configuration import get_server_config

_session: Optional[requests.Session] = None
_sessionLock: threading.Lock = threading.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: _session_lock to match Python naming convention

Some comments about what these variables are used for would also help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

api_key = get_api_key()
hostname, port = get_server_config()

ctx = AttestedTLSContext(_get_default_validators())
conn = AttestedHTTPSConnection(hostname, ctx, port)
response = _session.request(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't handle the case where connection was closed (maybe by remote). Possibly need something like https://github.com/singer-io/tap-skubana/pull/6/files or better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Contributor

@zizhong zizhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@HernanGatta HernanGatta merged commit b825036 into dev Aug 29, 2023
1 check passed
@HernanGatta HernanGatta deleted the hegatta/connection-pooling branch August 29, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants