endpoints on client added
This commit is contained in:
parent
7a00abbd6f
commit
34588e7568
|
@ -16,7 +16,7 @@ state = main(sys.argv)
|
||||||
|
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role - permission
|
#session file - role - value(permission or username)
|
||||||
def addPermission(args):
|
def addPermission(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -26,12 +26,12 @@ def addPermission(args):
|
||||||
|
|
||||||
parser.add_argument('session', nargs='?', default=None)
|
parser.add_argument('session', nargs='?', default=None)
|
||||||
parser.add_argument('role', nargs='?',default=None)
|
parser.add_argument('role', nargs='?',default=None)
|
||||||
parser.add_argument('permission', nargs='?',default=None)
|
parser.add_argument('value', nargs='?',default=None)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
#Check number of arguments
|
#Check number of arguments
|
||||||
if not args.session or not args.role or not args.permission:
|
if not args.session or not args.role or not args.value:
|
||||||
logger.error("Need session file and role.")
|
logger.error("Need session file and role.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ def addPermission(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -47,13 +47,48 @@ def addPermission(args):
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
args.session = json.load(f)
|
args.session = json.load(f)
|
||||||
|
|
||||||
# TODO:
|
|
||||||
try:
|
isPerm = False; isUsername = False
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
|
||||||
req.raise_for_status()
|
# query for permission
|
||||||
except requests.exceptions.RequestException as errex:
|
if args.value in ['ROLE_ACL', 'SUBJECT_NEW', 'SUBJECT_DOWN', 'SUBJECT_UP', 'DOC_NEW']:
|
||||||
logger.error("Failed to obtain response from server.")
|
isPerm = True
|
||||||
sys.exit(-1)
|
else:
|
||||||
|
try:
|
||||||
|
subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list',
|
||||||
|
json=json.dumps({'username' : args.value}),
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
|
subjects.raise_for_status()
|
||||||
|
isUsername = True
|
||||||
|
except requests.exceptions.RequestException as errex:
|
||||||
|
logger.error("Username doesn't exist.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if isPerm:
|
||||||
|
try:
|
||||||
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/perm/add/' + args.value,
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
|
req.raise_for_status()
|
||||||
|
except requests.exceptions.RequestException as errex:
|
||||||
|
logger.error("Failed to obtain response from server.")
|
||||||
|
sys.exit(-1)
|
||||||
|
elif isUsername:
|
||||||
|
try:
|
||||||
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/user/add/' + args.value,
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
|
req.raise_for_status()
|
||||||
|
except requests.exceptions.RequestException as errex:
|
||||||
|
logger.error("Failed to obtain response from server.")
|
||||||
|
sys.exit(-1)
|
||||||
|
else:
|
||||||
|
logger.error("Invalid permission or username.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
req = req.json()
|
||||||
|
|
||||||
|
# TODO: print response
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
addPermission(sys.argv[1:])
|
addPermission(sys.argv[1:])
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role
|
#session file - role
|
||||||
|
# add_role: adds/creates a role in the current organization
|
||||||
def addRole(args):
|
def addRole(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ def addRole(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -48,7 +49,9 @@ def addRole(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/create/',
|
||||||
|
json=json.dumps({'role' : args.role}),
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -36,8 +36,9 @@ def assumeRole(args):
|
||||||
|
|
||||||
#Validate role name
|
#Validate role name
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ def assumeRole(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/assume/' + args.role, headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -42,7 +42,7 @@ def decryptFile(args):
|
||||||
print(args.metadata)
|
print(args.metadata)
|
||||||
metadata = json.loads(args.metadata)
|
metadata = json.loads(args.metadata)
|
||||||
|
|
||||||
content = symmetric_encryption.decrypt_file(metadata['nonce'].encode(), metadata['key'].encode(), BASE_DIR + args.encrypted)
|
content = symmetric_encryption.decrypt_file(metadata['key'].encode(), BASE_DIR + args.encrypted, 'file.txt')
|
||||||
|
|
||||||
# Send decrypted content to stdout
|
# Send decrypted content to stdout
|
||||||
sys.stdout.write(content)
|
sys.stdout.write(content)
|
||||||
|
|
|
@ -37,7 +37,7 @@ def dropRole(args):
|
||||||
#Validate role name
|
#Validate role name
|
||||||
#TODO
|
#TODO
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ def dropRole(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/drop/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - permission
|
#session file - permission
|
||||||
|
# list_permission_roles: lists the roles that have a specific permission in the current organization
|
||||||
def listPermissionRoles(args):
|
def listPermissionRoles(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ def listPermissionRoles(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def listPermissionRoles(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.get(f'http://{state['REP_ADDRESS']}/role/perm/' + args.permission + '/roles', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role
|
#session file - role
|
||||||
|
# list_role_permissions: lists the permissions of a role in the current organization
|
||||||
def listRolePermissions(args):
|
def listRolePermissions(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ def listRolePermissions(args):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ def listRolePermissions(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/perms', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role
|
#session file - role
|
||||||
|
# list_role_subjects: lists the subjects that have a specific role in the current organization
|
||||||
def listRoleSubjects(args):
|
def listRoleSubjects(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ def listRoleSubjects(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def listRoleSubjects(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/users', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role
|
#session file - role
|
||||||
|
# list_roles: lists the roles of the current session
|
||||||
def listRoles(args):
|
def listRoles(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ def listRoles(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def listRoles(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - username
|
#session file - username
|
||||||
|
# list_subject_roles: lists the roles of someone in the current organization
|
||||||
def listSubjectRoles(args):
|
def listSubjectRoles(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ def listSubjectRoles(args):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ def listSubjectRoles(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.get(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/roles', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role
|
#session file - role
|
||||||
|
# reactivate_role: reactivates a role in the current organization
|
||||||
def reactivateRole(args):
|
def reactivateRole(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ def reactivateRole(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def reactivateRole(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/activate', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
|
@ -26,12 +26,12 @@ def removePermission(args):
|
||||||
|
|
||||||
parser.add_argument('session', nargs='?', default=None)
|
parser.add_argument('session', nargs='?', default=None)
|
||||||
parser.add_argument('role', nargs='?',default=None)
|
parser.add_argument('role', nargs='?',default=None)
|
||||||
parser.add_argument('permission', nargs='?',default=None)
|
parser.add_argument('value', nargs='?',default=None)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
#Check number of arguments
|
#Check number of arguments
|
||||||
if not args.session or not args.role or not args.permission:
|
if not args.session or not args.role or not args.value:
|
||||||
logger.error("Need session file and role.")
|
logger.error("Need session file and role.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ def removePermission(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -47,13 +47,48 @@ def removePermission(args):
|
||||||
with open(BASE_DIR + args.session, 'r') as f:
|
with open(BASE_DIR + args.session, 'r') as f:
|
||||||
args.session = json.load(f)
|
args.session = json.load(f)
|
||||||
|
|
||||||
# TODO:
|
|
||||||
try:
|
isPerm = False; isUsername = False
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
|
||||||
req.raise_for_status()
|
# query for permission
|
||||||
except requests.exceptions.RequestException as errex:
|
if args.value in ['ROLE_ACL', 'SUBJECT_NEW', 'SUBJECT_DOWN', 'SUBJECT_UP', 'DOC_NEW']:
|
||||||
logger.error("Failed to obtain response from server.")
|
isPerm = True
|
||||||
sys.exit(-1)
|
else:
|
||||||
|
try:
|
||||||
|
subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list',
|
||||||
|
json=json.dumps({'username' : args.value}),
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
|
subjects.raise_for_status()
|
||||||
|
isUsername = True
|
||||||
|
except requests.exceptions.RequestException as errex:
|
||||||
|
logger.error("Username doesn't exist.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if isPerm:
|
||||||
|
try:
|
||||||
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/perm/remove/' + args.value,
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
|
req.raise_for_status()
|
||||||
|
except requests.exceptions.RequestException as errex:
|
||||||
|
logger.error("Failed to obtain response from server.")
|
||||||
|
sys.exit(-1)
|
||||||
|
elif isUsername:
|
||||||
|
try:
|
||||||
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/user/remove/' + args.value,
|
||||||
|
headers={'Authorization': args.session['token']})
|
||||||
|
req.raise_for_status()
|
||||||
|
except requests.exceptions.RequestException as errex:
|
||||||
|
logger.error("Failed to obtain response from server.")
|
||||||
|
sys.exit(-1)
|
||||||
|
else:
|
||||||
|
logger.error("Invalid permission or username.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# TODO: print response
|
||||||
|
|
||||||
|
req = req.json()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
removePermission(sys.argv[1:])
|
removePermission(sys.argv[1:])
|
|
@ -17,6 +17,7 @@ state = main(sys.argv)
|
||||||
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/')
|
||||||
|
|
||||||
#session file - role
|
#session file - role
|
||||||
|
# suspend_role: suspends a role in the current organization
|
||||||
def suspendRole(args):
|
def suspendRole(args):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ def suspendRole(args):
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
# Check for session file
|
# Check for session file
|
||||||
if (not os.path.isfile(BASE_DIR + args.session)):
|
if not os.path.isfile(BASE_DIR + args.session):
|
||||||
logger.error("File '" + args.session + "' not found.")
|
logger.error("File '" + args.session + "' not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def suspendRole(args):
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/suspend', headers={'Authorization': args.session['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server.")
|
logger.error("Failed to obtain response from server.")
|
||||||
|
|
Loading…
Reference in New Issue