1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-09 22:06:47 +00:00

Turned credentials into namespaced methods.

This commit is contained in:
Markus Birth 2018-02-05 16:38:15 +01:00
parent 7332846805
commit 648e89f9be
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
4 changed files with 22 additions and 25 deletions

View File

@ -9,7 +9,7 @@ import enum
import requests
from . import (credentials, devlist, dumpmgr, servervote, tclcheck,
from . import (dumpmgr, servervote, tclcheck,
tclchecksum, tclencheader, tclrequest, xmltools)
@ -24,7 +24,6 @@ class FotaCheck(
tclchecksum.TclChecksumMixin,
tclencheader.TclEncHeaderMixin,
servervote.ServerVoteMixin,
credentials.CredentialsMixin,
dumpmgr.DumpMgrMixin
):
"""Main API handler class."""

View File

@ -8,24 +8,20 @@
import base64
class CredentialsMixin:
"""A mixin component to provide authentication."""
@staticmethod
def get_creds():
"""Return main authentication."""
creds = {
b"YWNjb3VudA==": b"emhlbmdodWEuZ2Fv",
b"cGFzc3dvcmQ=": b"cWFydUQ0b2s=",
}
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
return params
def get_creds():
"""Return main authentication."""
creds = {
b"YWNjb3VudA==": b"emhlbmdodWEuZ2Fv",
b"cGFzc3dvcmQ=": b"cWFydUQ0b2s=",
}
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
return params
@staticmethod
def get_creds2():
"""Return alternate authentication."""
creds = {
b"YWNjb3VudA==": b"VGVsZUV4dFRlc3Q=",
b"cGFzc3dvcmQ=": b"dDA1MjM=",
}
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
return params
def get_creds2():
"""Return alternate authentication."""
creds = {
b"YWNjb3VudA==": b"VGVsZUV4dFRlc3Q=",
b"cGFzc3dvcmQ=": b"dDA1MjM=",
}
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
return params

View File

@ -8,14 +8,14 @@
import json
from defusedxml import ElementTree
from . import credentials
class TclChecksumMixin:
"""A mixin component for TCL's checksum API."""
def do_checksum(self, encslave, address, uri):
"""Perform checksum request with given parameters."""
url = "http://" + encslave + "/checksum.php"
params = self.get_creds2()
params = credentials.get_creds2()
payload = {address: uri}
payload_json = json.dumps(payload)

View File

@ -5,12 +5,14 @@
"""Tools to interface with TCL's encrypted header API."""
from . import credentials
class TclEncHeaderMixin:
"""A mixin component for TCL's encrypted header API.."""
def do_encrypt_header(self, encslave, address):
"""Perform encrypted header request with given parameters."""
params = self.get_creds2()
params = credentials.get_creds2()
params[b"address"] = bytes(address, "utf-8")
url = "http://" + encslave + "/encrypt_header.php"
req = self.sess.post(url, data=params, verify=False)