Skip to content

Commit

Permalink
schemas: replace missing and default
Browse files Browse the repository at this point in the history
missing and default are deprecated and have been replaced by
load_default and dump_default respectively
  • Loading branch information
pc-m committed Dec 31, 2024
1 parent e0ea731 commit 99c5af7
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 52 deletions.
10 changes: 6 additions & 4 deletions wazo_auth/plugins/external_auth/mobile/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 14 additions & 10 deletions wazo_auth/plugins/http/ldap_config/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions wazo_auth/plugins/http/password_reset/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions wazo_auth/plugins/http/policies/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 16 additions & 16 deletions wazo_auth/plugins/http/tenants/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,60 @@ 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
)


empty_tenant_address = TenantAddress().dump({})


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,
)

Expand Down
4 changes: 2 additions & 2 deletions wazo_auth/plugins/http/tokens/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions wazo_auth/plugins/http/user_email/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions wazo_auth/plugins/http/user_registration/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
11 changes: 6 additions & 5 deletions wazo_auth/plugins/http/users/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions wazo_auth/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand All @@ -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):
Expand Down

0 comments on commit 99c5af7

Please sign in to comment.