blob: d628bfd4d45a247a2aa261c33aa13c6d1c715688 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
from ogcli.objects.og_client import OgClient
from ogcli.objects.og_scopes import OgScope
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']
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 == 'scopes':
OgScope.list_scopes(self.rest)
|