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

Auth #260

Merged
merged 3 commits into from
Aug 11, 2022
Merged

Auth #260

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.7.13] - 2022-08-11
### Updated
- [Authenticator] API
- [AsyncTool] API

## [1.7.12] - 2022-08-10
### Updated
- [Authenticator] API
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OctoBot-Commons [1.7.12](https://github.com/Drakkar-Software/OctoBot-Commons/blob/master/CHANGELOG.md)
# OctoBot-Commons [1.7.13](https://github.com/Drakkar-Software/OctoBot-Commons/blob/master/CHANGELOG.md)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b31f3ab3511744a5a5ca6b9bb48e77bb)](https://app.codacy.com/gh/Drakkar-Software/OctoBot-Commons?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/OctoBot-Commons&utm_campaign=Badge_Grade_Dashboard)
[![PyPI](https://img.shields.io/pypi/v/OctoBot-Commons.svg)](https://pypi.python.org/pypi/OctoBot-Commons/)
[![Coverage Status](https://coveralls.io/repos/github/Drakkar-Software/OctoBot-Commons/badge.svg?branch=master)](https://coveralls.io/github/Drakkar-Software/OctoBot-Commons?branch=master)
Expand Down
2 changes: 1 addition & 1 deletion octobot_commons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# License along with this library.

PROJECT_NAME = "OctoBot-Commons"
VERSION = "1.7.12" # major.minor.revision
VERSION = "1.7.13" # major.minor.revision

MARKET_SEPARATOR = "/"
DICT_BULLET_TOKEN_STR = "\n "
Expand Down
19 changes: 10 additions & 9 deletions octobot_commons/asyncio_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,35 @@
import octobot_commons.constants as constants
import octobot_commons.logging as logging_util

LOGGER = logging_util.get_logger("asyncio_tools")


def run_coroutine_in_asyncio_loop(coroutine, async_loop):
def run_coroutine_in_asyncio_loop(coroutine, async_loop, log_exceptions=True):
"""
Run a coroutine in the specified asyncio loop
:param coroutine: the coroutine to run
:param async_loop: the asyncio loop
:param log_exceptions: logs exceptions when True
:return: the execution result
"""
logger = logging_util.get_logger("asyncio_tools")
current_task_before_start = asyncio.current_task(async_loop)
future = asyncio.run_coroutine_threadsafe(coroutine, async_loop)
try:
return future.result(constants.DEFAULT_FUTURE_TIMEOUT)
except asyncio.TimeoutError as timeout_error:
LOGGER.error(
logger.error(
f"{coroutine} coroutine took too long to execute, cancelling the task. "
f"(current task before starting this one: {current_task_before_start}, actual current "
f"task before cancel: {asyncio.current_task(async_loop)})"
)
future.cancel()
raise timeout_error
except Exception as global_exception:
LOGGER.exception(
global_exception,
True,
f"{coroutine} coroutine raised an exception: {global_exception}",
)
if log_exceptions:
logger.exception(
global_exception,
True,
f"{coroutine} coroutine raised an exception: {global_exception}",
)
raise global_exception


Expand Down
7 changes: 7 additions & 0 deletions octobot_commons/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def is_logged_in(self):
"""
raise NotImplementedError

@abc.abstractmethod
def must_be_authenticated_through_authenticator(self):
"""
:return: True when this authenticator has to be validated
"""
raise NotImplementedError

@abc.abstractmethod
def ensure_token_validity(self):
"""
Expand Down