Skip to content

Commit 3655234

Browse files
author
tom statter
committed
fix security vulnerabilities
1 parent 17e3da8 commit 3655234

11 files changed

+66
-48
lines changed

datashift.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Gem::Specification.new do |s|
2222
s.require_paths = ['lib']
2323

2424
s.add_runtime_dependency 'rails', '>= 4.2', '~> 5.2'
25-
s.add_runtime_dependency 'thor', '<= 0.20', '>= 0.18'
25+
s.add_runtime_dependency 'thor', '>= 0.19.0', '< 2.0'
2626
s.add_runtime_dependency 'paperclip', '>= 4.3', '<= 6.0.0'
2727
s.add_runtime_dependency 'spreadsheet', '~> 1.1'
2828

29-
s.add_runtime_dependency 'rubyzip', '>= 0.9.9', '< 1.3'
29+
s.add_dependency "rubyzip", ">= 1.3.0"
3030

3131
s.add_runtime_dependency 'erubis', '~> 2.7', '>= 2.7.0'
3232
s.add_runtime_dependency 'thread_safe', '~> 0.3', '>= 0.3'

lib/datashift/generators/config_generator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def self.title
2020

2121
attr_writer :import_template, :export_template
2222

23-
def initialize
24-
super
23+
def initialize(config: nil)
24+
super(config: configuration)
2525
end
2626

2727
def import_template

lib/datashift/generators/csv_generator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class CsvGenerator < GeneratorBase
1111

1212
attr_accessor :file_name
1313

14-
def initialize
15-
super
14+
def initialize(config: nil)
15+
super(config: config)
1616
end
1717

1818
def generate(file_name, klass)

lib/datashift/generators/excel_generator.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@ class ExcelGenerator < GeneratorBase
1818
attr_accessor :excel
1919
attr_accessor :file_name
2020

21-
def initialize
22-
super
21+
def initialize(config: nil)
22+
super(config: config)
2323
end
2424

2525
# Create an Excel file template (header row) representing supplied Model
2626
# file_name => Filename for generated template
2727
#
2828
# See DataShift::Exporters::Configuration for options
2929
#
30-
def generate(file_name, klass, options = {})
30+
def generate(file_name, klass, associations: false, options: {})
3131

3232
@file_name = file_name
3333

3434
start_excel(klass, options)
3535

36-
@headers = Headers.klass_to_headers(klass)
36+
@config.with = :all if associations
37+
38+
@headers = Headers.klass_to_headers(klass, config: config)
3739

3840
@excel.set_headers(@headers)
3941

lib/datashift/generators/generator_base.rb

+5-11
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,19 @@ class GeneratorBase
1010

1111
include DataShift::Logging
1212

13-
attr_accessor :configuration
13+
attr_accessor :config
1414

15-
def initialize; end
15+
def initialize(config: nil)
16+
@config = config || DataShift::Configuration.call
17+
end
1618

1719
# Prepare to generate with associations but then
1820
# calls a **derived generate** method i.e abstract to this base class
1921
#
2022
# file_name => Filename for generated template
2123
#
2224
def generate_with_associations(file_name, klass)
23-
24-
state = DataShift::Configuration.call.with
25-
26-
DataShift::Configuration.call.with = :all
27-
28-
generate(file_name, klass)
29-
ensure
30-
DataShift::Configuration.call.with = state
31-
25+
generate(file_name, klass, associations: true)
3226
end
3327

3428
end

lib/datashift/headers.rb

+7-11
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def index(header)
5454
#
5555
class << self
5656

57-
def klass_to_operators(klass)
57+
def klass_to_operators(klass, config: DataShift::Configuration.call)
5858

59-
headers = Headers.new(klass)
59+
headers = Headers.new(klass, config: config)
6060

6161
headers.class_source_to_headers
6262

63-
DataShift::Transformation::Remove.new.unwanted_headers(headers)
63+
DataShift::Transformation::RemoveUnwantedHeaders.call(headers, config: config)
6464

6565
headers
6666
end
@@ -74,20 +74,18 @@ def klass_to_operators(klass)
7474
# These can be used to infer an operator to call from an inbound header
7575
# or provide mapping to an internal method from an external header
7676
#
77-
def class_source_to_operators
77+
def class_source_to_operators(config: DataShift::Configuration.call)
7878

7979
raise SourceIsNotAClass, 'Cannot parse source for headers - source must be a Class' unless source.is_a?(Class)
8080

8181
# TODO: This collection can now be sorted
8282
collection = ModelMethods::Manager.catalog_class(source)
8383

84-
configuration = DataShift::Configuration.call
85-
8684
if collection
8785
collection.each do |mm|
8886
next if(DataShift::Transformation::Remove.new.association?(mm))
8987

90-
next unless configuration.op_type_in_scope?(mm)
88+
next unless config.op_type_in_scope?(mm)
9189
if(mm.association_type?)
9290
association_to_headers(mm)
9391
else
@@ -100,11 +98,9 @@ def class_source_to_operators
10098

10199
alias class_source_to_headers class_source_to_operators
102100

