Skip to content

Authentication

import requests
import base64
import json

# Configuration
baseUrl = "https://localhost:8443"
username = "---USERNAME---"
password = "---PASSWORD---"

# Login & get JWT token
headers = {
    "Authorization":
        "Basic " +
        base64
        .b64encode(
            (username + ":" + password)
            .encode('utf-8')
        )
        .decode('utf-8')
}

response = requests.request("POST", "%s/api/v1/auth/login" % baseUrl, headers=headers, verify=False)
if response.status_code != 200:
    print("Login failed")
    exit()

authToken = response.text
headers = {"Authorization": "Bearer " + authToken}

# Get list of plugins
response = requests.get("%s/api/v1/plugins" % baseUrl, headers=headers, verify=False)
if response.status_code != 200:
    print("Could not get list of plugins")
    exit()

data = json.loads(response.text)
for pluginGroup in data:
    print(" # %s" % pluginGroup)
    print("   |- type: %s" % data[pluginGroup]["type"])
    print("   |- name: %s" % data[pluginGroup]["info"]["name"])
    print("   |- id: %s" % data[pluginGroup]["identifier"]["id"])
    if data[pluginGroup]["type"] == "command":
        print("   |- commands:")
        for commandName in data[pluginGroup]["commands"]:
            print("      * %s" % commandName)