From be18d619e69755ee836175d414dada7b6b3cf13e Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Fri, 19 Jun 2020 13:10:14 +0200 Subject: Add list scopes command This is consistent with HTTP GET /scopes --- ogcli/objects/og_scopes.py | 6 ++++++ ogcli/ogcli.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 ogcli/objects/og_scopes.py (limited to 'ogcli') diff --git a/ogcli/objects/og_scopes.py b/ogcli/objects/og_scopes.py new file mode 100644 index 0000000..0bf3ca8 --- /dev/null +++ b/ogcli/objects/og_scopes.py @@ -0,0 +1,6 @@ +class OgScope(): + + @staticmethod + def list_scopes(rest): + r = rest.get('/scopes') + print(r.json()) diff --git a/ogcli/ogcli.py b/ogcli/ogcli.py index 37fb2e0..d628bfd 100644 --- a/ogcli/ogcli.py +++ b/ogcli/ogcli.py @@ -1,4 +1,5 @@ from ogcli.objects.og_client import OgClient +from ogcli.objects.og_scopes import OgScope import argparse import requests import sys @@ -10,7 +11,7 @@ class OgREST(): def get(self, path): try: - r = requests.get(f'{self.URL}/clients', + r = requests.get(f'{self.URL}{path}', headers=self.HEADERS) if r.status_code != 200: sys.exit(f"Cannot connect to ogServer: " @@ -24,9 +25,12 @@ class OgCLI(): self.rest = OgREST(cfg['ip'], cfg['port'], cfg['api_token']) def list(self, args): + choices = ['clients', 'scopes'] parser = argparse.ArgumentParser() - parser.add_argument('item', choices=['clients']) + parser.add_argument('item', choices=choices) args = parser.parse_args(args) if args.item == 'clients': OgClient.list_clients(self.rest) + elif args.item == 'scopes': + OgScope.list_scopes(self.rest) -- cgit v1.2.3-18-g5258