X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4211e34c99a068e8beb0baa6522c655c35b47b20..49b58cc43218106f1633c389598894d59447a26b:/services/api/app/models/job.rb diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb index b41df63703..0444528b6b 100644 --- a/services/api/app/models/job.rb +++ b/services/api/app/models/job.rb @@ -15,6 +15,7 @@ class Job < ArvadosModel validate :find_docker_image_locator validate :validate_status validate :validate_state_change + validate :ensure_no_collection_uuids_in_script_params before_save :update_timestamps_when_state_changes has_many :commit_ancestors, :foreign_key => :descendant, :primary_key => :script_version @@ -376,4 +377,34 @@ class Job < ArvadosModel end ok end + + def ensure_no_collection_uuids_in_script_params + # recursive_hash_search searches recursively through hashes and + # arrays in 'thing' for string fields matching regular expression + # 'pattern'. Returns true if pattern is found, false otherwise. + def recursive_hash_search thing, pattern + if thing.is_a? Hash + thing.each do |k, v| + return true if recursive_hash_search v, pattern + end + elsif thing.is_a? Array + thing.each do |k| + return true if recursive_hash_search k, pattern + end + elsif thing.is_a? String + return true if thing.match pattern + end + false + end + + # Fail validation if any script_parameters field includes a string containing a + # collection uuid pattern. + if self.script_parameters_changed? + if recursive_hash_search(self.script_parameters, Collection.uuid_regex) + self.errors.add :script_parameters, "must use portable_data_hash instead of collection uuid" + return false + end + end + true + end end