Skip to content

Commit

Permalink
changing to upstream and alias
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog committed Jun 12, 2024
1 parent 3949c61 commit 64f81e3
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 125 deletions.
23 changes: 13 additions & 10 deletions brewtils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,13 +1617,13 @@ class User(BaseModel):

def __init__(
self,
username = None,
id = None,
username=None,
id=None,
password=None,
roles=None,
local_roles=None,
remote_roles=None,
remote_user_mapping=None,
upstream_roles=None,
alias_user_mapping=None,
metadata=None,
is_remote=False,
protected=False,
Expand All @@ -1634,9 +1634,9 @@ def __init__(
self.password = password
self.roles = roles or []
self.local_roles = local_roles or []
self.remote_roles = remote_roles or []
self.upstream_roles = upstream_roles or []
self.is_remote = is_remote
self.remote_user_mapping = remote_user_mapping or []
self.alias_user_mapping = alias_user_mapping or []
self.metadata = metadata or {}
self.protected = protected
self.file_generated = file_generated
Expand Down Expand Up @@ -1710,16 +1710,19 @@ def __repr__(self):
self.scope_commands,
)

class RemoteRole(Role):
schema = "RemoteRoleSchema"

class RemoteUserMap(BaseModel):
schema = "RemoteUserMapSchema"
class UpstreamRole(Role):
schema = "UpstreamRoleSchema"


class AliasUserMap(BaseModel):
schema = "AliasUserMapSchema"

def __init__(self, target_garden, username):
self.target_garden = target_garden
self.username = username


class Subscriber(BaseModel):
schema = "SubscriberSchema"

Expand Down
46 changes: 24 additions & 22 deletions brewtils/schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class SchemaParser(object):
"RunnerSchema": brewtils.models.Runner,
"ResolvableSchema": brewtils.models.Resolvable,
"RoleSchema": brewtils.models.Role,
"RemoteRoleSchema": brewtils.models.RemoteRole,
"UpstreamRoleSchema": brewtils.models.UpstreamRole,
"UserSchema": brewtils.models.User,
"RemoteUserMapSchema": brewtils.models.RemoteUserMap,
"AliasUserMapSchema": brewtils.models.AliasUserMap,
"SubscriberSchema": brewtils.models.Subscriber,
"TopicSchema": brewtils.models.Topic,
}
Expand Down Expand Up @@ -283,9 +283,9 @@ def parse_role(cls, role, from_string=False, **kwargs):
A Role object
"""
return cls.parse(role, brewtils.models.Role, from_string=from_string, **kwargs)

@classmethod
def parse_remote_role(cls, role, from_string=False, **kwargs):
def parse_upstream_role(cls, role, from_string=False, **kwargs):
"""Convert raw JSON string or dictionary to a role model object
Args:
Expand All @@ -296,23 +296,25 @@ def parse_remote_role(cls, role, from_string=False, **kwargs):
Returns:
A Role object
"""
return cls.parse(role, brewtils.models.RemoteRole, from_string=from_string, **kwargs)
return cls.parse(
role, brewtils.models.UpstreamRole, from_string=from_string, **kwargs
)

@classmethod
def parse_remote_user_map(cls, remote_user_map, from_string=False, **kwargs):
"""Convert raw JSON string or dictionary to a RemoteUserMap model object
def parse_alias_user_map(cls, alias_user_map, from_string=False, **kwargs):
"""Convert raw JSON string or dictionary to a AliasUserMap model object
Args:
role: The raw input
from_string: True if input is a JSON string, False if a dictionary
**kwargs: Additional parameters to be passed to the Schema (e.g. many=True)
Returns:
A RemoteUserMap object
A AliasUserMap object
"""
return cls.parse(
remote_user_map,
brewtils.models.RemoteUserMap,
alias_user_map,
brewtils.models.AliasUserMap,
from_string=from_string,
**kwargs
)
Expand All @@ -330,10 +332,7 @@ def parse_user_token(cls, user_token, from_string=False, **kwargs):
A UserToken object
"""
return cls.parse(
user_token,
brewtils.models.UserToken,
from_string=from_string,
**kwargs
user_token, brewtils.models.UserToken, from_string=from_string, **kwargs
)

@classmethod
Expand Down Expand Up @@ -771,9 +770,9 @@ def serialize_role(cls, role, to_string=True, **kwargs):
return cls.serialize(
role, to_string=to_string, schema_name=brewtils.models.Role.schema, **kwargs
)

@classmethod
def serialize_remote_role(cls, role, to_string=True, **kwargs):
def serialize_upstream_role(cls, role, to_string=True, **kwargs):
"""Convert a role model into serialized form
Args:
Expand All @@ -786,15 +785,18 @@ def serialize_remote_role(cls, role, to_string=True, **kwargs):
Serialized representation
"""
return cls.serialize(
role, to_string=to_string, schema_name=brewtils.models.RemoteRole.schema, **kwargs
role,
to_string=to_string,
schema_name=brewtils.models.UpstreamRole.schema,
**kwargs
)

@classmethod
def serialize_remote_user_map(cls, remote_user_map, to_string=True, **kwargs):
"""Convert a RemoteUserMap model into serialized form
def serialize_alias_user_map(cls, alias_user_map, to_string=True, **kwargs):
"""Convert a AliasUserMap model into serialized form
Args:
RemoteUserMap: The RemoteUserMap object(s) to be serialized
AliasUserMap: The AliasUserMap object(s) to be serialized
to_string: True to generate a JSON-formatted string, False to generate a
dictionary
**kwargs: Additional parameters to be passed to the Schema (e.g. many=True)
Expand All @@ -803,9 +805,9 @@ def serialize_remote_user_map(cls, remote_user_map, to_string=True, **kwargs):
Serialized representation
"""
return cls.serialize(
remote_user_map,
alias_user_map,
to_string=to_string,
schema_name=brewtils.models.RemoteUserMap.schema,
schema_name=brewtils.models.AliasUserMap.schema,
**kwargs
)

