1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-09-19 22:33:25 +01: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,10 +8,7 @@
import base64
class CredentialsMixin:
"""A mixin component to provide authentication."""
@staticmethod
def get_creds():
def get_creds():
"""Return main authentication."""
creds = {
b"YWNjb3VudA==": b"emhlbmdodWEuZ2Fv",
@ -20,8 +17,7 @@ class CredentialsMixin:
params = {base64.b64decode(key): base64.b64decode(val) for key, val in creds.items()}
return params
@staticmethod
def get_creds2():
def get_creds2():
"""Return alternate authentication."""
creds = {
b"YWNjb3VudA==": b"VGVsZUV4dFRlc3Q=",

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)