-
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
Merged
jstraceski
merged 8 commits into
GoogleCloudPlatform:main
from
pweiber:python-callouts-samples-1-4
Mar 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de0686c
Adding callouts use-cases 1-4 in the new structure
victorwoli 806134d
Fixing tests imports
victorwoli 25a252f
Adjusting callouts description
victorwoli a2b2c65
Readjusting imports and some minor fixes
pweiber b32f2f9
Readjusting imports
pweiber bd2c2ca
Deleting inits, adjusting the testing creds paths and adjusting the f…
pweiber b175705
Adjusting the add to include update, removed the update def, refactor…
pweiber 2399071
Adjusting defs args comments
pweiber File filter
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
commit de0686c8473ddc0803e2dc4a4e0103b2dd485150
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. File deleted |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
46 changes: 46 additions & 0 deletions
46
callouts/python/extproc/example/add_body/service_callout_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
51 changes: 51 additions & 0 deletions
51
callouts/python/extproc/example/add_header/service_callout_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
callouts/python/extproc/example/normalize_header/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
46 changes: 46 additions & 0 deletions
46
callouts/python/extproc/example/normalize_header/service_callout_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
53 changes: 53 additions & 0 deletions
53
callouts/python/extproc/example/update_header/service_callout_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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