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

Cleanup and test of garden connection configs #5

Draft
wants to merge 1 commit into
base: garden_connection_config_feature
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion src/app/beer_garden/db/mongo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def to_brewtils(
model_class = obj.brewtils_model
many = False

if getattr(obj, "pre_serialize", None):
if not many and getattr(obj, "pre_serialize", None):
obj.pre_serialize()
elif many:
for o in obj:
if getattr(o, "pre_serialize", None):
o.pre_serialize()

if model_class == brewtils.models.Garden:
# first step in decoupling from Brewtils
Expand Down
14 changes: 14 additions & 0 deletions src/app/beer_garden/db/mongo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,20 @@ class Garden(MongoModel, Document):
],
}

def save(self, *args, **kwargs):
# Before saving the Garden, remove connection parameters that are entirely empty
if self.connection_params is not None and self.connection_params != {}:
for field in ["http", "stomp"]:
value = self.connection_params.get(field, None)
if value is not None and value == {}:
_ = self.connection_params.pop(field)
return super().save(*args, **kwargs)

def pre_serialize(self):
from beer_garden.garden import clean_garden_connection_params

self.connection_params = clean_garden_connection_params(self).connection_params

def deep_save(self):
if self.connection_type != "LOCAL":
self._update_associated_systems()
Expand Down
18 changes: 14 additions & 4 deletions src/app/beer_garden/db/schemas/garden_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from brewtils.models import Garden as BrewtilsGarden
from brewtils.schema_parser import SchemaParser as BrewtilsSchemaParser
from brewtils.schemas import StatusInfoSchema # noqa # until we can fully decouple
from brewtils.schemas import SystemSchema # noqa # until we can fully decouple
from marshmallow import Schema, ValidationError, fields
Expand All @@ -19,7 +20,7 @@ class GardenBaseSchema(Schema):
def validate_all_keys(self, post_load_data, original_data, **kwargs):
# do not allow extraneous keys when operating on a dictionary
if isinstance(original_data, dict):
extra_args = original_data.keys() - post_load_data.keys()
extra_args = set(original_data.keys()) - set(post_load_data.keys())

if len(extra_args) > 0:
formatted_good_keys = ", ".join(
Expand Down Expand Up @@ -50,10 +51,10 @@ class HttpConnectionParamsSchema(GardenBaseSchema):
)
url_prefix = fields.String(required=True, dump_default="/", load_default="/")
ca_cert = fields.String(required=False, allow_none=True)
ca_verify = fields.Boolean(required=True)
ca_verify = fields.Boolean(required=True, default=False, missing=False)
client_cert = fields.String(required=False, allow_none=True)
client_key = fields.String(required=False, allow_none=True)
ssl = fields.Boolean(required=True)
ssl = fields.Boolean(required=True, default=False, missing=False)


class StompSSLParamsSchema(GardenBaseSchema):
Expand Down Expand Up @@ -106,4 +107,13 @@ class GardenSchema(GardenBaseSchema):

@post_load
def make_object(self, data):
return BrewtilsGarden(**data)
SYSTEMS = "systems"

systems_brewtils_list = list(
map(BrewtilsSchemaParser.parse_system, data.pop(SYSTEMS, None) or [])
)

garden = BrewtilsGarden(**data)
setattr(garden, SYSTEMS, systems_brewtils_list)

return garden
Loading