Skip to content

Commit

Permalink
config: addition of ERROR_MESSAGES dict
Browse files Browse the repository at this point in the history
* ADD ERROR_MESSAGES dictionary to contain cli user facing
  error messages. Currently groups all missing access token
  messages.

Signed-off-by: Dinos Kousidis <dinos.kousidis@cern.ch>
  • Loading branch information
dinosk committed Jul 18, 2018
1 parent b2e0537 commit ea4d079
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 65 deletions.
8 changes: 5 additions & 3 deletions reana_client/api/client.py
Expand Up @@ -119,9 +119,11 @@ def get_workflow_status(self, organization, workflow, access_token):
"""Get status of previously created workflow."""
try:
response, http_response = self.\
_client.api.get_workflow_status(organization=organization,
workflow_id_or_name=workflow,
access_token=access_token).result()
_client.api.get_workflow_status(
organization=organization,
workflow_id_or_name=workflow,
access_token=access_token)\
.result()
if http_response.status_code == 200:
return response
else:
Expand Down
18 changes: 8 additions & 10 deletions reana_client/cli/code.py
Expand Up @@ -31,7 +31,7 @@

from ..errors import FileUploadError
from ..api.client import UploadType
from ..config import default_organization
from ..config import ERROR_MESSAGES, default_organization
from reana_commons.utils import click_table_printer


