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

Webertim feature/cbr python pydantic v1 secret str #20119

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import re
import tempfile

from urllib.parse import quote
from pydantic import SecretStr
{{#tornado}}
import tornado.gen
{{/tornado}}
Expand Down Expand Up @@ -285,6 +286,7 @@ class ApiClient:
"""Builds a JSON POST object.

If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -297,6 +299,8 @@ class ApiClient:
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -316,7 +320,10 @@ class ApiClient:
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tempfile

from urllib.parse import quote
from pydantic import SecretStr

from openapi_client.configuration import Configuration
from openapi_client.api_response import ApiResponse
Expand Down Expand Up @@ -261,6 +262,7 @@ def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.

If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -273,6 +275,8 @@ def sanitize_for_serialization(self, obj):
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -292,7 +296,10 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tempfile

from urllib.parse import quote
from pydantic import SecretStr

from petstore_api.configuration import Configuration
from petstore_api.api_response import ApiResponse
Expand Down Expand Up @@ -241,6 +242,7 @@ def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.

If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -253,6 +255,8 @@ def sanitize_for_serialization(self, obj):
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -272,7 +276,10 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tempfile

from urllib.parse import quote
from pydantic import SecretStr

from petstore_api.configuration import Configuration
from petstore_api.api_response import ApiResponse
Expand Down Expand Up @@ -260,6 +261,7 @@ def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.

If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -272,6 +274,8 @@ def sanitize_for_serialization(self, obj):
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -291,7 +295,10 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Loading