diff --git a/manage.py b/manage.py index 0740731..69d0ae0 100755 --- a/manage.py +++ b/manage.py @@ -2,7 +2,11 @@ import os import sys import click +import random +import string from logzero import logger +from passlib.hash import pbkdf2_sha256 + from hyperglass import render as render from hyperglass import hyperglass @@ -22,6 +26,24 @@ def clearcache(): logger.error("Failed to clear cache.") +@main.command() +def generatekey(string_length=16): + ld = string.ascii_letters + string.digits + api_key = "".join(random.choice(ld) for i in range(string_length)) + key_hash = pbkdf2_sha256.hash(api_key) + click.echo( + """ +Your API Key is: {api_key} +Place your API Key in the `configuration.py` of your API module. For example, in: `hyperglass-frr/configuration.py` + +Your Key Hash is: {key_hash} +Use this hash as the password for the device using the API module. For example, in: `hyperglass/hyperglass/configuration/devices.toml` +""".format( + api_key=api_key, key_hash=key_hash + ) + ) + + @main.command() def testserver(): try: diff --git a/requirements.txt b/requirements.txt index 5fe4c38..7924c40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ markdown2 libsass logzero click +passlib