Expand Down
16 changes: 8 additions & 8 deletions brewtils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,16 @@ class RoleSchema(BaseSchema):
protected = fields.Boolean(allow_none=True)
file_generated = fields.Boolean(allow_none=True)

class RemoteRoleSchema(RoleSchema):

class UpstreamRoleSchema(RoleSchema):
pass


class RemoteUserMapSchema(BaseSchema):
class AliasUserMapSchema(BaseSchema):
target_garden = fields.Str()
username = fields.Str()


class SubscriberSchema(BaseSchema):
garden = fields.Str(allow_none=True)
namespace = fields.Str(allow_none=True)
Expand All @@ -603,16 +605,14 @@ class UserSchema(BaseSchema):
password = fields.Str(allow_none=True)
roles = fields.List(fields.Str(), allow_none=True)
local_roles = fields.List(fields.Nested(RoleSchema()), allow_none=True)
remote_roles = fields.List(fields.Nested(RemoteRoleSchema()), allow_none=True)
remote_user_mapping = fields.List(fields.Nested(RemoteUserMapSchema()))
upstream_roles = fields.List(fields.Nested(UpstreamRoleSchema()), allow_none=True)
alias_user_mapping = fields.List(fields.Nested(AliasUserMapSchema()))
is_remote = fields.Boolean(allow_none=True)
metadata = fields.Dict(allow_none=True)
protected = fields.Boolean(allow_none=True)
file_generated = fields.Boolean(allow_none=True)




model_schema_map.update(
{
"Choices": ChoicesSchema,
Expand Down Expand Up @@ -643,9 +643,9 @@ class UserSchema(BaseSchema):
"Runner": RunnerSchema,
"Resolvable": ResolvableSchema,
"Role": RoleSchema,
"RemoteRole": RemoteRoleSchema,
"UpstreamRole": UpstreamRoleSchema,
"User": UserSchema,
"RemoteUserMap": RemoteUserMapSchema,
"AliasUserMap": AliasUserMapSchema,
"Subscriber": SubscriberSchema,
"Topic": TopicSchema,
# Compatibility for the Job trigger types
Expand Down
27 changes: 15 additions & 12 deletions brewtils/test/comparable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import brewtils.test
from brewtils.models import (
AliasUserMap,
Choices,
Command,
Connection,
Expand All @@ -24,24 +25,23 @@
Instance,
IntervalTrigger,
Job,
Role,
LoggingConfig,
Operation,
Parameter,
PatchOperation,
User,
UserToken,
Queue,
RemoteUserMap,
RemoteRole,
Request,
RequestFile,
RequestTemplate,
Resolvable,
Role,
Runner,
System,
Subscriber,
System,
Topic,
UpstreamRole,
User,
UserToken,
)

__all__ = [
Expand All @@ -57,7 +57,7 @@
"assert_parameter_equal",
"assert_user_token_equal",
"assert_user_equal",
"assert_remote_user_map_equal",
"assert_alias_user_map_equal",
"assert_request_equal",
"assert_role_equal",
"assert_system_equal",
Expand Down Expand Up @@ -202,7 +202,7 @@ def _assert_wrapper(obj1, obj2, expected_type=None, do_raise=False, **kwargs):
assert_runner_equal = partial(_assert_wrapper, expected_type=Runner)
assert_resolvable_equal = partial(_assert_wrapper, expected_type=Resolvable)
assert_connection_equal = partial(_assert_wrapper, expected_type=Connection)
assert_remote_user_map_equal = partial(_assert_wrapper, expected_type=RemoteUserMap)
assert_alias_user_map_equal = partial(_assert_wrapper, expected_type=AliasUserMap)
assert_subscriber_equal = partial(_assert_wrapper, expected_type=Subscriber)


Expand Down Expand Up @@ -246,19 +246,21 @@ def assert_event_equal(obj1, obj2, do_raise=False):
do_raise=do_raise,
)


def assert_user_equal(obj1, obj2, do_raise=False):
return _assert_wrapper(
obj1,
obj2,
expected_type=User,
deep_fields={
"local_roles": partial(assert_role_equal, do_raise=True),
"remote_roles": partial(assert_remote_role_equal, do_raise=True),
"remote_user_mapping": partial(assert_remote_user_map_equal, do_raise=True),
"upstream_roles": partial(assert_upstream_role_equal, do_raise=True),
"alias_user_mapping": partial(assert_alias_user_map_equal, do_raise=True),
},
do_raise=do_raise,
)


def assert_user_token_equal(obj1, obj2, do_raise=False):
return _assert_wrapper(
obj1,
Expand Down Expand Up @@ -327,11 +329,12 @@ def assert_role_equal(obj1, obj2, do_raise=False):
do_raise=do_raise,
)

def assert_remote_role_equal(obj1, obj2, do_raise=False):

def assert_upstream_role_equal(obj1, obj2, do_raise=False):
return _assert_wrapper(
obj1,
obj2,
expected_type=RemoteRole,
expected_type=UpstreamRole,
do_raise=do_raise,
)

Expand Down
Loading

0 comments on commit 64f81e3

Please sign in to comment.