Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored danyi1212/django-windowsauth #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch https://github.com/sourcery-ai-bot/django-windowsauth main
git merge --ff-only FETCH_HEAD
git reset HEAD^

if domain:
# for specific domain
return user.ldap.domain == domain
else:
# for all domains
return True
return user.ldap.domain == domain if domain else True
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function domain_required.check_domain refactored with the following changes:

This removes the following comments ( why? ):

# for all domains
# for specific domain

Comment on lines -51 to +62
if user.is_authenticated and LDAPUser.objects.filter(user=user).exists():
try:
if WAUTH_USE_CACHE:
user.ldap.sync()
else:
# check via database query
if not timedelta or not user.ldap.last_sync or user.ldap.last_sync < timezone.now() - timedelta:
user.ldap.sync()

return True
except Exception as e:
if raise_exception:
raise e
else:
return False
else:
if (
not user.is_authenticated
or not LDAPUser.objects.filter(user=user).exists()
):
return allow_non_ldap
try:
if WAUTH_USE_CACHE:
user.ldap.sync()
elif not timedelta or not user.ldap.last_sync or user.ldap.last_sync < timezone.now() - timedelta:
user.ldap.sync()

return True
except Exception as e:
if raise_exception:
raise e
else:
return False
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ldap_sync_required.check_sync refactored with the following changes:

This removes the following comments ( why? ):

# check via database query

self.settings = settings if settings else LDAPSettings.for_domain(domain)
self.settings = settings or LDAPSettings.for_domain(domain)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LDAPManager.__init__ refactored with the following changes:

Comment on lines -43 to +58
else:
# check via database query
if not ldap_user.last_sync or ldap_user.last_sync < timezone.now() - timezone.timedelta(seconds=timeout):
ldap_user.sync()
elif not ldap_user.last_sync or ldap_user.last_sync < timezone.now() - timezone.timedelta(seconds=timeout):
ldap_user.sync()
except LDAPUser.DoesNotExist:
# user is getting created the first time
pass
except Exception as e:
logger.exception(f"Failed to synchronize user {request.user} against LDAP")
# return error response
if WAUTH_REQUIRE_RESYNC:
if isinstance(WAUTH_ERROR_RESPONSE, int):
return HttpResponse(f"Authorization Failed.", status=WAUTH_ERROR_RESPONSE)
elif callable(WAUTH_ERROR_RESPONSE):
if isinstance(WAUTH_ERROR_RESPONSE, int):
if WAUTH_REQUIRE_RESYNC:
return HttpResponse("Authorization Failed.", status=WAUTH_ERROR_RESPONSE)
elif callable(WAUTH_ERROR_RESPONSE):
if WAUTH_REQUIRE_RESYNC:
return WAUTH_ERROR_RESPONSE(request, e)
else:
raise e
response = self.get_response(request)
return response
elif WAUTH_REQUIRE_RESYNC:
raise e
return self.get_response(request)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function UserSyncMiddleware.__call__ refactored with the following changes:

This removes the following comments ( why? ):

# return error response
# check via database query

Comment on lines +48 to +52
elif "\\" in username:
domain, sam_account_name = username.split("\\", 2)

else:
raise ValueError("Username must be in DOMAIN\\username format.")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LDAPUserManager.create_user refactored with the following changes:

Comment on lines -65 to +67
return format_bytes(obj.bytes_received) + " / " + format_bytes(obj.bytes_transmitted)
return f'{format_bytes(obj.bytes_received)} / ' + format_bytes(
obj.bytes_transmitted
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LDAPUsageAdmin.bytes refactored with the following changes:

Comment on lines -68 to +70
return str(obj.messages_received) + " / " + str(obj.messages_transmitted)
return f'{str(obj.messages_received)} / {str(obj.messages_transmitted)}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LDAPUsageAdmin.messages refactored with the following changes:

Comment on lines -71 to +75
return str(obj.open_sockets) + " / " + str(obj.closed_sockets) + " / " + str(obj.wrapped_sockets)
return f'{str(obj.open_sockets)} / {str(obj.closed_sockets)} / ' + str(
obj.wrapped_sockets
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LDAPUsageAdmin.sockets refactored with the following changes:

logger.info(f"Unbinding all LDAP Connections for collecting metrics")
logger.info("Unbinding all LDAP Connections for collecting metrics")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function collect_metrics refactored with the following changes:

Comment on lines -69 to +73
# predefined tasks
if command in PREDEFINED_TASKS:
create_task = PREDEFINED_TASKS[command]
create_task(command=command, name=name, desc=desc, identity=identity, folder=folder,
interval=interval, random=random, timeout=timeout, priority=priority)
else:
if command not in PREDEFINED_TASKS:
raise CommandError(f"Predefined task for \"{command}\" does not exist.")
create_task = PREDEFINED_TASKS[command]
create_task(command=command, name=name, desc=desc, identity=identity, folder=folder,
interval=interval, random=random, timeout=timeout, priority=priority)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Command.handle refactored with the following changes:

This removes the following comments ( why? ):

# predefined tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant