rep_lists and drop_role
This commit is contained in:
parent
78dce9c8dc
commit
73c2b23eb9
|
@ -34,8 +34,6 @@ def dropRole(args):
|
|||
logger.error("Need session file and username.")
|
||||
sys.exit(1)
|
||||
|
||||
#Validate role name
|
||||
#TODO
|
||||
# Check for session file
|
||||
if not os.path.isfile(BASE_DIR + args.session):
|
||||
logger.error("File '" + args.session + "' not found.")
|
||||
|
@ -45,7 +43,20 @@ def dropRole(args):
|
|||
with open(BASE_DIR + args.session, 'r') as f:
|
||||
args.session = json.load(f)
|
||||
|
||||
# TODO:
|
||||
# Get roles in session
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', 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)
|
||||
|
||||
# Validate role name
|
||||
roles = req.json()
|
||||
if args.role not in roles.items():
|
||||
logger.error("Role does not exist.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
req = requests.post(f'http://{state['REP_ADDRESS']}/role/session/drop/' + args.username + '/activate', headers={'Authorization': args.session['token']})
|
||||
req.raise_for_status()
|
||||
|
@ -53,5 +64,8 @@ def dropRole(args):
|
|||
logger.error("Failed to obtain response from server.")
|
||||
sys.exit(-1)
|
||||
|
||||
logger.info("You dropped the role %s", args.role)
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
dropRole(sys.argv[1:])
|
|
@ -35,9 +35,6 @@ def listPermissionRoles(args):
|
|||
logger.error("Need session file and permission.")
|
||||
sys.exit(1)
|
||||
|
||||
#Validate permission name
|
||||
#TODO
|
||||
|
||||
# Check for session file
|
||||
if not os.path.isfile(BASE_DIR + args.session):
|
||||
logger.error("File '" + args.session + "' not found.")
|
||||
|
@ -47,7 +44,11 @@ def listPermissionRoles(args):
|
|||
with open(BASE_DIR + args.session, 'r') as f:
|
||||
args.session = json.load(f)
|
||||
|
||||
# TODO:
|
||||
#Validate permission name
|
||||
if args.permission in ['ROLE_ACL', 'SUBJECT_NEW', 'SUBJECT_DOWN', 'SUBJECT_UP', 'DOC_NEW']:
|
||||
logger.error("Permission does not exist.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/perm/' + args.permission + '/roles', headers={'Authorization': args.session['token']})
|
||||
req.raise_for_status()
|
||||
|
@ -55,5 +56,11 @@ def listPermissionRoles(args):
|
|||
logger.error("Failed to obtain response from server.")
|
||||
sys.exit(-1)
|
||||
|
||||
roles = req.json()
|
||||
for r in roles.items():
|
||||
sys.stdout.write(r)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
listPermissionRoles(sys.argv[1:])
|
|
@ -44,7 +44,20 @@ def listRolePermissions(args):
|
|||
with open(BASE_DIR + args.session, 'r') as f:
|
||||
args.session = json.load(f)
|
||||
|
||||
# TODO:
|
||||
# Get roles in session
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', 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)
|
||||
|
||||
# Validate role name
|
||||
roles = req.json()
|
||||
if args.role not in roles.items():
|
||||
logger.error("Role does not exist.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/perms', headers={'Authorization': args.session['token']})
|
||||
req.raise_for_status()
|
||||
|
@ -52,5 +65,11 @@ def listRolePermissions(args):
|
|||
logger.error("Failed to obtain response from server.")
|
||||
sys.exit(-1)
|
||||
|
||||
perms = req.json()
|
||||
for p in perms.items():
|
||||
sys.stdout.write(p)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
listRolePermissions(sys.argv[1:])
|
|
@ -35,9 +35,6 @@ def listRoleSubjects(args):
|
|||
logger.error("Need session file and role.")
|
||||
sys.exit(1)
|
||||
|
||||
#Validate role name
|
||||
#TODO
|
||||
|
||||
# Check for session file
|
||||
if not os.path.isfile(BASE_DIR + args.session):
|
||||
logger.error("File '" + args.session + "' not found.")
|
||||
|
@ -47,7 +44,20 @@ def listRoleSubjects(args):
|
|||
with open(BASE_DIR + args.session, 'r') as f:
|
||||
args.session = json.load(f)
|
||||
|
||||
# TODO:
|
||||
# Get roles in session
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', 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)
|
||||
|
||||
# Validate role name
|
||||
roles = req.json()
|
||||
if args.role not in roles.items():
|
||||
logger.error("Role does not exist.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/' + args.role + '/list/users', headers={'Authorization': args.session['token']})
|
||||
req.raise_for_status()
|
||||
|
@ -55,5 +65,11 @@ def listRoleSubjects(args):
|
|||
logger.error("Failed to obtain response from server.")
|
||||
sys.exit(-1)
|
||||
|
||||
subjects = req.json()
|
||||
for s in subjects.items():
|
||||
sys.stdout.write(s)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
listRoleSubjects(sys.argv[1:])
|
|
@ -44,7 +44,24 @@ def listSubjectRoles(args):
|
|||
with open(BASE_DIR + args.session, 'r') as f:
|
||||
args.session = json.load(f)
|
||||
|
||||
# TODO:
|
||||
# Get list of subjects
|
||||
try:
|
||||
subjects = requests.get(f'http://{state['REP_ADDRESS']}/user/list',
|
||||
json=json.dumps({}),
|
||||
headers={'Authorization': args.session['token']})
|
||||
subjects.raise_for_status()
|
||||
|
||||
except requests.exceptions.RequestException as errex:
|
||||
logger.error("Failed to obtain response from server.")
|
||||
sys.exit(-1)
|
||||
|
||||
subjects = subjects.json()
|
||||
|
||||
# Check if subject exists
|
||||
if args.username not in subjects.items():
|
||||
logger.error("Subject not found.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/user/' + args.username + '/roles', headers={'Authorization': args.session['token']})
|
||||
req.raise_for_status()
|
||||
|
|
Loading…
Reference in New Issue