Skip to content
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

REST API: make the profile configurable as request parameter #5054

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aiida/cmdline/commands/cmd_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
help='Enable POST endpoints (currently only /querybuilder).',
hidden=True,
)
def restapi(hostname, port, config_dir, debug, wsgi_profile, posting):
@click.pass_context
def restapi(ctx, hostname, port, config_dir, debug, wsgi_profile, posting):
"""
Run the AiiDA REST API server.

Expand All @@ -58,6 +59,7 @@ def restapi(hostname, port, config_dir, debug, wsgi_profile, posting):
# Invoke the runner
try:
run_api(
profile=ctx.obj['profile'].name,
hostname=hostname,
port=port,
config=config_dir,
Expand Down
8 changes: 7 additions & 1 deletion aiida/manage/configuration/schema/config-v9.schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"description": "Schema for AiiDA configuration files, format version 8",
"description": "Schema for AiiDA configuration files, format version 9",
"type": "object",
"definitions": {
"options": {
Expand Down Expand Up @@ -124,6 +124,12 @@
"minimum": 1,
"description": "Maximum number of transport task attempts before a Process is Paused."
},
"rest_api.profile_switching": {
"type": "boolean",
"default": false,
"description": "Toggle whether the profile can be specified in requests submitted to the REST API",
"global_only": true
},
"rmq.task_timeout": {
"type": "integer",
"default": 10,
Expand Down
14 changes: 11 additions & 3 deletions aiida/restapi/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def build_translator_parameters(self, field_list):
extras = None
extras_filter = None
full_type = None
profile = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_profile(None) defaults to loading the default profile.

I think the correct default here would be the profile that was used in
verdi -p profile restapi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have kept this as is, because this is just the parsing of the query parameters and I don't think that should be bothered with determining the default profile. This is now instead handled in BaseResource.load_profile which knows what default to use if not specified in the query parameters.


# io tree limit parameters
tree_in_limit = None
Expand Down Expand Up @@ -539,10 +540,17 @@ def build_translator_parameters(self, field_list):
raise RestInputValidationError('You cannot specify extras_filter more than once')
if 'full_type' in field_counts and field_counts['full_type'] > 1:
raise RestInputValidationError('You cannot specify full_type more than once')
if 'profile' in field_counts and field_counts['profile'] > 1:
raise RestInputValidationError('You cannot specify profile more than once')

## Extract results
for field in field_list:
if field[0] == 'limit':
if field[0] == 'profile':
if field[1] == '=':
profile = field[2]
else:
raise RestInputValidationError("only assignment operator '=' is permitted after 'profile'")
elif field[0] == 'limit':
if field[1] == '=':
limit = field[2]
else:
Expand Down Expand Up @@ -658,7 +666,7 @@ def build_translator_parameters(self, field_list):

return (
limit, offset, perpage, orderby, filters, download_format, download, filename, tree_in_limit,
tree_out_limit, attributes, attributes_filter, extras, extras_filter, full_type
tree_out_limit, attributes, attributes_filter, extras, extras_filter, full_type, profile
)

def parse_query_string(self, query_string):
Expand All @@ -680,7 +688,7 @@ def parse_query_string(self, query_string):

## Define grammar
# key types
key = Word(f'{alphas}_', f'{alphanums}_')
key = Word(f'{alphas}_', f'{alphanums}_-')
# operators
operator = (
Literal('=like=') | Literal('=ilike=') | Literal('=in=') | Literal('=notin=') | Literal('=') |
Expand Down
Loading