Passowrd and username checking now happens in @auth decorator. do_list_users and do_network_partitions added
Signed-off-by: Imesh Gunaratne <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5c9a9bf1 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5c9a9bf1 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5c9a9bf1 Branch: refs/heads/stratos-4.1.x Commit: 5c9a9bf134d176258d77fd87ba6e938d71a73cf7 Parents: f7a047d Author: Milindu Sanoj Kumarage <[email protected]> Authored: Sat Jul 25 12:29:13 2015 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Oct 13 16:32:45 2015 +0530 ---------------------------------------------------------------------- .../src/main/python/cli/CLI.py | 74 ++++++++++++++------ .../src/main/python/tox.ini | 0 2 files changed, 54 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/5c9a9bf1/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py b/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py index 7ba7dcd..554ba49 100755 --- a/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py +++ b/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py @@ -10,37 +10,71 @@ class CLI(Cmd): prompt = Configs.stratos_prompt # resolving the '-' issue Cmd.legalChars += '-' - Cmd.shortcuts.update({'deploy-user': 'deploy_user'}) + Cmd.shortcuts.update({'list-user': 'list_user'}) def completenames(self, text, *ignored): - return [a[3:].replace('_','-') for a in self.get_names() if a.replace('_','-').startswith('do-'+text)] - + return [a[3:].replace('_', '-') for a in self.get_names() if a.replace('_', '-').startswith('do-'+text)] @options([ make_option('-u', '--username', type="str", help="Username of the user"), make_option('-p', '--password', type="str", help="Password of the user") ]) + @auth def do_repositories(self, line, opts=None): """ Shows the git repositories of the user identified by given the username and password eg: repositories -u agentmilindu -p agentmilindu123 """ - if opts.username and opts.password: - r = requests.get('https://api.github.com/users/' + opts.username + '/repos?per_page=5', - auth=(opts.username, opts.password)) - repositories = r.json() - table = PrintableTable() - rows = [["Name", "language"]] - table.set_cols_align(["l", "r"]) - table.set_cols_valign(["t", "m"]) - - for repo in repositories: - rows.append([repo['name'], repo['language']]) - print(rows) - table.add_rows(rows) - table.print_table() - - else: - print("Some required argument(s) missing") + r = requests.get('https://api.github.com/users/' + Configs.stratos_username + '/repos?per_page=5', + auth=(Configs.stratos_username, Configs.stratos_password)) + repositories = r.json() + print(r) + print(repositories) + table = PrintableTable() + rows = [["Name", "language"]] + table.set_cols_align(["l", "r"]) + table.set_cols_valign(["t", "m"]) + + for repo in repositories: + rows.append([repo['name'], repo['language']]) + print(rows) + table.add_rows(rows) + table.print_table() + + + + @options([ + make_option('-u', '--username', type="str", help="Username of the user"), + make_option('-p', '--password', type="str", help="Password of the user") + ]) + @auth + def do_list_users(self, line , opts=None): + """Illustrate the base class method use.""" + r = requests.get(Configs.stratos_api_url + 'users', + auth=(Configs.stratos_username, Configs.stratos_password), verify=False) + users = r.json() + table = PrintableTable() + rows = [["Name", "language"]] + table.set_cols_align(["l", "r"]) + table.set_cols_valign(["t", "m"]) + for user in users: + rows.append([user['role'], user['userName']]) + table.add_rows(rows) + table.print_table() + + @options([ + make_option('-u', '--username', type="str", help="Username of the user"), + make_option('-p', '--password', type="str", help="Password of the user") + ]) + @auth + def do_networkpartitions(self, line , opts=None): + """Illustrate the base class method use.""" + r = requests.get(Configs.stratos_api_url + 'networkPartitions', + auth=(Configs.stratos_username, Configs.stratos_password), verify=False) + print(r) + print(r.text) + repositories = r.json() + tree = PrintableTree(repositories) + tree.print_tree() def do_deploy_user(self, line , opts=None): """Illustrate the base class method use.""" http://git-wip-us.apache.org/repos/asf/stratos/blob/5c9a9bf1/components/org.apache.stratos.python.cli/src/main/python/tox.ini ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cli/src/main/python/tox.ini b/components/org.apache.stratos.python.cli/src/main/python/tox.ini new file mode 100644 index 0000000..e69de29
