How to use the brewtils.schema_parser.SchemaParser.serialize function in brewtils

To help you get started, we’ve selected a few brewtils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beer-garden / beer-garden / src / app / beer_garden / api / http / processors.py View on Github external
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}")
github beer-garden / beer-garden / src / app / beer_garden / db / mongo / api.py View on Github external
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
github beer-garden / beer-garden / src / app / beer_garden / db / sql / api.py View on Github external
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
github beer-garden / beer-garden / src / app / beer_garden / events / parent_http_processor.py View on Github external
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(
github beer-garden / beer-garden / src / app / beer_garden / events / parent_http_processor.py View on Github external
def _post(self, endpoint, payload):
        return requests.post(
            self.endpoint + endpoint, json=SchemaParser.serialize(payload)
        )
github beer-garden / beer-garden / src / app / beer_garden / api / http / client.py View on Github external
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 {}))