[go: nahoru, domu]

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

feat: Adding use-cases 1 to 4 in the new callout scructure #48

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding callouts use-cases 1-4 in the new structure
  • Loading branch information
victorwoli committed Mar 4, 2024
commit de0686c8473ddc0803e2dc4a4e0103b2dd485150
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
/callouts/python/.pytest_cache/**
/callouts/python/.pytest_cache
/.vscode/**
/.idea/**
plugins/bazel-*
**/__pycache__
Empty file added callouts/__init__.py
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

File deleted

Empty file.
Empty file added callouts/python/__init__.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

File deleted

Empty file.
21 changes: 21 additions & 0 deletions callouts/python/extproc/example/add_body/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM marketplace.gcr.io/google/debian12
RUN apt-get update && apt-get install -y python3-pip python3-grpc-tools
WORKDIR /home/callouts/python
COPY ./extproc/service ./extproc/service
COPY ./extproc/proto ./extproc/proto
COPY ./extproc/ssl_creds ./extproc/ssl_creds
COPY ./extproc/example/add_body ./extproc/example/add_body
EXPOSE 443
EXPOSE 8080
EXPOSE 80
CMD [ "/usr/bin/python3", "-um", "extproc.example.add_body.service_callout_example" ]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2023 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from callouts.python.extproc.proto import service_pb2
from callouts.python.extproc.service import callout_server

from grpc import ServicerContext


class CalloutServerExample(callout_server.CalloutServer):
"""Example callout server.

Provides a non-comprehensive set of responses for each of the possible
callout interactions.

On a request body callout we provide a mutation to append '-added-body' to the body. On response body
callouts we send a mutation to replace the body with 'new-body'.
"""

def on_request_body(
self, body: service_pb2.HttpBody, context: ServicerContext
) -> service_pb2.BodyResponse:
"""Custom processor on the request body."""
return callout_server.add_body_mutation(body='-added-body')

def on_response_body(
self, body: service_pb2.HttpBody, context: ServicerContext
) -> service_pb2.BodyResponse:
"""Custom processor on the response body."""
return callout_server.add_body_mutation(body='new-body', clear_body=True)


if __name__ == '__main__':
# Run the gRPC service
CalloutServerExample(port=443, insecure_port=8080, health_check_port=80).run()
21 changes: 21 additions & 0 deletions callouts/python/extproc/example/add_header/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM marketplace.gcr.io/google/debian12
RUN apt-get update && apt-get install -y python3-pip python3-grpc-tools
WORKDIR /home/callouts/python
COPY ./extproc/service ./extproc/service
COPY ./extproc/proto ./extproc/proto
COPY ./extproc/ssl_creds ./extproc/ssl_creds
COPY ./extproc/example/add_header ./extproc/example/add_header
EXPOSE 443
EXPOSE 8080
EXPOSE 80
CMD [ "/usr/bin/python3", "-um", "extproc.example.add_header.service_callout_example" ]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

# Copyright 2023 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from grpc import ServicerContext
from callouts.python.extproc.proto import service_pb2
from callouts.python.extproc.service import callout_server


class CalloutServerExample(callout_server.CalloutServer):
"""Example callout server.

Provides a non-comprehensive set of responses for each of the possible
callout interactions.

For request header callouts we provide a mutation to add a header
'{header-request: request}', remove a header 'foo', and to clear the
route cache. On response header callouts, we respond with a mutation to add
the header '{header-response: response}'.
"""
def on_request_add_headers(
self, headers: service_pb2.HttpHeaders, context: ServicerContext
) -> service_pb2.HeadersResponse:
"""Custom processor on request headers."""
return callout_server.add_header_mutation(
add=[('header-request', 'request')], remove=['foo'],
clear_route_cache=True
)

def on_response_add_headers(
self, headers: service_pb2.HttpHeaders, context: ServicerContext
) -> service_pb2.HeadersResponse:
"""Custom processor on response headers."""
return callout_server.add_header_mutation(
add=[('header-response', 'response')]
)

if __name__ == '__main__':
# Run the gRPC service
CalloutServerExample().run()
21 changes: 21 additions & 0 deletions callouts/python/extproc/example/normalize_header/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM marketplace.gcr.io/google/debian12
RUN apt-get update && apt-get install -y python3-pip python3-grpc-tools
WORKDIR /home/callouts/python
COPY ./extproc/service ./extproc/service
COPY ./extproc/proto ./extproc/proto
COPY ./extproc/ssl_creds ./extproc/ssl_creds
COPY ./extproc/example/normalize_header ./extproc/example/normalize_header
EXPOSE 443
EXPOSE 8080
EXPOSE 80
CMD [ "/usr/bin/python3", "-um", "extproc.example.normalize_header.service_callout_example" ]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2023 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from callouts.python.extproc.proto import service_pb2
from callouts.python.extproc.service import callout_server

from grpc import ServicerContext


class CalloutServerExample(callout_server.CalloutServer):
"""Example callout server.

Provides a non-comprehensive set of responses for each of the possible
callout interactions.

For request header callouts we provide a mutation to update a header
'{header-request: request}', and to clear the route cache.

On response header callouts, we respond with a mutation to update
the header '{header-response: response}'.
"""

def on_request_headers(
self, headers: service_pb2.HttpHeaders, context: ServicerContext
) -> service_pb2.HeadersResponse:
"""Custom processor on request headers."""
return callout_server.normalize_header_mutation(
headers=headers,
clear_route_cache=True
)


if __name__ == '__main__':
# Run the gRPC service
CalloutServerExample(port=443, insecure_port=8080, health_check_port=80).run()
21 changes: 21 additions & 0 deletions callouts/python/extproc/example/update_header/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM marketplace.gcr.io/google/debian12
RUN apt-get update && apt-get install -y python3-pip python3-grpc-tools
WORKDIR /home/callouts/python
COPY ./extproc/service ./extproc/service
COPY ./extproc/proto ./extproc/proto
COPY ./extproc/ssl_creds ./extproc/ssl_creds
COPY ./extproc/example/update_header ./extproc/example/update_header
EXPOSE 443
EXPOSE 8080
EXPOSE 80
CMD [ "/usr/bin/python3", "-um", "extproc.example.update_header.service_callout_example" ]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2023 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from grpc import ServicerContext
from callouts.python.extproc.proto import service_pb2
from callouts.python.extproc.service import callout_server


class CalloutServerExample(callout_server.CalloutServer):
"""Example callout server.

Provides a non-comprehensive set of responses for each of the possible
callout interactions.

For request header callouts we provide a mutation to update a header
'{header-request: request}', and to clear the route cache.

On response header callouts, we respond with a mutation to update
the header '{header-response: response}'.
"""
def on_request_headers(
self, headers: service_pb2.HttpHeaders, context: ServicerContext
) -> service_pb2.HeadersResponse:
"""Custom processor on request headers."""
return callout_server.update_header_mutation(
headers=headers,
update=[('header-request', 'request')],
clear_route_cache=True
)

def on_response_headers(
self, headers: service_pb2.HttpHeaders, context: ServicerContext
) -> service_pb2.HeadersResponse:
"""Custom processor on response headers."""
return callout_server.update_header_mutation(
headers=headers,
update=[('header-response', 'response')]
)

if __name__ == '__main__':
# Run the gRPC service
CalloutServerExample(port=443, insecure_port=8080, health_check_port=80).run()
Loading