-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: Adding use-cases 1 to 4 in the new callout scructure #48
feat: Adding use-cases 1 to 4 in the new callout scructure #48
Conversation
@@ -1,19 +0,0 @@ | |||
-----BEGIN CERTIFICATE----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these files being deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new structure is using the creds from python/extproc/ssl_creds, that's why we removed the external one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That additional ssl_creds was to be used in other callout examples, but I can add them later, I am working on a proto generation script currently.
callouts/__init__.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These init.py files are outside the scope of the python project.
I believe that it will give a false impression of what constitutes the ext_proc project files.
I was intending the python execution from within the callouts/python/extproc
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File deleted
callouts/python/__init__.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly just formatting concerns, I can read through the changes but changing the format to the original 2 spaces would help with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that the formatting for this project was changed from 2 spaces to 4 spaces?
It's making it a bit difficult to see the changes, I am wondering if you could modify your formatting script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted the formatting, let me know if it's fine now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused, this path should be from the root directory callouts/python/extproc
and not a relative path. Does this work when you run the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had an issue with the path and it was throwing a not found error, that's the reason we changed it but I found out what was the problem, should be good now for the tests.
But for the service/callout_server.py I had to do a os.path.abspath workaround, I tried with the './extproc/ssl_creds/localhost.crt' but was not working when executing the examples, let me know if we can keep like that or use another strategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you demonstrate how you were running the samples? Ideally you would run from the callouts/python
directory and running with python -m extproc.example.grpc.service_callout_example
. For me this allowed the old pathing. It would be ideal if we could use a direct path in the callout server settings as it would allow a user to provide a local link to a cert rather than relying on the project structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running like you mentioned worked, I found what was the problem, for some reason when I was running the example it was changing the path during execution, I was able to run with the old path and reverted the changes, should be good now.
…ormat back to 2 spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few suggestions, the rest of the pr looks good though.
@@ -61,23 +63,104 @@ def add_header_mutation( | |||
return header_mutation | |||
|
|||
|
|||
def update_header_mutation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no real conception of updating the headers from the callout in terms of what is represented in the proto.
would it be better to consolidate this update method into the add method, adding the ability to set the append action?
Something like this:
def add_header_mutation(
add: list[tuple[str, str]] | None = None,
remove: list[str] | None = None,
clear_route_cache: bool = False,
append_action: service_pb2.HeaderValueOption.HeaderAppendAction = None,
) -> service_pb2.HeadersResponse:
"""Generate a header response for incoming requests.
Args:
add: A list of tuples representing headers to add.
remove: List of header strings to remove from the request.
clear_route_cache: If true, will enable clear_route_cache on the response.
Returns:
The constructed header response object.
"""
header_mutation = service_pb2.HeadersResponse()
if add:
for k, v in add:
header_value_option = service_pb2.HeaderValueOption(
header=service_pb2.HeaderValue(key=k, raw_value=bytes(v, 'utf-8'))
)
if append_action:
header_value_option.append_action = append_action
header_mutation.response.header_mutation.set_headers.append(header_value_option)
if remove is not None:
header_mutation.response.header_mutation.remove_headers.extend(remove)
if clear_route_cache:
header_mutation.response.clear_route_cache = True
return header_mutation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally we could also add in a parameter for the HeadersResponse
i.e.
(snippet #1
)
def add_header_mutation(
...
header_mutation:bool = None,
...)
...
header_mutation = header_mutation or service_pb2.HeadersResponse()
...
)
so that the (snippet #2
)
if update is None:
update = []
host_value = next((header.raw_value.decode('utf-8') for header in headers.headers.headers if header.key == 'host'),
None)
if host_value:
device_type = get_device_type(host_value)
update.append(('client-device-type', device_type))
could live here as well.
possibly behind an additional flag, I.e. normalize_host
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think that the normalize_header_mutation
function is a good separation then we could leave snippet #2
in the normalize_header_mutation
function and just call the modified snippet #1
+ add_header_mutation
function from the normalize_header_mutation
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#48 (comment) would allow chaining of the add function as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the suggested changes and apparently it worked fine, I decided to keep the normalize_header_mutation function and call the add_header_mutation inside so we can keep a good separation, let me know if the changes are following what you expected.
…ing the normalize to call add | Reverted the old path for creds | Fixed tests based on the changes | Adjusted formatting for the remaining files
Fixes #40
Considering closed PR #41 comments
Use-cases