GET all company tokens and system entity hierarchy

Use get_deep_config.py to print the system's company tokens and entity hierarchy to the console using multiple /config requests.

Figure 1. get_deep_config.py
#!/usr/bin/env python

# Copyright 2017 Voci Technologies All rights reserved.
# Unsupported example code - Not for production use.

# Uses root token to read company and folder information from the specified host
# 
# Prints a hierarchical listing of available companies (each with its
# associated authorization token), the organizations within those
# companies, and the folders within those organizations.

import requests

def usage(argv):
    print "Usage:", argv[0], "<sparkhost:port> <root token>"
    exit(1)

def main(argv): 
    if len(argv) != 3: usage(argv)
    host, token = argv[1:]
    tokens = gettokens(host,token)
    folderinfo = getfolderinfo(host,token)
    printfolders(host, folderinfo, tokens)

def gettokens(host, token): 
    url = "http://%s/config?token=%s" % (host,token)
    cfg = requests.get(url).json()
    return dict([(comp,d['uuid']) for comp,d in cfg.iteritems()])

def getfolderinfo(host, token): 
    url = "http://%s/config/folders?token=%s" % (host,token)
    return requests.get(url).json()

def printfolders(host, folder_info, tokens):
    for comp, comp_data in folder_info.iteritems(): 
        print comp+" (Token: "+tokens[comp]+")"
        for org, org_data in comp_data.iteritems(): 
            print "\t", org
            for folder, folder_data in org_data.iteritems(): 
                print "\t\t", folder

if __name__ == '__main__':
    from sys import argv
    main(argv)

get_deep_config.py prints a table of company tokens to the console, along with a hierarchy of the system's company, organization, and folder entities.

Use this script with the following command and arguments:

python get_deep_config.py $host:$port $root_token
$host
Hostname or URL for the system running V‑Spark.
$port
Port configured for the host system. Default 3000.
$root_token
V‑Spark's root authorization token. Only available to system administrators.