-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move API endpoints from the config file to the code #118
Conversation
dc931f8
to
c9f3c8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to move this from the config? I thought we found it elegant that when the name of an API in molgenis is changed, it can still be used, unless functionality of the API was changed of course.
aa210ef
to
0d8f4c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect most encoding issues could be prevented by using the MOLGENIS Python API client.
|
||
@endpoint | ||
def member(group_name): | ||
return 'api/plugin/security/group/{}/member/'.format(group_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group_name
should be encoded (something like https://stackoverflow.com/a/6431284)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tommydeboer group name should still be encoded?
mcmd/commands/delete.py
Outdated
@@ -98,15 +98,15 @@ def _delete_package_contents(args): | |||
|
|||
def _delete_entity_types_in_package(package_id): | |||
response = client.get( | |||
config.api('rest2') + ResourceType.ENTITY_TYPE.get_entity_id() + '?attrs=id&q=package==' + package_id) | |||
api.rest2() + ResourceType.ENTITY_TYPE.get_entity_id() + '?attrs=id&q=package==' + package_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package_id
should be RSQL encoded (as described in https://github.com/jirutka/rsql-parser)package_id
should be encoded (something like https://stackoverflow.com/a/51649797)
mcmd/commands/delete.py
Outdated
entity_ids = [entity_type['id'] for entity_type in response.json()['items']] | ||
if len(entity_ids) > 0: | ||
_delete_rows(ResourceType.ENTITY_TYPE.get_entity_id(), entity_ids) | ||
|
||
|
||
def _delete_packages_in_package(package_id): | ||
response = client.get( | ||
config.api('rest2') + ResourceType.PACKAGE.get_entity_id() + '?attrs=id&q=parent==' + package_id) | ||
api.rest2() + ResourceType.PACKAGE.get_entity_id() + '?attrs=id&q=parent==' + package_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see previous comment on encoding
mcmd/commands/delete.py
Outdated
|
||
|
||
def _delete_rows(entity_type, rows): | ||
url = '{}{}'.format(config.api('rest2'), entity_type) | ||
url = '{}{}'.format(api.rest2(), entity_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entity_type
needs to be encoded
mcmd/commands/set.py
Outdated
@@ -66,7 +66,7 @@ def set_(args): | |||
io.start( | |||
'Updating {} of {} settings to {}'.format(highlight(args.setting), highlight(args.type), highlight(args.value))) | |||
row = _get_row_id(entity) | |||
url = '{}{}/{}/{}'.format(config.api('rest1'), entity, row, args.setting) | |||
url = '{}{}/{}/{}'.format(api.rest1(), entity, row, args.setting) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL components should be encoded
mcmd/utils/resources.py
Outdated
@@ -53,14 +53,14 @@ def detect_resource_type(resource_id, types: List[ResourceType]): | |||
def resource_exists(resource_id, resource_type): | |||
log.debug('Checking if %s %s exists' % (resource_type.get_label(), resource_id)) | |||
query = '?q={}=={}'.format(resource_type.get_identifying_attribute(), resource_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encoding issues (see previous comments)
mcmd/utils/resources.py
Outdated
@@ -53,14 +53,14 @@ def detect_resource_type(resource_id, types: List[ResourceType]): | |||
def resource_exists(resource_id, resource_type): | |||
log.debug('Checking if %s %s exists' % (resource_type.get_label(), resource_id)) | |||
query = '?q={}=={}'.format(resource_type.get_identifying_attribute(), resource_id) | |||
response = get(config.api('rest2') + resource_type.get_entity_id() + query) | |||
response = get(api.rest2() + resource_type.get_entity_id() + query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource_type.get_entity_id()
should be encoded
mcmd/utils/resources.py
Outdated
@@ -53,14 +53,14 @@ def detect_resource_type(resource_id, types: List[ResourceType]): | |||
def resource_exists(resource_id, resource_type): | |||
log.debug('Checking if %s %s exists' % (resource_type.get_label(), resource_id)) | |||
query = '?q={}=={}'.format(resource_type.get_identifying_attribute(), resource_id) | |||
response = get(config.api('rest2') + resource_type.get_entity_id() + query) | |||
response = get(api.rest2() + resource_type.get_entity_id() + query) | |||
return int(response.json()['total']) > 0 | |||
|
|||
|
|||
def one_resource_exists(resources, resource_type): | |||
log.debug('Checking if one of [{}] exists in [{}]'.format(','.join(resources), resource_type.get_label())) | |||
query = '?q={}=in=({})'.format(resource_type.get_identifying_attribute(), ','.join(resources)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encoded issues (see previous comments)
mcmd/utils/resources.py
Outdated
return int(response.json()['total']) > 0 | ||
|
||
|
||
def one_resource_exists(resources, resource_type): | ||
log.debug('Checking if one of [{}] exists in [{}]'.format(','.join(resources), resource_type.get_label())) | ||
query = '?q={}=in=({})'.format(resource_type.get_identifying_attribute(), ','.join(resources)) | ||
response = get(config.api('rest2') + resource_type.get_entity_id() + query) | ||
response = get(api.rest2() + resource_type.get_entity_id() + query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encoding issues (see previous comments)
@tommydeboer could you address the comment of @marikaris? |
Moving the location of these strings to the code makes it easier to switch between them based on versions (see #119). If we would want to do this in the config we would have to invent new keys for each endpoint ( |
We're not using the Python client (yet), because:
I think we can fix the encoding issues in the |
@tommydeboer |
@dennishendriksen @marikaris |
@dennishendriksen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few comments, no sure if you should do something with it.
|
||
@endpoint | ||
def member(group_name): | ||
return 'api/plugin/security/group/{}/member/'.format(group_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tommydeboer group name should still be encoded?
|
||
|
||
@command | ||
def add_token(args): | ||
io.start('Adding token %s for user %s' % (highlight(args.token), highlight(args.user))) | ||
|
||
user = get(config.api('rest2') + 'sys_sec_User?attrs=id&q=username==%s' % args.user) | ||
user = get(api.rest2('sys_sec_User'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want this tablename hardcoded here?
@@ -173,7 +178,7 @@ def add_token(args): | |||
data = {'User': user_id, | |||
'token': args.token} | |||
|
|||
post(config.api('rest1') + 'sys_sec_Token', data) | |||
post(api.rest1('sys_sec_Token'), data=data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want this tablename hardcoded here?
|
||
|
||
def _find_group(role): | ||
io.debug('Fetching groups') | ||
groups = get(config.api('rest2') + 'sys_sec_Group?attrs=name') | ||
groups = get(api.rest2('sys_sec_Group'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this table name hardcoded here?
query = 'q=extends==sys_set_settings&attrs=~id' | ||
molgenis_settings = _quick_get(entity, query) | ||
molgenis_settings = get(api.rest2('sys_md_EntityType'), | ||
params={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a hardcoded table name?
return int(response.json()['total']) > 0 | ||
|
||
|
||
def role_exists(rolename): | ||
log.debug('Checking if role %s exists' % rolename) | ||
response = get(config.api('rest2') + 'sys_sec_Role?q=name==' + rolename.upper()) | ||
response = get(api.rest2('sys_sec_Role'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded tablename
@@ -30,13 +30,20 @@ def principal_exists(principal_name, principal_type): | |||
|
|||
def user_exists(username): | |||
log.debug('Checking if user %s exists' % username) | |||
response = get(config.api('rest2') + 'sys_sec_User?q=username==' + username) | |||
response = get(api.rest2('sys_sec_User'), | |||
params={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcoded tablename
Depends on: #117 Error when the config contains (old) unknown properties
This PR is a preparation for the compatibility framework
After this PR you can no longer override the API endpoints in the config file, so running integration tests against a MOLGENIS 8 will cause some tests (involving groups) to fail.
Checklist