Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def websocket_publish(item):
"""Will serialize an event and publish it to all event websocket endpoints"""
try:
beer_garden.api.http.io_loop.add_callback(
EventSocket.publish, SchemaParser.serialize(item, to_string=True)
)
except Exception as ex:
logger.exception(f"Error publishing event to websocket: {ex}")
def from_brewtils(obj: ModelItem) -> MongoModel:
"""Convert an item from its Brewtils model to its one
Args:
obj: The Brewtils model item
Returns:
The Mongo model item
"""
model_dict = SchemaParser.serialize(obj, to_string=False)
mongo_obj = MongoParser.parse(model_dict, type(obj), from_string=False)
return mongo_obj
def from_brewtils(obj: ModelItem) -> SqlModel:
"""Convert an item from its Brewtils model to its one
Args:
obj: The Brewtils model item
Returns:
The Mongo model item
"""
model_dict = SchemaParser.serialize(obj, to_string=False)
sql_obj = SqlParser.parse(model_dict, type(obj), from_string=False)
return sql_obj
def _register_with_parent(self):
try:
if not self.registered:
response = requests.post(
self.endpoint + "namespaces/" + self.namespace,
json=SchemaParser.serialize(
Namespace(
namespace=self.namespace,
status="INITIALIZING",
connection_type="https"
if self.callback.ssl_enabled
else "http",
connection_params=self.callback,
),
to_string=False,
),
)
if response.status_code in [200, 201]:
self.registered = True
self.connected = True
else:
response = self._patch(
def _post(self, endpoint, payload):
return requests.post(
self.endpoint + endpoint, json=SchemaParser.serialize(payload)
)
self.pool, partial(beer_garden.router.route, *args, **kwargs)
)
# Handlers overwhelmingly just write the response so default to serializing
serialize_kwargs = serialize_kwargs or {}
if "to_string" not in serialize_kwargs:
serialize_kwargs["to_string"] = True
# We're not going to ever double-serialize a string
if isinstance(result, six.string_types):
return result
if self.json_dump(result):
return json.dumps(result) if serialize_kwargs["to_string"] else result
return SchemaParser.serialize(result, **(serialize_kwargs or {}))