103-
def association_to_headers( model_method )
104-
105-
configuration = DataShift::Configuration.call
101+
def association_to_headers( model_method, config: DataShift::Configuration.call)
106102

107-
if(configuration.expand_associations)
103+
if(config.expand_associations)
108104
model_method.association_columns.each do |c|
109105
add "#{model_method.operator}::#{c.name}"
110106
end

lib/datashift/loaders/loader_base.rb

+18-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ def configure_from(yaml_file, klass = nil, locale_key = 'data_flow_schema')
139139

140140
logger.info("Reading Datashift loader config from: #{yaml_file.inspect}")
141141

142-
data = Configuration.parse_yaml(yaml_file)
143-
144-
logger.info("Read Datashift config: #{data.inspect}")
145-
146142
@binder ||= DataShift::Binder.new
147143

148144
data_flow_schema = DataShift::DataFlowSchema.new
@@ -157,6 +153,24 @@ def configure_from(yaml_file, klass = nil, locale_key = 'data_flow_schema')
157153
logger.info("Loader Options : #{@config.inspect}")
158154
end
159155

156+
def configure_from_yaml(yaml, klass: nil, locale_key: 'data_flow_schema')
157+
158+
setup_load_class(klass) if(klass)
159+
160+
@binder ||= DataShift::Binder.new
161+
162+
data_flow_schema = DataShift::DataFlowSchema.new
163+
164+
# Includes configuring DataShift::Transformation
165+
nodes = data_flow_schema.prepare_from_yaml(yaml, locale_key)
166+
167+
@binder.add_bindings_from_nodes( nodes )
168+
169+
PopulatorFactory.configure_from_yaml(load_object_class, yaml)
170+
171+
logger.info("Loader Options : #{@config.inspect}")
172+
end
173+
160174
end
161175

162176
end

lib/datashift/node_context.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ def next_update?
4545
def process
4646
populator.prepare_and_assign(self, doc_context.load_object, data)
4747
rescue StandardError => x
48-
failed = FailureData.new( doc_context.load_object, self, x.message)
49-
48+
#failed = FailureData.new( doc_context.load_object, self, x.message)
5049
failed.error_messages << "Failed to process node : #{method_binding.pp}"
51-
52-
doc_context.progress_monitor.failure(failed)
53-
5450
logger.error("#{x.backtrace.first} : #{x.message}")
5551
raise x
5652
end

lib/datashift/populators/populator_factory.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ def self.populators
2424
# populator
2525
#
2626
def self.configure(load_object_class, yaml_file)
27+
configure_from_yaml(load_object_class, Configuration.parse_yaml(yaml_file))
28+
end
2729

28-
@config = Configuration.parse_yaml(yaml_file)
30+
def self.configure_from_yaml(load_object_class, yaml)
31+
@config = yaml
2932

3033
if @config[:datashift_populators]
3134
@config[:datashift_populators].each do |_operator, type|
3235
populator = ::Object.const_get(type).new
3336

34-
populator.configure_from(load_object_class, yaml_file)
37+
populator.configure_from_yaml(load_object_class, yaml)
3538

3639
populators[@config[:datashift_populators]]
3740
end

lib/datashift/progress_monitor.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def success(reportable_object)
5252
# so the load object is invalid
5353

5454
def failure(failure_data)
55-
5655
@current_status = :failure
5756

5857
logger.error 'Failure(s) reported :'
@@ -64,17 +63,21 @@ def failure(failure_data)
6463
end
6564

6665
def add_loaded_object(object)
66+
return if object.nil? || @loaded_objects.include?(object)
67+
6768
@success_inbound_count += 1
6869
@processed_object_count += 1
6970

70-
@loaded_objects << object.id unless object.nil? || @loaded_objects.include?(object)
71+
@loaded_objects << object
7172
end
7273

7374
def add_failed_object(object)
75+
return if object.nil? || @failed_objects.include?(object)
76+
7477
@failed_inbound_count += 1
7578
@processed_object_count += 1
7679

77-
@failed_objects << object unless object.nil? || @failed_objects.include?(object)
80+
@failed_objects << object
7881
end
7982

8083
# The database objects created or rejected

lib/datashift/transformation/remove.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ module DataShift
1010

1111
module Transformation
1212

13+
class RemoveUnwantedHeaders
14+
def self.call(headers, config: DataShift::Configuration.call)
15+
Remove.new(config: config).unwanted_headers(headers)
16+
end
17+
end
18+
1319
class Remove
1420

21+
def initialize(config: DataShift::Configuration.call)
22+
@config = config
23+
end
24+
1525
def remove_list
16-
@remove_list ||= DataShift::Configuration.call.prep_remove_list
26+
@remove_list ||= @config.prep_remove_list
1727
end
1828

1929
def association?(mm)
2030
return false unless(mm.association_type?)
21-
(DataShift::Configuration.call.exclude_associations & [mm.operator, mm.operator.to_sym]).present?
31+
(@config.exclude_associations & [mm.operator, mm.operator.to_sym]).present?
2232
end
2333

2434
# Specify columns to remove via DataShift::Configuration

0 commit comments

Comments
 (0)