From dfe126d7ff22ebba6ec86fda609731133bbddbec Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 29 May 2020 17:25:58 +0200 Subject: [PATCH 1/8] Fix missing error information --- app/controllers/carto/api/connectors_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/carto/api/connectors_controller.rb b/app/controllers/carto/api/connectors_controller.rb index 9f47740fe0f5..2353b13a7237 100644 --- a/app/controllers/carto/api/connectors_controller.rb +++ b/app/controllers/carto/api/connectors_controller.rb @@ -76,7 +76,7 @@ def projects render_jsonp({ errors: e.message }, 501) rescue Carto::Connector::InvalidParametersError => e render_jsonp({ errors: e.message }, 422) - rescue + rescue => e render_jsonp({ errors: "Error connecting to provider #{provider_id}: #{e}" }, 400) end end From cefcb18e8745995c6bcb4cd7b58dc4a91c8152e8 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 29 May 2020 17:26:12 +0200 Subject: [PATCH 2/8] Fix typo --- app/controllers/carto/api/connectors_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/carto/api/connectors_controller.rb b/app/controllers/carto/api/connectors_controller.rb index 2353b13a7237..5889d717f64d 100644 --- a/app/controllers/carto/api/connectors_controller.rb +++ b/app/controllers/carto/api/connectors_controller.rb @@ -118,7 +118,7 @@ def project_dataset_tables rescue Carto::Connector::InvalidParametersError => e render_jsonp({ errors: e.message }, 422) rescue => e - render_jsonp({ errors: "Error connecting to provider #{provider_id}, #{e}" }, 400) + render_jsonp({ errors: "Error connecting to provider #{provider_id}: #{e}" }, 400) end end From dda6204d3edc5a8d38fed3f89ccc23f0a51ebb51 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 29 May 2020 17:27:38 +0200 Subject: [PATCH 3/8] Fix for connectors without connection parameter A connector may not use the connection parameter yet need to pass parameters for metadata instantiation --- app/controllers/carto/api/connectors_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/carto/api/connectors_controller.rb b/app/controllers/carto/api/connectors_controller.rb index 5889d717f64d..1f86024b2742 100644 --- a/app/controllers/carto/api/connectors_controller.rb +++ b/app/controllers/carto/api/connectors_controller.rb @@ -163,6 +163,8 @@ def build_connection_parameters(provider_id, request_params) parameters[:connection][key.to_sym] = request_params[key.to_sym] end end + else + parameters.merge! request_params.except(:provider_id, :format, :controller, :action) end parameters end From 802d02fa5bf5d46b379936fd4f660f51e83cf560 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 29 May 2020 18:28:35 +0200 Subject: [PATCH 4/8] Update NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 193b52e51620..edd759a088fc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ Development - Add support for Node.js 12 ### Bug fixes / enhancements +- Fix missing connector metadata error information ([#15690](https://github.com/CartoDB/cartodb/pull/15690)) - Add maxRetries for aws s3 operation to improve reliability ([#15679](https://github.com/CartoDB/cartodb/pull/15679)) - Add metrics for connectors actions ([#155564](https://github.com/CartoDB/cartodb/pull/15564)) - Make DB Direct server_ca configurable ([#15650](https://github.com/CartoDB/cartodb/pull/15650)) From e9d58cd1a97db39510433f0cd8562e13aafff72e Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 4 Jun 2020 20:31:38 +0200 Subject: [PATCH 5/8] Method to delete connector parameters --- lib/carto/connector/parameters.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/carto/connector/parameters.rb b/lib/carto/connector/parameters.rb index 95b7fbedf904..32e52f1e0849 100644 --- a/lib/carto/connector/parameters.rb +++ b/lib/carto/connector/parameters.rb @@ -29,6 +29,11 @@ def [](name) v end + def delete(name) + k, _v = fetch(name) + @params.delete(k) + end + def blank? @params.blank? end From dcc81a7316b67633155e71b44666683650085962 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 4 Jun 2020 20:33:19 +0200 Subject: [PATCH 6/8] Connector parameters normalize_parameter_names modification Now for no explicit parameters to check it returns all the accepted parameter names instead of an empty array. This makes it easier to use this method to check which parameters must be validated. --- lib/carto/connector/parameters.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/carto/connector/parameters.rb b/lib/carto/connector/parameters.rb index 32e52f1e0849..0a80ee6eaa1d 100644 --- a/lib/carto/connector/parameters.rb +++ b/lib/carto/connector/parameters.rb @@ -102,6 +102,7 @@ def normalized_names end def normalize_parameter_names(names) + names ||= @accepted_parameters normalized_array(Array(names)) end @@ -110,10 +111,7 @@ def errors(only_for: nil, parameters_term: 'parameters') if @accepted_parameters.present? invalid_params = normalized_names - @accepted_parameters missing_parameters = @required_parameters - normalized_names - if only_for.present? - only_for = normalize_parameter_names(only_for) - missing_parameters &= only_for - end + missing_parameters &= normalize_parameter_names(only_for) if missing_parameters.present? errors << "Missing required #{parameters_term} #{missing_parameters * ','}" end From 9c30dcb9bfe3123c1674be16894156eab53d5e23 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 4 Jun 2020 22:09:19 +0200 Subject: [PATCH 7/8] This shouldn't be needed Parameters needed for checking the connection or listing projects etc. should be declared inside connection. --- app/controllers/carto/api/connectors_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/carto/api/connectors_controller.rb b/app/controllers/carto/api/connectors_controller.rb index 1f86024b2742..5889d717f64d 100644 --- a/app/controllers/carto/api/connectors_controller.rb +++ b/app/controllers/carto/api/connectors_controller.rb @@ -163,8 +163,6 @@ def build_connection_parameters(provider_id, request_params) parameters[:connection][key.to_sym] = request_params[key.to_sym] end end - else - parameters.merge! request_params.except(:provider_id, :format, :controller, :action) end parameters end From 495a338e9c8697b9bc50251a6cced0c1ae5508f8 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 5 Jun 2020 08:37:54 +0200 Subject: [PATCH 8/8] Fix connectors registration warning message --- lib/tasks/connectors_api.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/connectors_api.rake b/lib/tasks/connectors_api.rake index ccd12ce48dad..4d961adca470 100644 --- a/lib/tasks/connectors_api.rake +++ b/lib/tasks/connectors_api.rake @@ -9,7 +9,7 @@ namespace :cartodb do Carto::ConnectorProvider.create! name: provider_name end end - providers = Carto::Connector.providers(all: true).keys.map { |name| "'#{name}'" } + providers = Carto::Connector.providers(all: true).keys Carto::ConnectorProvider.where.not(name: providers).each do |provider| puts "Provider #{provider.name} is not configured in the code!" end