summaryrefslogtreecommitdiffstats
path: root/cli/objects/repo.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects/repo.py')
-rw-r--r--cli/objects/repo.py63
1 files changed, 42 insertions, 21 deletions
diff --git a/cli/objects/repo.py b/cli/objects/repo.py
index 7085633..d172a0d 100644
--- a/cli/objects/repo.py
+++ b/cli/objects/repo.py
@@ -13,8 +13,11 @@ class OgRepo():
@staticmethod
def list_repos(rest):
- r = rest.get('/repositories')
- print_json(r.text)
+ res = rest.get('/repositories')
+ if not res:
+ return 1
+ print_json(res.text)
+ return 0
@staticmethod
def _add_repo(rest, parsed_args):
@@ -22,37 +25,43 @@ class OgRepo():
'addr': parsed_args.ip,
'name': parsed_args.name,
}
- rest.post('/repository/add', payload=payload)
+ res = rest.post('/repository/add', payload=payload)
+ if not res:
+ return 1
+ return 0
@staticmethod
def _add_repo_ip(rest, parsed_args):
for ip in parsed_args.ip:
if not check_address(ip):
print(f'Invalid IP address: {ip}')
- return
+ return 1
- r = rest.get('/repositories')
+ res = rest.get('/repositories')
target_repo = None
- for repo in r.json()['repositories']:
+ for repo in res.json()['repositories']:
if repo['id'] == parsed_args.id:
target_repo = repo
break
if not target_repo:
print('Invalid repository id specified')
- return
+ return 1
for ip in parsed_args.ip:
if ip in target_repo['addr']:
print(f'The repository already contains the address {ip}')
- return
+ return 1
payload = {
'id': parsed_args.id,
'addr': target_repo['addr'] + parsed_args.ip,
'name': target_repo['name'],
}
- rest.post('/repository/update', payload=payload)
+ res = rest.post('/repository/update', payload=payload)
+ if not res:
+ return 1
+ return 0
@staticmethod
def add_repo(rest, args):
@@ -101,30 +110,33 @@ class OgRepo():
'name': parsed_args.name,
}
- rest.post('/repository/update', payload=payload)
+ res = rest.post('/repository/update', payload=payload)
+ if not res:
+ return 1
+ return 0
@staticmethod
def _delete_repo_ip(rest, parsed_args):
for ip in parsed_args.ip:
if not check_address(ip):
print(f'Invalid IP address: {ip}')
- return
+ return 1
- r = rest.get('/repositories')
+ res = rest.get('/repositories')
target_repo = None
- for repo in r.json()['repositories']:
+ for repo in res.json()['repositories']:
if repo['id'] == parsed_args.id:
target_repo = repo
break
if not target_repo:
print('Invalid repository id specified')
- return
+ return 1
for ip in parsed_args.ip:
if ip not in target_repo['addr']:
print(f'Invalid address {ip}: The repository has the following IPs: {target_repo["addr"]}')
- return
+ return 1
target_repo['addr'].remove(ip)
@@ -133,12 +145,18 @@ class OgRepo():
'addr': target_repo['addr'],
'name': target_repo['name'],
}
- rest.post('/repository/update', payload=payload)
+ res = rest.post('/repository/update', payload=payload)
+ if not res:
+ return 1
+ return 0
@staticmethod
def _delete_repo(rest, parsed_args):
payload = {'id': parsed_args.id}
- rest.post('/repository/delete', payload=payload)
+ res = rest.post('/repository/delete', payload=payload)
+ if not res:
+ return 1
+ return 0
@staticmethod
def delete_repo(rest, args):
@@ -184,8 +202,8 @@ class OgRepo():
help='Any valid client ip address')
parsed_args = parser.parse_args(args)
- r = rest.get('/scopes')
- scopes = r.json()
+ res = rest.get('/scopes')
+ scopes = res.json()
ips = set()
for room in parsed_args.room_id:
@@ -195,7 +213,10 @@ class OgRepo():
ips.add(l)
if not ips:
print('No valid clients specified.')
- return
+ return 1
payload = {'id': parsed_args.id, 'clients': list(ips)}
- rest.post('/client/repo', payload=payload)
+ res = rest.post('/client/repo', payload=payload)
+ if not res:
+ return 1
+ return 0