Source code for django_scim.utils
import json
from six.moves.urllib.parse import urlunparse
from .settings import scim_settings
[docs]def get_user_adapter():
"""
Return the user model adapter.
"""
return scim_settings.USER_ADAPTER
[docs]def get_group_model():
"""
Return the group model.
"""
return scim_settings.GROUP_MODEL
[docs]def get_group_adapter():
"""
Return the group model adapter.
"""
return scim_settings.GROUP_ADAPTER
[docs]def get_service_provider_config_model():
"""
Return the Service Provider Config model.
"""
return scim_settings.SERVICE_PROVIDER_CONFIG_MODEL
[docs]def get_base_scim_location_getter():
"""
Return a function that will, when called, returns the base
location of scim app.
"""
return scim_settings.BASE_LOCATION_GETTER
[docs]def get_all_schemas_getter():
"""
Return a function that will, when called, returns the base
location of scim app.
"""
return scim_settings.SCHEMAS_GETTER
[docs]def default_base_scim_location_getter(request=None, *args, **kwargs):
"""
Return the default location of the app implementing the SCIM api.
"""
base_scim_location_parts = (
scim_settings.SCHEME,
scim_settings.NETLOC,
'', # path
'', # params
'', # query
'' # fragment
)
base_scim_location = urlunparse(base_scim_location_parts)
return base_scim_location
def clean_structure_of_passwords(obj):
if isinstance(obj, dict):
new_obj = {}
for key, value in obj.items():
if 'password' in key.lower():
new_obj[key] = '*' * len(value) if value else None
else:
new_obj[key] = clean_structure_of_passwords(value)
return new_obj
elif isinstance(obj, list):
return [clean_structure_of_passwords(item) for item in obj]
else:
return obj
def get_loggable_body(text):
if not text:
return text
try:
obj = json.loads(text)
except:
return text
obj = clean_structure_of_passwords(obj)
return json.dumps(obj)