[ARVADOS] created: a95f899d7ac84f29b3d019aa410d265bb40833e5
Git user
git at public.curoverse.com
Wed Jun 8 10:04:40 EDT 2016
at a95f899d7ac84f29b3d019aa410d265bb40833e5 (commit)
commit a95f899d7ac84f29b3d019aa410d265bb40833e5
Merge: 252a5f7 8630c54
Author: radhika <radhika at curoverse.com>
Date: Wed Jun 8 07:23:19 2016 -0400
Merge branch 'master' into wtsi-hgi-8087-arv-cli-request-body-from-file
commit 252a5f7f290567f7cbcc9897a879c0a7ebe64e90
Merge: fe3f19b 7afa73a
Author: radhika <radhika at curoverse.com>
Date: Wed Jun 8 07:19:36 2016 -0400
Merge branch '8087-arv-cli-request-body-from-file' of https://github.com/wtsi-hgi/arvados into wtsi-hgi-8087-arv-cli-request-body-from-file
commit 7afa73aff577d3c2c066c21586a44a94c8731710
Author: Joshua Randall <joshua.randall at sanger.ac.uk>
Date: Mon Apr 4 14:08:17 2016 +0100
8087: makes changes suggested by radhika
untested
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index da65b07..10a9d43 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -559,11 +559,11 @@ def parse_arguments(discovery_document, subcommands)
if body_object["required"] == false
is_required = false
end
- _resource_opt_desc = "Either a string representing #{resource} as JSON or a filename from which to read #{resource} JSON (use '-' to read from stdin)."
+ resource_opt_desc = "Either a string representing #{resource} as JSON or a filename from which to read #{resource} JSON (use '-' to read from stdin)."
if is_required
- _resource_opt_desc += " This option must be specified."
+ resource_opt_desc += " This option must be specified."
end
- opt resource.to_sym, _resource_opt_desc, {
+ opt resource.to_sym, resource_opt_desc, {
required: is_required,
type: :string
}
@@ -630,36 +630,43 @@ request_parameters = {_profile:true}.merge(method_opts)
resource_body = request_parameters.delete(resource_schema.to_sym)
if resource_body
# check if resource_body is valid JSON by attempting to parse it
- _is_json = true
+ resource_body_is_json = true
begin
- # we don't actually need the results of the parsing,
+ # we don't actually need the results of the parsing,
# just checking for the JSON::ParserError exception
JSON.parse resource_body
rescue JSON::ParserError => e
- _is_json = false
+ resource_body_is_json = false
end
- _is_readable_file = false
+ resource_body_is_readable_file = false
# if resource_body is not valid JSON, it should be a filename (or '-' for stdin)
if resource_body == '-'
- _is_readable_file = true
- _resource_body_file = $stdin
+ resource_body_is_readable_file = true
+ resource_body_file = $stdin
elsif File.readable? resource_body
- _is_readable_file = true
- _resource_body_file = File.open(resource_body, 'r')
+ resource_body_is_readable_file = true
+ resource_body_file = File.open(resource_body, 'r')
end
- if _is_json and _is_readable_file
- abort "Argument '#{resource_body}' specified for option '--#{resource_schema.to_sym}' is both valid JSON and a readable file, cannot continue (suggest renaming the file '#{resource_body}')."
- elsif !_is_json and !_is_readable_file
+ if resource_body_is_json and resource_body_is_readable_file
+ abort "Argument specified for option '--#{resource_schema.to_sym}' is both valid JSON and a readable file. Please consider renaming the file: '#{resource_body}'"
+ elsif !resource_body_is_json and !resource_body_is_readable_file
if File.exists? resource_body
# specified file exists but is not readable
- abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' exists but is not readable."
+ abort "Argument specified for option '--#{resource_schema.to_sym}' is an existing file but is not readable. Please check permissions on: '#{resource_body}'"
else
# specified file does not exist
- abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' does not exist."
+ abort "Argument specified for option '--#{resource_schema.to_sym}' is neither valid JSON nor an existing file: '#{resource_body}'"
end
- elsif _is_readable_file
- resource_body = _resource_body_file.read()
- _resource_body_file.close()
+ elsif resource_body_is_readable_file
+ resource_body = resource_body_file.read()
+ begin
+ # we don't actually need the results of the parsing,
+ # just checking for the JSON::ParserError exception
+ JSON.parse resource_body
+ rescue JSON::ParserError => e
+ abort "Contents of file '#{resource_body_file.path}' is not valid JSON: #{e}"
+ end
+ resource_body_file.close()
end
request_body = {
resource_schema => resource_body
commit fe3f19bb8f0a684de9c5a7d1f7c619943d0daca0
Merge: 5768e5a ae3a047
Author: radhika <radhika at curoverse.com>
Date: Thu Mar 17 13:14:52 2016 -0400
Merge branch '8087-arv-cli-request-body-from-file' of https://github.com/wtsi-hgi/arvados into wtsi-hgi-8087-arv-cli-request-body-from-file
commit ae3a047bed172be701e3d2aa2d566e9800552d85
Author: Joshua C. Randall <jcrandall at alum.mit.edu>
Date: Tue Feb 23 15:26:56 2016 +0000
Adds checking for request body options that are both valid JSON and readable files
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index b91d137..da65b07 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -638,23 +638,26 @@ if resource_body
rescue JSON::ParserError => e
_is_json = false
end
- if !_is_json
- # if resource_body is not valid JSON, it should be a filename (or '-' for stdin)
- if resource_body == '-'
- _resource_body_file = $stdin
+ _is_readable_file = false
+ # if resource_body is not valid JSON, it should be a filename (or '-' for stdin)
+ if resource_body == '-'
+ _is_readable_file = true
+ _resource_body_file = $stdin
+ elsif File.readable? resource_body
+ _is_readable_file = true
+ _resource_body_file = File.open(resource_body, 'r')
+ end
+ if _is_json and _is_readable_file
+ abort "Argument '#{resource_body}' specified for option '--#{resource_schema.to_sym}' is both valid JSON and a readable file, cannot continue (suggest renaming the file '#{resource_body}')."
+ elsif !_is_json and !_is_readable_file
+ if File.exists? resource_body
+ # specified file exists but is not readable
+ abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' exists but is not readable."
else
- if File.readable? resource_body
- _resource_body_file = File.open(resource_body, 'r')
- else
- if File.exists? resource_body
- # specified file exists but is not readable
- abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' exists but is not readable."
- else
- # specified file does not exist
- abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' does not exist."
- end
- end
+ # specified file does not exist
+ abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' does not exist."
end
+ elsif _is_readable_file
resource_body = _resource_body_file.read()
_resource_body_file.close()
end
commit 212fa4898c594211217444b20ef629157813bc4a
Author: Joshua C. Randall <jcrandall at alum.mit.edu>
Date: Mon Feb 22 22:20:48 2016 +0000
Adds better error reporting for problems with request body file
Reports clear error messages if the specified file does not
exist or is not readable.
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 6811a44..b91d137 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -643,7 +643,17 @@ if resource_body
if resource_body == '-'
_resource_body_file = $stdin
else
- _resource_body_file = File.open(resource_body, 'r')
+ if File.readable? resource_body
+ _resource_body_file = File.open(resource_body, 'r')
+ else
+ if File.exists? resource_body
+ # specified file exists but is not readable
+ abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' exists but is not readable."
+ else
+ # specified file does not exist
+ abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' does not exist."
+ end
+ end
end
resource_body = _resource_body_file.read()
_resource_body_file.close()
commit f6400fca6dc60055b613b0e3dc3c8422b7af6391
Author: Joshua Randall <joshua.randall at sanger.ac.uk>
Date: Mon Feb 22 21:30:09 2016 +0000
8087: implements reading of request body from file
Attempts to parse the provided request body value as JSON. If
JSON parsing fails, assume it is a filename (or '-' for stdin)
and read the request body from that file instead.
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 185a5b0..6811a44 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -559,7 +559,11 @@ def parse_arguments(discovery_document, subcommands)
if body_object["required"] == false
is_required = false
end
- opt resource.to_sym, "#{resource} (request body)", {
+ _resource_opt_desc = "Either a string representing #{resource} as JSON or a filename from which to read #{resource} JSON (use '-' to read from stdin)."
+ if is_required
+ _resource_opt_desc += " This option must be specified."
+ end
+ opt resource.to_sym, _resource_opt_desc, {
required: is_required,
type: :string
}
@@ -625,6 +629,25 @@ end
request_parameters = {_profile:true}.merge(method_opts)
resource_body = request_parameters.delete(resource_schema.to_sym)
if resource_body
+ # check if resource_body is valid JSON by attempting to parse it
+ _is_json = true
+ begin
+ # we don't actually need the results of the parsing,
+ # just checking for the JSON::ParserError exception
+ JSON.parse resource_body
+ rescue JSON::ParserError => e
+ _is_json = false
+ end
+ if !_is_json
+ # if resource_body is not valid JSON, it should be a filename (or '-' for stdin)
+ if resource_body == '-'
+ _resource_body_file = $stdin
+ else
+ _resource_body_file = File.open(resource_body, 'r')
+ end
+ resource_body = _resource_body_file.read()
+ _resource_body_file.close()
+ end
request_body = {
resource_schema => resource_body
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list