Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit f01eb352 authored by fandrem's avatar fandrem
Browse files

Feature #28491 - sid_user.py script

parent e71b1167
No related branches found
No related tags found
No related merge requests found
......@@ -382,62 +382,57 @@ def sid_update_user_exlude_approver_scheduler_change_management(diego, dfqdn, re
def sid_create_update_user_approver_scheduler_change_management(diego, dfqdn, res_rw_user, user, uid, typeAdd, need_to_update, context_uid=778000000, verify=True):
create = True
results = diego.diegoGetObject(uid)
print(need_to_update)
print(results['objects'])
ty = []
ty2 = []
if 'objects' in results :
for typ in results['objects'] :
ty.append(typ['type'])
if typ['type'] == typeAdd and need_to_update :
#if is one of that create -> TODO : just support one by context!
if typ['type'] in ['approver', 'scheduler'] :
create = False
ty2 = ty
ty2.append(typeAdd)
#print(ty2)
#exit(1)
#logger.debug(results)
block_to_update = {
'name': user,
'context': context_uid,
'type': typeAdd,
'properties': {
'is a' : typeAdd
if create :
block_to_update = {
'uid': uid,
'name': user,
'context': 778000000,
"is applicable in the context of" : 778000000,
'is a specialization of' : typeAdd,
'type': typeAdd,
}
}
block_to_update = {
'uid': uid,
'name': user,
'context': context_uid,
'type': typeAdd,
'properties': {
"is a" : [{'type': 'user', 'context': 666000002}, {'type': 'approver', 'context': 778000000}, {'type' : typeAdd, 'context': 778000000}],
}
}
to_print = pformat(block_to_update)
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.info('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
''' delete: need to check the line exist if not 409'''
scrat_inst = Scrat(res_rw_user, '', fqdn=dfqdn, version=2, verify=verify)
(scrat_json, scratres) = scrat_inst.scratUpdate(block_to_update, overwrite_mode=True, line_only=True, Full=True)
#(scratres) = scrat_inst.scratQuery(block_to_update, 'creation')
if str(scratres) != '200':
to_print = pformat(block_to_update)
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.error('scrat %s creating cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.error('scrat %s creating failed: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
# print('scrat %s update failed: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
else:
to_print = pformat(block_to_update)
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.debug('scrat %s creating cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
logger.info('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
print("STOP!")
exit(1)
''' delete: need to check the line exist if not 409'''
scrat_inst = Scrat(res_rw_user, '', fqdn=dfqdn, version=2, verify=verify)
#(scrat_json, scratres) = scrat_inst.scratUpdate(block_to_update, overwrite_mode=True, line_only=True, Full=True)
(scrat_json, scratres) = scrat_inst.scratQuery(block_to_update, Full=True)
#(scrat_json, scratres) = scrat_inst.scratQuery(scratter, Full=True)
if str(scratres) != '200':
'''Scrat add new user relation in diferent context'''
to_print = pformat(block_to_update)
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.info('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
to_print = pformat(block_to_update)
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.error('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
# print('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
to_print = '%s: %s' % (str(scratres), str(scrat_json))
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.error('scrat %s update failed: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
# print('scrat %s update failed: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
else:
to_print = pformat(block_to_update)
for i in list(range(0, int(round(len(to_print) / 250)) + 1)):
logger.debug('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
# print('scrat %s update cmd: %s' % (str(i), to_print[250 * i:250 * (i + 1)]))
else :
logger.error('the ' + typeAdd + ' role. is already defined for this user')
pass
def main():
......@@ -905,9 +900,9 @@ def main():
logger.debug('SID user ' + user + ' should be addded to scheduler.')
#create the relation if not exists
if not dryrun:
#sid_create_update_user_approver_scheduler_change_management(diego, fqdn, res_rw_user, user, sid_results[1][user]['uid'], 'scheduler', need_to_update)
pass
if not dryrun or True:
sid_create_update_user_approver_scheduler_change_management(diego, fqdn, res_rw_user, user, sid_results[1][user]['uid'], 'scheduler', need_to_update)
#pass
else:
logger.error('dry run, user not add/update from the scheduler role.')
continue
......@@ -940,9 +935,9 @@ def main():
need_to_create = True
logger.debug('SID user ' + user + ' should be addded to approver.')
#create the relation if not exists
if not dryrun:
#sid_create_update_user_approver_scheduler_change_management(diego, fqdn, res_rw_user, user, sid_results[1][user]['uid'], 'approver', need_to_update)
pass
if not dryrun or True:
sid_create_update_user_approver_scheduler_change_management(diego, fqdn, res_rw_user, user, sid_results[1][user]['uid'], 'approver', need_to_update)
#pass
else:
logger.error('dry run, user not add/update from the approver role.')
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment