diff --git a/brewtils/models.py b/brewtils/models.py index d22bf768..ad42ccc7 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -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, @@ -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 @@ -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" diff --git a/brewtils/schema_parser.py b/brewtils/schema_parser.py index 4f302e2d..abe523aa 100644 --- a/brewtils/schema_parser.py +++ b/brewtils/schema_parser.py @@ -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, } @@ -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: @@ -296,11 +296,13 @@ 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 @@ -308,11 +310,11 @@ def parse_remote_user_map(cls, remote_user_map, from_string=False, **kwargs): **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 ) @@ -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 @@ -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: @@ -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) @@ -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 ) diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 470f07b3..885a290f 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -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) @@ -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, @@ -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 diff --git a/brewtils/test/comparable.py b/brewtils/test/comparable.py index 43a4add7..1874906b 100644 --- a/brewtils/test/comparable.py +++ b/brewtils/test/comparable.py @@ -14,6 +14,7 @@ import brewtils.test from brewtils.models import ( + AliasUserMap, Choices, Command, Connection, @@ -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__ = [ @@ -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", @@ -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) @@ -246,6 +246,7 @@ 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, @@ -253,12 +254,13 @@ def assert_user_equal(obj1, obj2, do_raise=False): 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, @@ -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, ) diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 85b89937..11cfdf0f 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -7,6 +7,7 @@ import pytz from brewtils.models import ( + AliasUserMap, Choices, Command, Connection, @@ -22,19 +23,18 @@ Parameter, PatchOperation, Queue, - RemoteUserMap, - RemoteRole, Request, RequestFile, RequestTemplate, Resolvable, + Role, Runner, + Subscriber, System, + Topic, + UpstreamRole, User, UserToken, - Role, - Subscriber, - Topic, ) @@ -533,7 +533,7 @@ def bg_queue(queue_dict): @pytest.fixture -def remote_user_map_dict(): +def alias_user_map_dict(): return { "target_garden": "test", "username": "user", @@ -541,8 +541,9 @@ def remote_user_map_dict(): @pytest.fixture -def bg_remote_user_map(remote_user_map_dict): - return RemoteUserMap(**remote_user_map_dict) +def bg_alias_user_map(alias_user_map_dict): + return AliasUserMap(**alias_user_map_dict) + @pytest.fixture def user_token_dict(user_dict, ts_epoch): @@ -582,11 +583,12 @@ def role_dict(): @pytest.fixture -def bg_remote_role(role_dict): - return RemoteRole(**role_dict) +def bg_role(role_dict): + return Role(**role_dict) + @pytest.fixture -def remote_role_dict(): +def upstream_role_dict(): return { "permission": "PLUGIN_ADMIN", "description": "PLUGIN ADMIN ROLE", @@ -604,20 +606,20 @@ def remote_role_dict(): @pytest.fixture -def bg_role(role_dict): - return Role(**role_dict) +def bg_upstream_role(upstream_role_dict): + return UpstreamRole(**upstream_role_dict) @pytest.fixture -def user_dict(role_dict, remote_role_dict, remote_user_map_dict): +def user_dict(role_dict, upstream_role_dict, alias_user_map_dict): return { "id": "1", "username": "USERNAME", "password": "HASH", "roles": ["PLUGIN_ADMIN_ROLE"], "local_roles": [role_dict], - "remote_roles": [remote_role_dict], - "remote_user_mapping": [remote_user_map_dict], + "upstream_roles": [upstream_role_dict], + "alias_user_mapping": [alias_user_map_dict], "is_remote": False, "metadata": {}, "protected": False, @@ -626,11 +628,11 @@ def user_dict(role_dict, remote_role_dict, remote_user_map_dict): @pytest.fixture -def bg_user(user_dict, bg_role, bg_remote_role, bg_remote_user_map): +def bg_user(user_dict, bg_role, bg_upstream_role, bg_alias_user_map): dict_copy = copy.deepcopy(user_dict) - dict_copy["remote_roles"] = [bg_remote_role] + dict_copy["upstream_roles"] = [bg_upstream_role] dict_copy["local_roles"] = [bg_role] - dict_copy["remote_user_mapping"] = [bg_remote_user_map] + dict_copy["alias_user_mapping"] = [bg_alias_user_map] return User(**dict_copy) diff --git a/test/schema_parser_test.py b/test/schema_parser_test.py index d575980b..94fa1cc2 100644 --- a/test/schema_parser_test.py +++ b/test/schema_parser_test.py @@ -5,11 +5,15 @@ import copy -import brewtils.models import pytest +from marshmallow.exceptions import MarshmallowError +from pytest_lazyfixture import lazy_fixture + +import brewtils.models from brewtils.models import System from brewtils.schema_parser import SchemaParser from brewtils.test.comparable import ( + assert_alias_user_map_equal, assert_command_equal, assert_connection_equal, assert_event_equal, @@ -21,11 +25,7 @@ assert_operation_equal, assert_parameter_equal, assert_patch_equal, - assert_user_equal, - assert_user_token_equal, assert_queue_equal, - assert_remote_user_map_equal, - assert_remote_role_equal, assert_request_equal, assert_request_file_equal, assert_resolvable_equal, @@ -34,9 +34,10 @@ assert_subscriber_equal, assert_system_equal, assert_topic_equal, + assert_upstream_role_equal, + assert_user_equal, + assert_user_token_equal, ) -from marshmallow.exceptions import MarshmallowError -from pytest_lazyfixture import lazy_fixture class TestParse(object): @@ -138,10 +139,10 @@ def test_no_modify(self, system_dict): lazy_fixture("bg_user_token"), ), ( - brewtils.models.RemoteUserMap, - lazy_fixture("remote_user_map_dict"), - assert_remote_user_map_equal, - lazy_fixture("bg_remote_user_map"), + brewtils.models.AliasUserMap, + lazy_fixture("alias_user_map_dict"), + assert_alias_user_map_equal, + lazy_fixture("bg_alias_user_map"), ), ( brewtils.models.Role, @@ -150,10 +151,10 @@ def test_no_modify(self, system_dict): lazy_fixture("bg_role"), ), ( - brewtils.models.RemoteRole, - lazy_fixture("remote_role_dict"), - assert_remote_role_equal, - lazy_fixture("bg_remote_role"), + brewtils.models.UpstreamRole, + lazy_fixture("upstream_role_dict"), + assert_upstream_role_equal, + lazy_fixture("bg_upstream_role"), ), ( brewtils.models.Job, @@ -296,10 +297,10 @@ def test_single_from_string(self): lazy_fixture("bg_user_token"), ), ( - "parse_remote_user_map", - lazy_fixture("remote_user_map_dict"), - assert_remote_user_map_equal, - lazy_fixture("bg_remote_user_map"), + "parse_alias_user_map", + lazy_fixture("alias_user_map_dict"), + assert_alias_user_map_equal, + lazy_fixture("bg_alias_user_map"), ), ( "parse_role", @@ -308,10 +309,10 @@ def test_single_from_string(self): lazy_fixture("bg_role"), ), ( - "parse_remote_role", - lazy_fixture("remote_role_dict"), - assert_remote_role_equal, - lazy_fixture("bg_remote_role"), + "parse_upstream_role", + lazy_fixture("upstream_role_dict"), + assert_upstream_role_equal, + lazy_fixture("bg_upstream_role"), ), ( "parse_job", @@ -459,10 +460,10 @@ def test_single_specific_from_string(self): lazy_fixture("bg_user_token"), ), ( - brewtils.models.RemoteUserMap, - lazy_fixture("remote_user_map_dict"), - assert_remote_user_map_equal, - lazy_fixture("bg_remote_user_map"), + brewtils.models.AliasUserMap, + lazy_fixture("alias_user_map_dict"), + assert_alias_user_map_equal, + lazy_fixture("bg_alias_user_map"), ), ( brewtils.models.Role, @@ -471,10 +472,10 @@ def test_single_specific_from_string(self): lazy_fixture("bg_role"), ), ( - brewtils.models.RemoteRole, - lazy_fixture("remote_role_dict"), - assert_remote_role_equal, - lazy_fixture("bg_remote_role"), + brewtils.models.UpstreamRole, + lazy_fixture("upstream_role_dict"), + assert_upstream_role_equal, + lazy_fixture("bg_upstream_role"), ), ( brewtils.models.Job, @@ -615,10 +616,10 @@ def test_many(self, model, data, assertion, expected): lazy_fixture("bg_user_token"), ), ( - "parse_remote_user_map", - lazy_fixture("remote_user_map_dict"), - assert_remote_user_map_equal, - lazy_fixture("bg_remote_user_map"), + "parse_alias_user_map", + lazy_fixture("alias_user_map_dict"), + assert_alias_user_map_equal, + lazy_fixture("bg_alias_user_map"), ), ( "parse_role", @@ -627,10 +628,10 @@ def test_many(self, model, data, assertion, expected): lazy_fixture("bg_role"), ), ( - "parse_remote_role", - lazy_fixture("remote_role_dict"), - assert_remote_role_equal, - lazy_fixture("bg_remote_role"), + "parse_upstream_role", + lazy_fixture("upstream_role_dict"), + assert_upstream_role_equal, + lazy_fixture("bg_upstream_role"), ), ( "parse_job", @@ -732,9 +733,9 @@ class TestSerialize(object): (lazy_fixture("bg_queue"), lazy_fixture("queue_dict")), (lazy_fixture("bg_user"), lazy_fixture("user_dict")), (lazy_fixture("bg_user_token"), lazy_fixture("user_token_dict")), - (lazy_fixture("bg_remote_user_map"), lazy_fixture("remote_user_map_dict")), + (lazy_fixture("bg_alias_user_map"), lazy_fixture("alias_user_map_dict")), (lazy_fixture("bg_role"), lazy_fixture("role_dict")), - (lazy_fixture("bg_remote_role"), lazy_fixture("remote_role_dict")), + (lazy_fixture("bg_upstream_role"), lazy_fixture("upstream_role_dict")), (lazy_fixture("bg_job"), lazy_fixture("job_dict")), (lazy_fixture("bg_cron_job"), lazy_fixture("cron_job_dict")), (lazy_fixture("bg_interval_job"), lazy_fixture("interval_job_dict")), @@ -805,9 +806,9 @@ def test_single(self, model, expected): lazy_fixture("user_token_dict"), ), ( - "serialize_remote_user_map", - lazy_fixture("bg_remote_user_map"), - lazy_fixture("remote_user_map_dict"), + "serialize_alias_user_map", + lazy_fixture("bg_alias_user_map"), + lazy_fixture("alias_user_map_dict"), ), ( "serialize_role", @@ -815,9 +816,9 @@ def test_single(self, model, expected): lazy_fixture("role_dict"), ), ( - "serialize_remote_role", - lazy_fixture("bg_remote_role"), - lazy_fixture("remote_role_dict"), + "serialize_upstream_role", + lazy_fixture("bg_upstream_role"), + lazy_fixture("upstream_role_dict"), ), ("serialize_job", lazy_fixture("bg_job"), lazy_fixture("job_dict")), ( @@ -891,9 +892,9 @@ def test_single_specific(self, method, data, expected): (lazy_fixture("bg_queue"), lazy_fixture("queue_dict")), (lazy_fixture("bg_user"), lazy_fixture("user_dict")), (lazy_fixture("bg_user_token"), lazy_fixture("user_token_dict")), - (lazy_fixture("bg_remote_user_map"), lazy_fixture("remote_user_map_dict")), + (lazy_fixture("bg_alias_user_map"), lazy_fixture("alias_user_map_dict")), (lazy_fixture("bg_role"), lazy_fixture("role_dict")), - (lazy_fixture("bg_remote_role"), lazy_fixture("remote_role_dict")), + (lazy_fixture("bg_upstream_role"), lazy_fixture("upstream_role_dict")), (lazy_fixture("bg_job"), lazy_fixture("job_dict")), (lazy_fixture("bg_cron_job"), lazy_fixture("cron_job_dict")), (lazy_fixture("bg_interval_job"), lazy_fixture("interval_job_dict")), @@ -981,12 +982,16 @@ class TestRoundTrip(object): lazy_fixture("bg_user_token"), ), ( - brewtils.models.RemoteUserMap, - assert_remote_user_map_equal, - lazy_fixture("bg_remote_user_map"), + brewtils.models.AliasUserMap, + assert_alias_user_map_equal, + lazy_fixture("bg_alias_user_map"), ), (brewtils.models.Role, assert_role_equal, lazy_fixture("bg_role")), - (brewtils.models.RemoteRole, assert_remote_role_equal, lazy_fixture("bg_remote_role")), + ( + brewtils.models.UpstreamRole, + assert_upstream_role_equal, + lazy_fixture("bg_upstream_role"), + ), (brewtils.models.Job, assert_job_equal, lazy_fixture("bg_job")), (brewtils.models.Job, assert_job_equal, lazy_fixture("bg_cron_job")), (brewtils.models.Job, assert_job_equal, lazy_fixture("bg_interval_job")), @@ -1033,7 +1038,7 @@ def test_parsed_start(self, model, assertion, data): (brewtils.models.User, lazy_fixture("user_dict")), (brewtils.models.UserToken, lazy_fixture("user_token_dict")), (brewtils.models.Role, lazy_fixture("role_dict")), - (brewtils.models.RemoteRole, lazy_fixture("remote_role_dict")), + (brewtils.models.UpstreamRole, lazy_fixture("upstream_role_dict")), (brewtils.models.Job, lazy_fixture("job_dict")), (brewtils.models.Job, lazy_fixture("cron_job_dict")), (brewtils.models.Job, lazy_fixture("interval_job_dict")),