Move UltimakerCloudAuthentication and UltimakerCloudScope

...to their own module
Fixes an import error where UltimakerCloudScope was used my both the
Toolbox and CuraDrive plugins

CURA-7150
This commit is contained in:
Nino van Hooff 2020-03-12 17:48:54 +01:00
parent 2e7b47f1ea
commit 96ed85f9c0
15 changed files with 53 additions and 80 deletions

View file

@ -1,31 +0,0 @@
from PyQt5.QtNetwork import QNetworkRequest
from UM.Logger import Logger
from UM.TaskManagement.HttpRequestScope import DefaultUserAgentScope
from cura.API import Account
from cura.CuraApplication import CuraApplication
class UltimakerCloudScope(DefaultUserAgentScope):
"""Add an Authorization header to the request for Ultimaker Cloud Api requests.
When the user is not logged in or a token is not available, a warning will be logged
Also add the user agent headers (see DefaultUserAgentScope)
"""
def __init__(self, application: CuraApplication):
super().__init__(application)
api = application.getCuraAPI()
self._account = api.account # type: Account
def requestHook(self, request: QNetworkRequest):
super().requestHook(request)
token = self._account.accessToken
if not self._account.isLoggedIn or token is None:
Logger.warning("Cannot add authorization to Cloud Api request")
return
header_dict = {
"Authorization": "Bearer {}".format(token)
}
self.addHeaders(request, header_dict)