<commit_before>#!/usr/bin/python3
# pylint: disable=invalid-name,missing-docstring
#
# Copyright (C) 2021 <NAME> <<EMAIL>>
#
# SPDX-License-Identifier: LGPL-2.1+

import json

from flask import Flask, Response, request, g

app = Flask(__name__)

HARDCODED_USERNAME = "username2"
HARDCODED_PASSWORD = "<PASSWORD>"

app._percentage: int = 0


def _failure(msg: str, status=400):
    res = {
        "error": {"message": msg},
    }
    return Response(response=json.dumps(msg), status=401, mimetype="application/json")


@app.route("/redfish/v1/")
def index():

    # reset counter
    app._percentage = 0

    # check password from the config file
    try:
        if (
            request.authorization["username"] != HARDCODED_USERNAME
            or request.authorization["password"] != HARDCODED_PASSWORD
        ):
            return _failure("unauthorised", status=401)
    except (KeyError, TypeError):
        return _failure("invalid")

    res = {
        "@odata.id": "/redfish/v1/",
        "RedfishVersion": "1.6.0",
        "UUID": "92384634-2938-2342-8820-489239905423",
        "UpdateService": {"@odata.id": "/redfish/v1/UpdateService"},
    }
    return Response(json.dumps(res), status=200, mimetype="application/json")


@app.route("/redfish/v1/UpdateService")<commit_msg>trivial: redfish: drop unused import and variables<commit_after>#!/usr/bin/python3
# pylint: disable=invalid-name,missing-docstring
#
# Copyright (C) 2021 <NAME> <<EMAIL>>
#
# SPDX-License-Identifier: LGPL-2.1+

import json

from flask import Flask, Response, request

app = Flask(__name__)

HARDCODED_USERNAME = "username2"
HARDCODED_PASSWORD = "<PASSWORD>"

app._percentage: int = 0


def _failure(msg: str, status=400):
    res = {
        "error": {"message": msg},
    }
    return Response(response=json.dumps(res), status=401, mimetype="application/json")


@app.route("/redfish/v1/")
def index():

    # reset counter
    app._percentage = 0

    # check password from the config file
    try:
        if (
            request.authorization["username"] != HARDCODED_USERNAME
            or request.authorization["password"] != HARDCODED_PASSWORD
        ):
            return _failure("unauthorised", status=401)
    except (KeyError, TypeError):
        return _failure("invalid")

    res = {
        "@odata.id": "/redfish/v1/",
        "RedfishVersion": "1.6.0",
        "UUID": "92384634-2938-2342-8820-489239905423",
        "UpdateService": {"@odata.id": "/redfish/v1/UpdateService"},
    }
    return Response(json.dumps(res), status=200, mimetype="application/json")


@app.route("/redfish/v1/UpdateService")
{'fraction_non_alphanumeric': 0.15099388379204892, 'fraction_numerical': 0.046636085626911315, 'mean_word_length': 3.304276315789474, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2741361', 'n_tokens_mistral': 951, 'n_tokens_neox': 873, 'n_words': 170}