Expand Down Expand Up @@ -82,9 +82,8 @@ def code_list(ctx, organization, workflow, _filter,

if not access_token:
click.echo(
click.style('Please provide your API access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -at/--access-token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)

if workflow:
try:
Expand Down Expand Up @@ -152,17 +151,16 @@ def code_list(ctx, organization, workflow, _filter,
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def code_upload(ctx, organization, workflow, filenames, token):
def code_upload(ctx, organization, workflow, filenames, access_token):
"""Upload code file(s) to workflow workspace. Associate with a workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)

if workflow:
for filename in filenames:
Expand All @@ -172,7 +170,7 @@ def code_upload(ctx, organization, workflow, filenames, token):
workflow,
filename,
UploadType.code,
token)
access_token)
if type(response) is list:
for _filename in response:
click.echo(
Expand Down
25 changes: 12 additions & 13 deletions reana_client/cli/inputs.py
Expand Up @@ -29,7 +29,7 @@
import click
import tablib

from ..config import default_organization, default_user
from ..config import ERROR_MESSAGES, default_organization, default_user
from ..errors import FileUploadError
from ..api.client import UploadType
from reana_commons.utils import click_table_printer
Expand Down Expand Up @@ -74,23 +74,23 @@ def inputs(ctx):
help='Access token of the current user.')
@click.pass_context
def inputs_list(ctx, organization, workflow, _filter,
output_format, token):
output_format, access_token):
"""List input files of a workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
try:
response = ctx.obj.client.get_workflow_inputs(organization,
workflow, token)
workflow,
access_token)
headers = ['name', 'size', 'last-modified']
data = []
for file_ in response:
Expand Down Expand Up @@ -153,17 +153,16 @@ def inputs_list(ctx, organization, workflow, _filter,
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def inputs_upload(ctx, organization, workflow, filenames, token):
def inputs_upload(ctx, organization, workflow, filenames, access_token):
"""Upload input file(s) to workflow workspace.Associate with a workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
Expand All @@ -174,7 +173,7 @@ def inputs_upload(ctx, organization, workflow, filenames, token):
workflow,
filename,
UploadType.inputs,
token)
access_token)
if response:
click.echo(
click.style('File {} was successfully uploaded.'.
Expand Down
23 changes: 11 additions & 12 deletions reana_client/cli/outputs.py
Expand Up @@ -74,23 +74,23 @@ def outputs(ctx):
help='Access token of the current user.')
@click.pass_context
def outputs_list(ctx, organization, workflow, _filter,
output_format, token):
output_format, access_token):
"""List files a workflow has outputted."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)
if workflow:
logging.info('Workflow "{}" selected'.format(workflow))
try:
response = ctx.obj.client.get_workflow_outputs(organization,
workflow, token)
workflow,
access_token)
headers = ['name', 'size', 'last-modified']
data = []
for file_ in response:
Expand Down Expand Up @@ -159,17 +159,16 @@ def outputs_list(ctx, organization, workflow, _filter,
help='Access token of the current user.')
@click.pass_context
def outputs_download(ctx, organization, workflow, file_,
output_directory, token):
output_directory, access_token):
"""Download file(s) workflow has outputted."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
Expand All @@ -179,7 +178,7 @@ def outputs_download(ctx, organization, workflow, file_,
ctx.obj.client.download_workflow_output_file(organization,
workflow,
file_name,
token)
access_token)
logging.info('{0} binary file downloaded ... writing to {1}'.
format(file_name, output_directory))

Expand Down
52 changes: 25 additions & 27 deletions reana_client/cli/workflow.py
Expand Up @@ -32,7 +32,8 @@
import tablib
import yaml

from ..config import default_organization, reana_yaml_default_file_path
from ..config import ERROR_MESSAGES, default_organization, \
reana_yaml_default_file_path
from ..utils import get_workflow_name_and_run_number, load_reana_spec, \
load_workflow_spec, is_uuid_v4, workflow_uuid_or_name
from reana_commons.utils import click_table_printer
Expand Down Expand Up @@ -83,21 +84,21 @@ def workflow(ctx):
count=True,
help='Set status information verbosity.')
@click.pass_context
def workflow_list(ctx, organization, _filter, output_format, token, verbose):
def workflow_list(ctx, organization, _filter, output_format, access_token,
verbose):
"""List all workflows user has."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

try:
response = ctx.obj.client.get_all_workflows(organization, token)
response = ctx.obj.client.get_all_workflows(organization, access_token)
verbose_headers = ['id', 'user', 'organization']
headers = ['name', 'run_number', 'created', 'status']
if verbose:
Expand Down Expand Up @@ -179,7 +180,7 @@ def workflow_list(ctx, organization, _filter, output_format, token, verbose):
help='Access token of the current user.')
@click.pass_context
def workflow_create(ctx, file, name, organization,
skip_validation, token):
skip_validation, access_token):
"""Create a REANA compatible workflow from REANA spec file."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
Expand All @@ -192,11 +193,10 @@ def workflow_create(ctx, file, name, organization,
click.echo(
click.style('Workflow name cannot be a valid UUIDv4', fg='red'),
err=True)
if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)
try:
reana_spec = load_reana_spec(click.format_filename(file),
Expand All @@ -220,7 +220,7 @@ def workflow_create(ctx, file, name, organization,
response = ctx.obj.client.create_workflow(organization,
reana_spec,
name,
token)
access_token)
click.echo(click.style(response['workflow_name'], fg='green'))

except Exception as e:
Expand Down Expand Up @@ -253,25 +253,24 @@ def workflow_create(ctx, file, name, organization,
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def workflow_start(ctx, organization, workflow, token):
def workflow_start(ctx, organization, workflow, access_token):
"""Start previously created workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
try:
logging.info('Connecting to {0}'.format(ctx.obj.client.server_url))
response = ctx.obj.client.start_workflow(organization,
workflow,
token)
access_token)
click.echo(
click.style('{} has been started.'.format(workflow),
fg='green'))
Expand Down Expand Up @@ -330,24 +329,23 @@ def workflow_start(ctx, organization, workflow, token):
help='Set status information verbosity.')
@click.pass_context
def workflow_status(ctx, organization, workflow, _filter, output_format,
token, verbose):
access_token, verbose):
"""Get status of previously created workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not token:
if not access_token:
click.echo(
click.style('Please provide your access token, either by setting the'
' REANA_ACCESS_TOKEN environment variable, or by using'
' the -t/--token flag.', fg='red'), err=True)
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
try:
response = ctx.obj.client.get_workflow_status(organization,
workflow,
token)
access_token)
verbose_headers = ['id', 'user', 'organization']
headers = ['name', 'run_number', 'created',
'status', 'progress', 'command']
Expand Down Expand Up @@ -454,7 +452,7 @@ def workflow_status(ctx, organization, workflow, _filter, output_format,
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.pass_context
def workflow_logs(ctx, organization, workflow, token):
def workflow_logs(ctx, organization, workflow, access_token):
"""Get status of previously created workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
Expand All @@ -463,7 +461,7 @@ def workflow_logs(ctx, organization, workflow, token):
if workflow:
try:
response = ctx.obj.client.get_workflow_logs(organization,
workflow, token)
workflow, access_token)
click.echo(response)
except Exception as e:
logging.debug(traceback.format_exc())
Expand Down
7 changes: 7 additions & 0 deletions reana_client/config.py
Expand Up @@ -39,3 +39,10 @@

default_download_path = './outputs/'
"""Default path where files outputted by a workflow will be downloaded."""

ERROR_MESSAGES = {
'missing_access_token':
'Please provide your access token by using'
' the -at/--access-token flag, or by setting the'
' REANA_ACCESS_TOKEN environment variable.'
}

0 comments on commit ea4d079

Please sign in to comment.