From e0ea731d9de65800aebdcb1488d8faa70084be2b Mon Sep 17 00:00:00 2001 From: Pascal Cadotte Michaud Date: Mon, 30 Dec 2024 14:04:06 -0500 Subject: [PATCH 1/2] Use marshmallow version 3.18.0 from Bookworm This change uses the Bookworm version of marshmallow to reduce the scope of changes that are going to happen when doing the upgrade --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 584f6207..28159eb0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ jinja2==3.0.3 jsonpatch==1.25 kombu==5.0.2 markupsafe==2.0.1 # from jinja -marshmallow==3.10.0 +marshmallow==3.18.0 netifaces==0.10.9 psycopg2-binary==2.8.6 python-consul==1.1.0 From 99c5af73ed241ba370e66affe3fec4f4acfa361e Mon Sep 17 00:00:00 2001 From: Pascal Cadotte Michaud Date: Tue, 31 Dec 2024 14:14:13 -0500 Subject: [PATCH 2/2] schemas: replace missing and default missing and default are deprecated and have been replaced by load_default and dump_default respectively --- .../plugins/external_auth/mobile/http.py | 10 +++--- wazo_auth/plugins/http/ldap_config/schemas.py | 24 ++++++++------ .../plugins/http/password_reset/schemas.py | 8 +++-- wazo_auth/plugins/http/policies/schemas.py | 8 ++--- wazo_auth/plugins/http/tenants/schemas.py | 32 +++++++++---------- wazo_auth/plugins/http/tokens/schemas.py | 4 +-- wazo_auth/plugins/http/user_email/schemas.py | 6 ++-- .../plugins/http/user_registration/schemas.py | 4 +-- wazo_auth/plugins/http/users/schemas.py | 11 ++++--- wazo_auth/schemas.py | 6 ++-- 10 files changed, 61 insertions(+), 52 deletions(-) diff --git a/wazo_auth/plugins/external_auth/mobile/http.py b/wazo_auth/plugins/external_auth/mobile/http.py index b0fdf5b0..258304e4 100644 --- a/wazo_auth/plugins/external_auth/mobile/http.py +++ b/wazo_auth/plugins/external_auth/mobile/http.py @@ -14,10 +14,12 @@ class MobileSchema(schemas.BaseSchema): - token = fields.String(min=1, max=512, missing=None) - apns_token = fields.String(allow_none=True, max=512, missing=None) # deprecated - apns_voip_token = fields.String(allow_none=True, max=512, missing=None) - apns_notification_token = fields.String(allow_none=True, max=512, missing=None) + token = fields.String(min=1, max=512, load_default=None) + apns_token = fields.String( + allow_none=True, max=512, load_default=None + ) # deprecated + apns_voip_token = fields.String(allow_none=True, max=512, load_default=None) + apns_notification_token = fields.String(allow_none=True, max=512, load_default=None) class MobileAuthSenderID(http.AuthResource): diff --git a/wazo_auth/plugins/http/ldap_config/schemas.py b/wazo_auth/plugins/http/ldap_config/schemas.py index 468cd29d..ad76be0b 100644 --- a/wazo_auth/plugins/http/ldap_config/schemas.py +++ b/wazo_auth/plugins/http/ldap_config/schemas.py @@ -8,26 +8,30 @@ class LDAPConfig(BaseSchema): - tenant_uuid = fields.String(dump_only=True, default=None) - host = fields.String(validate=Length(max=512), required=True, default=None) - port = fields.Integer(required=True, default=None) + tenant_uuid = fields.String(dump_only=True, dump_default=None) + host = fields.String(validate=Length(max=512), required=True, dump_default=None) + port = fields.Integer(required=True, dump_default=None) protocol_version = fields.Integer( - validate=Range(min=2, max=3), missing=3, default=None + validate=Range(min=2, max=3), load_default=3, dump_default=None ) protocol_security = fields.String( validate=OneOf(['ldaps', 'tls']), allow_none=True, - default=None, + dump_default=None, + ) + bind_dn = fields.String( + validate=Length(max=256), allow_none=True, dump_default=None + ) + user_base_dn = fields.String( + validate=Length(max=256), required=True, dump_default=None ) - bind_dn = fields.String(validate=Length(max=256), allow_none=True, default=None) - user_base_dn = fields.String(validate=Length(max=256), required=True, default=None) user_login_attribute = fields.String( - validate=Length(max=64), required=True, default=None + validate=Length(max=64), required=True, dump_default=None ) user_email_attribute = fields.String( - validate=Length(max=64), required=True, default=None + validate=Length(max=64), required=True, dump_default=None ) - search_filters = fields.String(allow_none=True, default=None) + search_filters = fields.String(allow_none=True, dump_default=None) class LDAPConfigEdit(LDAPConfig): diff --git a/wazo_auth/plugins/http/password_reset/schemas.py b/wazo_auth/plugins/http/password_reset/schemas.py index 4ffef23c..1961d848 100644 --- a/wazo_auth/plugins/http/password_reset/schemas.py +++ b/wazo_auth/plugins/http/password_reset/schemas.py @@ -14,9 +14,11 @@ class PasswordResetPostParameters(BaseSchema): class PasswordResetQueryParameters(BaseSchema): - username = fields.String(validate=validate.Length(min=1, max=256), missing=None) - email_address = fields.Email(data_key='email', missing=None) - login = fields.String(validate=validate.Length(min=1, max=256), missing=None) + username = fields.String( + validate=validate.Length(min=1, max=256), load_default=None + ) + email_address = fields.Email(data_key='email', load_default=None) + login = fields.String(validate=validate.Length(min=1, max=256), load_default=None) @validates_schema def validate_mutually_exclusive_fields(self, data, **kwargs): diff --git a/wazo_auth/plugins/http/policies/schemas.py b/wazo_auth/plugins/http/policies/schemas.py index 9cefbc52..a1bb414f 100644 --- a/wazo_auth/plugins/http/policies/schemas.py +++ b/wazo_auth/plugins/http/policies/schemas.py @@ -14,12 +14,12 @@ class PolicyFullSchema(BaseSchema): name = fields.String(validate=validate.Length(min=1, max=80), required=True) slug = fields.String( validate=[validate.Length(min=1, max=80), validate.Regexp(Slug.valid_re())], - missing=None, + load_default=None, ) - description = fields.String(allow_none=True, missing=None) - acl = fields.List(fields.String(), missing=[], attribute='acl') + description = fields.String(allow_none=True, load_default=None) + acl = fields.List(fields.String(), load_default=[], attribute='acl') read_only = fields.Boolean(dump_only=True) - shared = fields.Boolean(missing=False) + shared = fields.Boolean(load_default=False) @post_dump(pass_original=True) def set_shared_exposed_only_for_dump(self, data, original, **kwargs): diff --git a/wazo_auth/plugins/http/tenants/schemas.py b/wazo_auth/plugins/http/tenants/schemas.py index 35b57807..0384dc67 100644 --- a/wazo_auth/plugins/http/tenants/schemas.py +++ b/wazo_auth/plugins/http/tenants/schemas.py @@ -23,22 +23,22 @@ class TenantListSchema(BaseListSchema): class TenantAddress(BaseSchema): line_1 = fields.String( - validate=validate.Length(min=1, max=256), missing=None, default=None + validate=validate.Length(min=1, max=256), load_default=None, dump_default=None ) line_2 = fields.String( - validate=validate.Length(min=1, max=256), missing=None, default=None + validate=validate.Length(min=1, max=256), load_default=None, dump_default=None ) city = fields.String( - validate=validate.Length(min=1, max=128), missing=None, default=None + validate=validate.Length(min=1, max=128), load_default=None, dump_default=None ) state = fields.String( - validate=validate.Length(min=1, max=128), missing=None, default=None + validate=validate.Length(min=1, max=128), load_default=None, dump_default=None ) country = fields.String( - validate=validate.Length(min=1, max=128), missing=None, default=None + validate=validate.Length(min=1, max=128), load_default=None, dump_default=None ) zip_code = fields.String( - validate=validate.Length(min=1, max=16), missing=None, default=None + validate=validate.Length(min=1, max=16), load_default=None, dump_default=None ) @@ -46,37 +46,37 @@ class TenantAddress(BaseSchema): class TenantFullSchema(BaseSchema): - uuid = fields.UUID(missing=None) + uuid = fields.UUID(load_default=None) parent_uuid = fields.UUID(dump_only=True) name = fields.String( - validate=validate.Length(min=1, max=128), default=None, missing=None + validate=validate.Length(min=1, max=128), dump_default=None, load_default=None ) slug = fields.String( validate=[ validate.Length(min=1, max=10), validate.Regexp(TenantSlug.valid_re()), ], - missing=None, + load_default=None, ) - contact_uuid = fields.UUID(data_key='contact', missing=None, default=None) + contact_uuid = fields.UUID(data_key='contact', load_default=None, dump_default=None) phone = fields.String( - validate=validate.Length(min=1, max=32), default=None, missing=None + validate=validate.Length(min=1, max=32), dump_default=None, load_default=None ) default_authentication_method = fields.String( - missing='native', + load_default='native', validate=validate.OneOf(['native', 'ldap', 'saml']), allow_none=False, ) domain_names = fields.List( fields.String(validate=validate.Regexp(DOMAIN_RE)), - missing=[], - default=[], + load_default=[], + dump_default=[], allow_none=False, ) address = fields.Nested( TenantAddress, - missing=empty_tenant_address, - default=empty_tenant_address, + load_default=empty_tenant_address, + dump_default=empty_tenant_address, allow_none=False, ) diff --git a/wazo_auth/plugins/http/tokens/schemas.py b/wazo_auth/plugins/http/tokens/schemas.py index eb3704ec..19b619b7 100644 --- a/wazo_auth/plugins/http/tokens/schemas.py +++ b/wazo_auth/plugins/http/tokens/schemas.py @@ -12,7 +12,7 @@ class TokenRequestSchema(BaseSchema): - backend = fields.String(missing='wazo_user') + backend = fields.String(load_default='wazo_user') expiration = fields.Integer(validate=Range(min=1, max=TEN_YEARS)) access_type = fields.String(validate=OneOf(['online', 'offline'])) client_id = fields.String(validate=Length(min=1, max=1024)) @@ -87,4 +87,4 @@ class RefreshTokenSchema(BaseSchema): class TokenScopesRequestSchema(BaseSchema): scopes = fields.List(fields.String()) - tenant_uuid = fields.String(missing=None) + tenant_uuid = fields.String(load_default=None) diff --git a/wazo_auth/plugins/http/user_email/schemas.py b/wazo_auth/plugins/http/user_email/schemas.py index 6d4ba77e..ce0647c7 100644 --- a/wazo_auth/plugins/http/user_email/schemas.py +++ b/wazo_auth/plugins/http/user_email/schemas.py @@ -9,13 +9,13 @@ class _AdminEmailSchema(BaseSchema): address = fields.Email(required=True) - confirmed = fields.Boolean(missing=None, allow_none=True) - main = fields.Boolean(missing=False) + confirmed = fields.Boolean(load_default=None, allow_none=True) + main = fields.Boolean(load_default=False) class _UserEmailSchema(BaseSchema): address = fields.Email(required=True) - main = fields.Boolean(missing=False) + main = fields.Boolean(load_default=False) class _EmailPutSchema(BaseSchema): diff --git a/wazo_auth/plugins/http/user_registration/schemas.py b/wazo_auth/plugins/http/user_registration/schemas.py index 9280d335..0f272c06 100644 --- a/wazo_auth/plugins/http/user_registration/schemas.py +++ b/wazo_auth/plugins/http/user_registration/schemas.py @@ -9,8 +9,8 @@ class UserRegisterPostSchema(BaseSchema): username = fields.String(validate=validate.Length(min=1, max=256)) password = fields.String(validate=validate.Length(min=1), required=True) - firstname = fields.String(missing=None) - lastname = fields.String(missing=None) + firstname = fields.String(load_default=None) + lastname = fields.String(load_default=None) email_address = fields.Email(required=True) purpose = fields.Constant('user') authentication_method = fields.Constant('default') diff --git a/wazo_auth/plugins/http/users/schemas.py b/wazo_auth/plugins/http/users/schemas.py index a0237d6a..ff54f25d 100644 --- a/wazo_auth/plugins/http/users/schemas.py +++ b/wazo_auth/plugins/http/users/schemas.py @@ -9,17 +9,18 @@ class _BaseUserSchema(BaseSchema): username = fields.String( - validate=validate.Length(min=1, max=256), missing=None, allow_none=True + validate=validate.Length(min=1, max=256), load_default=None, allow_none=True ) - firstname = fields.String(missing=None, allow_none=True) - lastname = fields.String(missing=None, allow_none=True) + firstname = fields.String(load_default=None, allow_none=True) + lastname = fields.String(load_default=None, allow_none=True) purpose = fields.String( - missing='user', validate=validate.OneOf(['user', 'internal', 'external_api']) + load_default='user', + validate=validate.OneOf(['user', 'internal', 'external_api']), ) authentication_method = fields.String( validate=validate.OneOf(['default', 'native', 'ldap', 'saml']), ) - enabled = fields.Boolean(missing=True) + enabled = fields.Boolean(load_default=True) @pre_load def set_authentication_method(self, data, **kwargs): diff --git a/wazo_auth/schemas.py b/wazo_auth/schemas.py index fd9acdde..b7265d27 100644 --- a/wazo_auth/schemas.py +++ b/wazo_auth/schemas.py @@ -17,7 +17,7 @@ class GroupRequestSchema(BaseSchema): name = fields.String(validate=validate.Length(min=1, max=128), required=True) slug = fields.String( validate=[validate.Length(min=1, max=80), validate.Regexp(Slug.valid_re())], - missing=None, + load_default=None, ) @@ -31,14 +31,14 @@ class GroupFullSchema(BaseSchema): name = fields.String(validate=validate.Length(min=1, max=80), required=True) slug = fields.String( validate=[validate.Length(min=1, max=80), validate.Regexp(Slug.valid_re())], - missing=None, + load_default=None, ) read_only = fields.Boolean(dump_only=True, attribute='system_managed') system_managed = fields.Boolean(dump_only=True) class BaseListSchema(mallow.ListSchema): - recurse = fields.Boolean(missing=False) + recurse = fields.Boolean(load_default=False) class ExternalListSchema(BaseListSchema):