Commit 56e43279 authored by redmitry@list.ru's avatar redmitry@list.ru

use regular user instead of the KC 'admin'.

parent abbdb6ba
......@@ -6,18 +6,24 @@ import urllib.request
import urllib.parse
OPENEBENCH_URL = "https://dev-openebench.bsc.es/api/scientific/access"
KEYCLOAK_TOKEN_ENDPOINT = "https://inb.bsc.es/auth/realms/master/protocol/openid-connect/token"
KEYCLOAK_TOKEN_ENDPOINT = "https://inb.bsc.es/auth/realms/openebench/protocol/openid-connect/token"
KEYCLOAK_OPENEBENCH_REALM = "https://inb.bsc.es/auth/admin/realms/openebench/"
def main():
if (len(sys.argv) > 1):
password = sys.argv[1]
username = sys.argv[1]
else:
print('username:', end = ' ')
username = str(input())
if (len(sys.argv) > 2):
password = sys.argv[2]
else:
print('password:', end = ' ')
password = str(input())
token = getAdminToken('admin', password)
token = getAdminToken(username, password)
headers = {'Authorization' : 'Bearer ' + token}
updateCommunities(headers)
......@@ -35,7 +41,7 @@ def updateCommunities(headers):
# update existing communities
for group in groups[:]:
attributes = group['attributes']
roles = attributes.get('roles')
roles = attributes.get('oeb:roles')
if (roles != None):
for role in roles:
if (role.startswith('owner:')):
......@@ -52,7 +58,7 @@ def updateCommunities(headers):
group = {}
group['name'] = community['name']
#group['attributes'] = {'community_id' : [community['_id']], 'acronym' : [community['acronym']]}
group['attributes'] = {'roles' : ['owner:' + community['_id']], 'acronym' : [community['acronym']]}
group['attributes'] = {'oeb:roles' : ['owner:' + community['_id']], 'acronym' : [community['acronym']]}
addCommunityGroup(root, group, headers)
#remove old communities
......@@ -77,7 +83,7 @@ def updatePrivileges(headers):
if (email == user['email']):
for privilege in privileges:
if (privilege['_id'] == contact['_id']):
roles = privilege.get('roles')
roles = privilege.get('oeb:roles')
if (roles != None):
for role in roles:
community_id = role.get('community_id')
......@@ -96,7 +102,7 @@ def addContactToCommunity(groups, user, community_id, headers):
for group in groups:
attributes = group['attributes']
roles = attributes.get('roles')
roles = attributes.get('oeb:roles')
if (roles != None):
for role in roles:
if (role.startswith('owner:') and community_id == role[6:]):
......@@ -109,10 +115,10 @@ def addContactToChallenge(user, role, challenge_id, headers):
r = role + ':' + challenge_id
attributes = user['attributes']
rz = attributes.get('roles')
rz = attributes.get('oeb:roles')
if (rz == None):
attributes['roles'] = [r]
attributes['oeb:roles'] = [r]
updateKeycloakUser(user, headers)
elif (not r in rz):
rz.append(r)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment