Add utils command 85/63585/9
authorDW Talton <dtalton@contractor.linuxfoundation.org>
Sun, 29 Mar 2020 21:15:01 +0000 (14:15 -0700)
committerBengt Thuree <bthuree@linuxfoundation.org>
Mon, 6 Apr 2020 02:09:22 +0000 (12:09 +1000)
Add utils command to hold utilities like password generators
and whatnot.

Issue-ID: RELENG-2754
Signed-off-by: DW Talton <dtalton@contractor.linuxfoundation.org>
Change-Id: I968c73f52a87c4436c355a1b9b66a49128a3bf56

lftools/cli/__init__.py
lftools/cli/utils.py [new file with mode: 0644]
releasenotes/notes/add_util_passgen-1c2b08bbf4771c12.yaml [new file with mode: 0644]

index fb790be..8422bb0 100644 (file)
@@ -33,6 +33,7 @@ from lftools.cli.nexus import nexus
 from lftools.cli.rtd import rtd
 from lftools.cli.schema import schema
 from lftools.cli.sign import sign
+from lftools.cli.utils import utils
 from lftools.cli.version import version
 
 log = logging.getLogger(__name__)
@@ -92,6 +93,7 @@ cli.add_command(rtd)
 cli.add_command(schema)
 cli.add_command(lfidapi)
 cli.add_command(sign)
+cli.add_command(utils)
 cli.add_command(version)
 
 try:
diff --git a/lftools/cli/utils.py b/lftools/cli/utils.py
new file mode 100644 (file)
index 0000000..db81ff0
--- /dev/null
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2020 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+"""lftools utils command."""
+
+import click
+import logging
+
+from lftools import helpers
+
+log = logging.getLogger(__name__)
+
+
+@click.group()
+@click.pass_context
+def utils(ctx):
+    """Tools to make life easier."""
+    pass
+
+
+@click.command(name="passgen")
+@click.argument("length", required=False)
+@click.pass_context
+def password_generator(ctx, length):
+    """Generate a complex password.
+
+    Length defaults to 12 characters if not specified.
+    """
+    if length:
+        log.info(helpers.generate_password(int(length)))
+    else:
+        log.info(helpers.generate_password())
+
+
+utils.add_command(password_generator)
diff --git a/releasenotes/notes/add_util_passgen-1c2b08bbf4771c12.yaml b/releasenotes/notes/add_util_passgen-1c2b08bbf4771c12.yaml
new file mode 100644 (file)
index 0000000..bc07fc3
--- /dev/null
@@ -0,0 +1,4 @@
+---
+features:
+  - |
+    Add utils section, with password generator (passgen).