Esempio n. 1
0
def addHost(listHost):
    (json, errors) = hostValidate()

    if errors:
        return basic.resp(400, {"errors": errors})

    try:
        if not findParams(json):
            return basic.resp(400, {"errors": "uncorrected"})

        if not 'username' in json:
            username = str(json['user'])
        else:
            username = str(json['username'])

        newHost = Host(username, str(json['hostname']), str(json['user']))

        if 'auth_type' in json:
            if json['auth_type'] == 'psw' and 'password' in json:
                newHost.setPassword(json['password'])
            if json['auth_type'] == 'key' and 'key' in json:
                newHost.setKey(json['key'])
    except:
        return basic.resp(400, {"errors": "uncorrected"})

    listHost.append(newHost)

    return basic.resp(200, {})
Esempio n. 2
0
def getHosts(tmp_hosts):
    try:
        answer = []
        for host in tmp_hosts:
            answer_item = {
                "username": host.user,
                "user": host.hostuser,
                "auth_type": host.typeAuth,
                "hostname": host.hostname
            }

            if not host.activeHost:
                answer_item["active"] = bool(False)
                answer.append(answer_item)
                continue

            answer_item["active"] = bool(True)

            if not host.branchGit == '':
                answer_item["git"] = {
                    "branch": host.branchGit,
                    "revision": host.revisionGit
                }

            if not host.branchSVN == '':
                answer_item["svn"] = {
                    "branch": host.branchSVN,
                    "revision": host.revisionSVN
                }

            answer.append(answer_item)
    except:
        return basic.resp(400, {"errors": "Did not form response"})

    return basic.resp(200, {"hosts": answer})
Esempio n. 3
0
def clear():
    lock.acquire()
    listHost.clear()
    lock.release()
    return basic.resp(200, {})
Esempio n. 4
0
def ping():
    return basic.resp(200, {})
Esempio n. 5
0
def page_not_found(e):
    return basic.resp(405, {})
Esempio n. 6
0
def hello_world():
    return basic.resp(400, {})