summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-06-30 12:51:51 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-06-30 12:51:51 +0200
commitdbf0f00650200b8b4817274953f2e0b684bd622d (patch)
tree1bf085f2502e9704a7e1bf46cfc44aa039da5292 /cli
parentf41b5f8f9dd5672864b2dfe995e73f259741fa8b (diff)
Rename files to remove 'og' prefix
This prefix is redundant on almost every file, so the prefix is removed from filenames and imports.
Diffstat (limited to 'cli')
-rw-r--r--cli/__init__.py1
-rw-r--r--cli/cli.py39
-rw-r--r--cli/objects/__init__.py0
-rw-r--r--cli/objects/client.py6
-rw-r--r--cli/objects/modes.py6
-rw-r--r--cli/objects/scopes.py6
6 files changed, 58 insertions, 0 deletions
diff --git a/cli/__init__.py b/cli/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/cli/__init__.py
@@ -0,0 +1 @@
+
diff --git a/cli/cli.py b/cli/cli.py
new file mode 100644
index 0000000..30c1bb6
--- /dev/null
+++ b/cli/cli.py
@@ -0,0 +1,39 @@
+from cli.objects.client import OgClient
+from cli.objects.scopes import OgScope
+from cli.objects.modes import OgModes
+import argparse
+import requests
+import sys
+
+class OgREST():
+ def __init__(self, ip, port, api_token):
+ self.URL = f'http://{ip}:{port}'
+ self.HEADERS = {'Authorization' : api_token}
+
+ def get(self, path):
+ try:
+ r = requests.get(f'{self.URL}{path}',
+ headers=self.HEADERS)
+ if r.status_code != 200:
+ sys.exit(f"Cannot connect to ogServer: "
+ f"{r.status_code} HTTP status code")
+ except IOError as e:
+ sys.exit(f"Cannot connect to ogServer: {e}")
+ return r
+
+class OgCLI():
+ def __init__(self, cfg):
+ self.rest = OgREST(cfg['ip'], cfg['port'], cfg['api_token'])
+
+ def list(self, args):
+ choices = ['clients', 'scopes', 'modes']
+ parser = argparse.ArgumentParser()
+ parser.add_argument('item', choices=choices)
+ args = parser.parse_args(args)
+
+ if args.item == 'clients':
+ OgClient.list_clients(self.rest)
+ elif args.item == 'modes':
+ OgModes.list_available_modes(self.rest)
+ elif args.item == 'scopes':
+ OgScope.list_scopes(self.rest)
diff --git a/cli/objects/__init__.py b/cli/objects/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cli/objects/__init__.py
diff --git a/cli/objects/client.py b/cli/objects/client.py
new file mode 100644
index 0000000..ca91036
--- /dev/null
+++ b/cli/objects/client.py
@@ -0,0 +1,6 @@
+class OgClient():
+
+ @staticmethod
+ def list_clients(rest):
+ r = rest.get('/clients')
+ print(r.json())
diff --git a/cli/objects/modes.py b/cli/objects/modes.py
new file mode 100644
index 0000000..bf175d6
--- /dev/null
+++ b/cli/objects/modes.py
@@ -0,0 +1,6 @@
+class OgModes():
+
+ @staticmethod
+ def list_available_modes(rest):
+ r = rest.get('/modes')
+ print(r.json())
diff --git a/cli/objects/scopes.py b/cli/objects/scopes.py
new file mode 100644
index 0000000..0bf3ca8
--- /dev/null
+++ b/cli/objects/scopes.py
@@ -0,0 +1,6 @@
+class OgScope():
+
+ @staticmethod
+ def list_scopes(rest):
+ r = rest.get('/scopes')
+ print(r.json())