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:
parent
7332846805
commit
648e89f9be
@ -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."""
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user