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

Audit after join, Audit Queueing, Swagger UI #38

Merged
merged 22 commits into from
Oct 24, 2020
Merged

Audit after join, Audit Queueing, Swagger UI #38

merged 22 commits into from
Oct 24, 2020

Conversation

Xyaren
Copy link
Contributor

@Xyaren Xyaren commented Sep 22, 2020

  • Add Swagger UI on / route
  • Add Audit on join (prioritized)
  • Enable queued audit processing
  • Move audit functions to separate service
  • allow cli arguments to be passed via ENV variables
  • allow log level and filepath to be provided via args
  • fixed some linter warnings
  • fix bug that caused leftover guild icons on the server on deleting the guild
  • slightly improved performance of audit for users that are in the Database but not in the Ts DB (flipped if-conditions)
  • remove reinit of ts connection as this is working with listeners and "state" of the connection. (Name, Channel etc)

@Xyaren Xyaren self-assigned this Sep 22, 2020
@Xyaren Xyaren added enhancement New feature or request refactoring Somehting that need to be done but isn't a current bug labels Sep 22, 2020
@Xyaren Xyaren linked an issue Sep 22, 2020 that may be closed by this pull request
* Add Audit on join (prioritized)
* Enable queued audit processing
* Move audit functions to separate service
* allow arguments to be passed via ENV variables
* allow log level and filepath to be provided via args
* fixe some linter warnings
* fix bug that caused leftover guild icons on the server on deleting the guild
bot/main.py Outdated Show resolved Hide resolved
/health:
get:
summary: Healthckeck
operationId: helathCheck
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a typo here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still seeing it as "helathCheck" on my end.

bot/ts/TS3Facade.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ogrady ogrady left a comment

Choose a reason for hiding this comment

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

Looks generally good, see some inline comments.

@Xyaren
Copy link
Contributor Author

Xyaren commented Sep 30, 2020

@ogrady As there have been some dramatic changes, I would like to request a re-review :)

@Xyaren Xyaren requested a review from ogrady September 30, 2020 10:03
bot/emblem_downloader.py Outdated Show resolved Hide resolved
bot/audit_service.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ogrady ogrady left a comment

Choose a reason for hiding this comment

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

This review was brought to you by: my darn tablet with no English keyboard. :)

bot/audit_service.py Outdated Show resolved Hide resolved
bot/event_looper.py Outdated Show resolved Hide resolved
bot/event_looper.py Show resolved Hide resolved
bot/event_looper.py Show resolved Hide resolved
bot/event_looper.py Outdated Show resolved Hide resolved
/health:
get:
summary: Healthckeck
operationId: helathCheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Still seeing it as "helathCheck" on my end.

@@ -20,11 +21,21 @@ def __init__(self, ts3_connection: ThreadSafeTSConnection):
def close(self):
self._ts3_connection.close()

def __str__(self):
return f"TS3Facade[{self._ts3_connection}]"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should settle on a consistent style for formatting strings. %-style seems to be the more prevalent one in this project rn, would you be fine with that?

Copy link
Contributor Author

@Xyaren Xyaren Oct 1, 2020

Choose a reason for hiding this comment

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

Log statement are using %s, for performance reasons, as the String is not built when not logged. (https://docs.python.org/3/howto/logging.html#optimization)
This on the other hand will always be "formatted" when called, always.
f Style strings are much more readable in my opinion and should be favored if possible.

Not only are they more readable, more concise, and less prone to error than other ways of formatting, but they are also faster!
Great readup: https://realpython.com/python-f-strings/

try:
resp = self._ts3_connection.ts3exec_raise(lambda tc: tc.wait_for_event(timeout=timeout))
except TS3TimeoutError:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

resp = None

Same effect but structured.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm much more of a fan of early returns, especially in a indentation based language like python.
It makes diffs much more readable for example if code gets added or removed.

Readup: https://softwareengineering.stackexchange.com/questions/18454/should-i-return-from-a-function-early-or-use-an-if-statement

Copy link
Contributor

Choose a reason for hiding this comment

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

This is arguably an early return in this particular case, as the whole function is just one statement (other than that, not really in line with SE-discussion), but same reasoning as before: putting cleanup code below except is then skipped altogether when catching an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleanup code should be handled in a "finally" block or even better using a "with" statement.

Yes this is only one small function, but in terms of extendability the same rule applies here.

@@ -19,6 +19,11 @@ def default_exception_handler(ex):
return ex


def raise_exception_handler(ex):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really a fan. This is what signal_exception_handler is for, adhering to the functional style of this part of the code, losely based on https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Either.html

Copy link
Contributor Author

@Xyaren Xyaren Oct 1, 2020

Choose a reason for hiding this comment

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

This would require manually raising the error through the whole callstack during the event loop. This leads to more clutter than it is already.
This is basically what Exceptions are made for.
Using exceptions Errors are not silently ignored if not looked for explicitly. You have to deal with the error explicitly sooner or later. This inevitably leads to more reliant code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Absolutely! And I am not particularly a fan of raising exceptions through multiple layers of the call stack (read: goto), unless they signal absolutely application-breaking circumstances in which any cleanup can be bypassed (this probably ultimately lead to the invention of the finally block, which basically is spaghetti to me).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the case here. We are talking about Connection Problems, which can not be dealt with where they occur.

bot/user_service.py Outdated Show resolved Hide resolved
@Xyaren Xyaren marked this pull request as ready for review October 17, 2020 16:50
@Xyaren
Copy link
Contributor Author

Xyaren commented Oct 22, 2020

Update:
Added SSH query connection option (default is still telnet)

@Xyaren
Copy link
Contributor Author

Xyaren commented Oct 22, 2020

Pylint is currently restricted to Python 3.8.x (pylint-dev/pylint#3882 (comment))
I changed the build action to use 3.8.x instead of 3.x

@Xyaren Xyaren merged commit 8e975bc into FlussuferOrga:master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring Somehting that need to be done but isn't a current bug
Projects
None yet
2 participants