From c9ef1171382e41512ef77c61fd277c9f63014ca7 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 27 Mar 2024 13:36:56 -0300 Subject: [PATCH 01/14] fix: reportar errores de ssh una sola vez closes #14339 closes #14561 closes #14662 closes #15845 closes #15846 closes #15847 closes #15848 closes #15849 closes #15855 closes #15856 closes #15857 closes #15858 closes #15859 closes #15860 closes #15861 closes #15862 closes #15863 closes #15864 closes #15865 closes #15866 closes #15867 closes #15868 closes #15869 closes #15870 closes #15871 --- app/jobs/git_push_job.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb index 3c62bee2..91589189 100644 --- a/app/jobs/git_push_job.rb +++ b/app/jobs/git_push_job.rb @@ -6,6 +6,14 @@ class GitPushJob < ApplicationJob # @param :site [Site] # @return [nil] def perform(site) - site.repository.push if site.repository.origin + site.repository.push if site.repository.origin end -end \ No newline at end of file + + # Reportar una sola vez para que podamos resolver el problema, pero + # reportarlo igual. + # + # @return [Bool] + def handle_error(error) + expire + end +end From ba3cc9cad99db093c7583e5f5d29964e2c6897a0 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 27 Mar 2024 13:42:27 -0300 Subject: [PATCH 02/14] chore: rubocop --- app/jobs/git_push_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb index 91589189..7c3eb236 100644 --- a/app/jobs/git_push_job.rb +++ b/app/jobs/git_push_job.rb @@ -13,7 +13,7 @@ class GitPushJob < ApplicationJob # reportarlo igual. # # @return [Bool] - def handle_error(error) + def handle_error(_) expire end end From 94d7b32ce6fc4e4b2fbcb89717655310876086ba Mon Sep 17 00:00:00 2001 From: f Date: Tue, 9 Apr 2024 14:16:01 -0300 Subject: [PATCH 03/14] fix: handle_error no es compatible con activejob --- app/jobs/application_job.rb | 5 +++++ app/jobs/git_push_job.rb | 12 ++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 06690c53..8b85358c 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -4,6 +4,11 @@ class ApplicationJob < ActiveJob::Base include Que::ActiveJob::JobExtensions + # Si falla por cualquier cosa informar y descartar + discard_on(Exception) do |error| + ExceptionNotifier.notify_exception(error, data: { site: site.name }) + end + private def site diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb index 7c3eb236..260e3476 100644 --- a/app/jobs/git_push_job.rb +++ b/app/jobs/git_push_job.rb @@ -3,17 +3,13 @@ # Permite pushear los cambios cada vez que se # hacen commits en un sitio class GitPushJob < ApplicationJob + attr_reader :site + # @param :site [Site] # @return [nil] def perform(site) + @site = site + site.repository.push if site.repository.origin end - - # Reportar una sola vez para que podamos resolver el problema, pero - # reportarlo igual. - # - # @return [Bool] - def handle_error(_) - expire - end end From 6dbc8fa0c12bbfcec92b16ffaa72549dd83c5c2f Mon Sep 17 00:00:00 2001 From: f Date: Tue, 9 Apr 2024 14:16:27 -0300 Subject: [PATCH 04/14] fix: reintentar compilaciones --- app/jobs/deploy_job.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 3044b59f..6765bb89 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -11,13 +11,8 @@ class DeployJob < ApplicationJob # Lanzar lo antes posible self.priority = 10 - def handle_error(error) - case error - when DeployAlreadyRunningException then retry_in 1.minute - when DeployTimedOutException then expire - else super - end - end + retry_on DeployAlreadyRunningException, wait: 1.minute + discard_on DeployTimedOutException # rubocop:disable Metrics/MethodLength def perform(site, notify: true, time: Time.now, output: false) From b0bf0c0c535b8c52ce6d4fafc5a3167c95322a4e Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Apr 2024 11:00:18 -0300 Subject: [PATCH 05/14] BREAKING CHANGE: usar global ids en los jobs --- app/controllers/api/v1/contact_controller.rb | 2 +- app/controllers/api/v1/notices_controller.rb | 2 +- app/jobs/application_job.rb | 8 ++--- app/jobs/backtrace_job.rb | 9 ++---- app/jobs/contact_job.rb | 8 ++--- app/jobs/deploy_job.rb | 32 ++++++++++---------- app/jobs/git_push_job.rb | 4 --- app/jobs/maintenance_job.rb | 3 +- app/jobs/periodic_job.rb | 3 -- app/jobs/stat_collection_job.rb | 6 ++-- app/jobs/uri_collection_job.rb | 4 +-- app/mailers/application_mailer.rb | 2 +- app/mailers/deploy_mailer.rb | 3 +- app/mailers/invitadx_mailer.rb | 9 ------ app/models/log_entry.rb | 2 +- app/services/site_service.rb | 2 +- lib/tasks/stats.rake | 6 ++-- 17 files changed, 37 insertions(+), 68 deletions(-) delete mode 100644 app/mailers/invitadx_mailer.rb diff --git a/app/controllers/api/v1/contact_controller.rb b/app/controllers/api/v1/contact_controller.rb index d949dc30..c340097f 100644 --- a/app/controllers/api/v1/contact_controller.rb +++ b/app/controllers/api/v1/contact_controller.rb @@ -18,7 +18,7 @@ module Api # Si todo salió bien, enviar los correos y redirigir al sitio. # El sitio nos dice a dónde tenemos que ir. - ContactJob.perform_later site.id, + ContactJob.perform_later site, params[:form], contact_params.to_h.symbolize_keys, params[:redirect] diff --git a/app/controllers/api/v1/notices_controller.rb b/app/controllers/api/v1/notices_controller.rb index 8f384f1a..01bec517 100644 --- a/app/controllers/api/v1/notices_controller.rb +++ b/app/controllers/api/v1/notices_controller.rb @@ -11,7 +11,7 @@ module Api # respondemos con lo mismo. def create if (site&.airbrake_valid? airbrake_token) && !detected_device.bot? - BacktraceJob.perform_later site_id: params[:site_id], + BacktraceJob.perform_later site: site, params: airbrake_params.to_h end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 8b85358c..66345949 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -4,14 +4,10 @@ class ApplicationJob < ActiveJob::Base include Que::ActiveJob::JobExtensions + attr_reader :site + # Si falla por cualquier cosa informar y descartar discard_on(Exception) do |error| ExceptionNotifier.notify_exception(error, data: { site: site.name }) end - - private - - def site - @site ||= Site.find @params[:site_id] - end end diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 97e6007b..830dc9b3 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -6,10 +6,9 @@ class BacktraceJob < ApplicationJob EMPTY_SOURCEMAP = { 'mappings' => '' }.freeze - attr_reader :params, :site_id + attr_reader :params - def perform(site_id:, params:) - @site_id = site_id + def perform(site:, params:) @params = params unless sources.empty? @@ -44,10 +43,6 @@ class BacktraceJob < ApplicationJob private - def site - @site ||= Site.find_by_id(site_id) - end - # Obtiene todos los archivos del backtrace solo si los puede descargar # desde fuentes seguras. # diff --git a/app/jobs/contact_job.rb b/app/jobs/contact_job.rb index c15d7eee..2ac80ce3 100644 --- a/app/jobs/contact_job.rb +++ b/app/jobs/contact_job.rb @@ -5,11 +5,7 @@ class ContactJob < ApplicationJob # @param [Integer] # @param [String] # @param [Hash] - def perform(site_id, form_name, form, origin = nil) - # Retrocompabilidad al actualizar a 2.7.1 - # @see ApplicationJob#site - @params = { site_id: site_id } - + def perform(site, form_name, form, origin = nil) # Sanitizar los valores form.each_key do |key| form[key] = ActionController::Base.helpers.sanitize form[key] @@ -23,7 +19,7 @@ class ContactJob < ApplicationJob usuaries.each_slice(10) do |u| ContactMailer.with(form_name: form_name, form: form, - site_id: site_id, + site: site, usuaries_emails: u, origin: origin) .notify_usuaries.deliver_now diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 6765bb89..103656f4 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -16,34 +16,32 @@ class DeployJob < ApplicationJob # rubocop:disable Metrics/MethodLength def perform(site, notify: true, time: Time.now, output: false) - @output = output + @site = site ActiveRecord::Base.connection_pool.with_connection do - @site = Site.find(site) - # Si ya hay una tarea corriendo, aplazar esta. Si estuvo # esperando más de 10 minutos, recuperar el estado anterior. # # Como el trabajo actual se aplaza al siguiente, arrastrar la # hora original para poder ir haciendo timeouts. - if @site.building? + if site.building? notify = false if 10.minutes.ago >= time raise DeployTimedOutException, - "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" + "#{site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" else raise DeployAlreadyRunningException end end @deployed = {} - @site.update status: 'building' - @site.deployment_list.each do |d| + site.update status: 'building' + site.deployment_list.each do |d| begin raise DeployException, 'Una dependencia falló' if failed_dependencies? d - status = d.deploy(output: @output) + status = d.deploy(output: output) seconds = d.build_stats.last.try(:seconds) || 0 size = d.size urls = d.urls.map do |url| @@ -52,7 +50,7 @@ class DeployJob < ApplicationJob nil end.compact - if d == @site.deployment_list.last && !status + if d == site.deployment_list.last && !status raise DeployException, 'Falló la compilación' end rescue StandardError => e @@ -73,7 +71,7 @@ class DeployJob < ApplicationJob } end - return unless @output + return unless output puts (Terminal::Table.new do |t| t << (%w[type] + @deployed.values.first.keys) @@ -83,12 +81,12 @@ class DeployJob < ApplicationJob end end) ensure - if @site.present? - @site.update status: 'waiting' + if site.present? + site.update status: 'waiting' notify_usuaries if notify - puts "\a" if @output + puts "\a" if output end end end @@ -118,7 +116,7 @@ class DeployJob < ApplicationJob # @param :deploy [Deploy] def notify_exception(exception, deploy = nil) data = { - site: @site.id, + site: site.name, deploy: deploy&.type, log: deploy&.build_stats&.last&.log, failed_dependencies: (failed_dependencies(deploy) if deploy) @@ -128,8 +126,10 @@ class DeployJob < ApplicationJob end def notify_usuaries - @site.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id).each do |usuarie| - DeployMailer.with(usuarie: usuarie, site: @site.id) + usuarie_ids = site.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id) + + Usuarie.where(id: usuarie_ids).find_each do |usuarie| + DeployMailer.with(usuarie_id: usuarie, site: site) .deployed(@deployed) .deliver_now end diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb index 260e3476..d8c811ba 100644 --- a/app/jobs/git_push_job.rb +++ b/app/jobs/git_push_job.rb @@ -3,13 +3,9 @@ # Permite pushear los cambios cada vez que se # hacen commits en un sitio class GitPushJob < ApplicationJob - attr_reader :site - # @param :site [Site] # @return [nil] def perform(site) - @site = site - site.repository.push if site.repository.origin end end diff --git a/app/jobs/maintenance_job.rb b/app/jobs/maintenance_job.rb index c7a962f9..02f29a77 100644 --- a/app/jobs/maintenance_job.rb +++ b/app/jobs/maintenance_job.rb @@ -15,8 +15,7 @@ # Lo mismo para salir de mantenimiento, agregando el atributo # are_we_back: true al crear el Maintenance. class MaintenanceJob < ApplicationJob - def perform(maintenance_id:) - maintenance = Maintenance.find(maintenance_id) + def perform(maintenance:) # Decidir cuál vamos a enviar según el estado de Maintenance mailer = maintenance.are_we_back ? :were_back : :notice diff --git a/app/jobs/periodic_job.rb b/app/jobs/periodic_job.rb index 2f60a2b3..f66434c9 100644 --- a/app/jobs/periodic_job.rb +++ b/app/jobs/periodic_job.rb @@ -6,9 +6,6 @@ class PeriodicJob < ApplicationJob STARTING_INTERVAL = Stat::INTERVALS.first - # Tener el sitio a mano - attr_reader :site - # Descartar y notificar si pasó algo más. # # XXX: En realidad deberíamos seguir reintentando? diff --git a/app/jobs/stat_collection_job.rb b/app/jobs/stat_collection_job.rb index e402e3b5..02752901 100644 --- a/app/jobs/stat_collection_job.rb +++ b/app/jobs/stat_collection_job.rb @@ -7,8 +7,8 @@ class StatCollectionJob < PeriodicJob STAT_NAME = 'stat_collection_job' - def perform(site_id:, once: true) - @site = Site.find site_id + def perform(site:, once: true) + @site = site beginning = beginning_of_interval stat = site.stats.create! name: STAT_NAME @@ -22,7 +22,7 @@ class StatCollectionJob < PeriodicJob rollup.average(:seconds) end - dimensions = { site_id: site_id } + dimensions = { site_id: site.id } reduce_rollup(name: 'builds', operation: :sum, dimensions: dimensions) reduce_rollup(name: 'space_used', operation: :average, dimensions: dimensions) diff --git a/app/jobs/uri_collection_job.rb b/app/jobs/uri_collection_job.rb index 4cbbf593..92d788bc 100644 --- a/app/jobs/uri_collection_job.rb +++ b/app/jobs/uri_collection_job.rb @@ -16,8 +16,8 @@ class UriCollectionJob < PeriodicJob IMAGES = %w[.png .jpg .jpeg .gif .webp .jfif].freeze STAT_NAME = 'uri_collection_job' - def perform(site_id:, once: true) - @site = Site.find site_id + def perform(site:, once: true) + @site = site # Obtener el principio del intervalo anterior beginning_of_interval diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 8369550d..1f1d453e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -10,7 +10,7 @@ class ApplicationMailer < ActionMailer::Base private def site - @site ||= Site.find @params[:site_id] + @site ||= @params[:site] end def inline_logo! diff --git a/app/mailers/deploy_mailer.rb b/app/mailers/deploy_mailer.rb index 37748b42..abf6932c 100644 --- a/app/mailers/deploy_mailer.rb +++ b/app/mailers/deploy_mailer.rb @@ -13,8 +13,7 @@ class DeployMailer < ApplicationMailer # rubocop:disable Metrics/AbcSize def deployed(deploys = {}) - usuarie = Usuarie.find(params[:usuarie]) - site = usuarie.sites.find(params[:site]) + usuarie = params[:usuarie] hostname = site.hostname deploys ||= {} diff --git a/app/mailers/invitadx_mailer.rb b/app/mailers/invitadx_mailer.rb deleted file mode 100644 index cfb80a55..00000000 --- a/app/mailers/invitadx_mailer.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class InvitadxMailer < ApplicationMailer - def confirmation_required - @invitadx = params[:invitadx] - @site = params[:site] - mail from: "#{@site.config.dig('title')} <#{ENV.fetch('DEFAULT_FROM', 'sutty@kefir.red')}>", to: @invitadx.email, subject: t('.subject') - end -end diff --git a/app/models/log_entry.rb b/app/models/log_entry.rb index 9685e0d0..7525177a 100644 --- a/app/models/log_entry.rb +++ b/app/models/log_entry.rb @@ -11,7 +11,7 @@ class LogEntry < ApplicationRecord def resend return if sent - ContactJob.perform_later site_id, params[:form], params + ContactJob.perform_later site, params[:form], params end def params diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 5c37cfe3..3a6b36f7 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -5,7 +5,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do def deploy site.enqueue! - DeployJob.perform_later site.id + DeployJob.perform_later site end # Crea un sitio, agrega un rol nuevo y guarda los cambios a la diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index 9461782a..fbcb5fa4 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -3,9 +3,9 @@ namespace :stats do desc 'Process stats' task process_all: :environment do - Site.all.pluck(:id).each do |site_id| - UriCollectionJob.perform_now site_id: site_id, once: true - StatCollectionJob.perform_now site_id: site_id, once: true + Site.all.find_each do |site| + UriCollectionJob.perform_now site: site, once: true + StatCollectionJob.perform_now site: site, once: true end end end From 53fe2847a1ca5adb96776bb2b74730ec51de1b81 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Apr 2024 13:22:17 -0300 Subject: [PATCH 06/14] fixup! BREAKING CHANGE: usar global ids en los jobs --- app/jobs/deploy_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 103656f4..f84dc55c 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -129,7 +129,7 @@ class DeployJob < ApplicationJob usuarie_ids = site.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id) Usuarie.where(id: usuarie_ids).find_each do |usuarie| - DeployMailer.with(usuarie_id: usuarie, site: site) + DeployMailer.with(usuarie: usuarie, site: site) .deployed(@deployed) .deliver_now end From 7a71e1de8856f241e271d14ff3cf04c28544ed8a Mon Sep 17 00:00:00 2001 From: f Date: Fri, 12 Apr 2024 15:31:47 -0300 Subject: [PATCH 07/14] fix: no fallar si no hay sitio #16007 --- app/jobs/application_job.rb | 2 +- app/jobs/backtrace_job.rb | 1 + app/jobs/contact_job.rb | 2 ++ app/jobs/git_pull_job.rb | 2 ++ app/jobs/git_push_job.rb | 2 ++ 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 66345949..37ec0f76 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -8,6 +8,6 @@ class ApplicationJob < ActiveJob::Base # Si falla por cualquier cosa informar y descartar discard_on(Exception) do |error| - ExceptionNotifier.notify_exception(error, data: { site: site.name }) + ExceptionNotifier.notify_exception(error, data: { site: @site&.name }) end end diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 830dc9b3..5e9a05cf 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -9,6 +9,7 @@ class BacktraceJob < ApplicationJob attr_reader :params def perform(site:, params:) + @site = site @params = params unless sources.empty? diff --git a/app/jobs/contact_job.rb b/app/jobs/contact_job.rb index 2ac80ce3..d4c2677f 100644 --- a/app/jobs/contact_job.rb +++ b/app/jobs/contact_job.rb @@ -6,6 +6,8 @@ class ContactJob < ApplicationJob # @param [String] # @param [Hash] def perform(site, form_name, form, origin = nil) + @site = site + # Sanitizar los valores form.each_key do |key| form[key] = ActionController::Base.helpers.sanitize form[key] diff --git a/app/jobs/git_pull_job.rb b/app/jobs/git_pull_job.rb index 58a4e6b1..72e20be0 100644 --- a/app/jobs/git_pull_job.rb +++ b/app/jobs/git_pull_job.rb @@ -7,6 +7,8 @@ class GitPullJob < ApplicationJob # @param :usuarie [Usuarie] # @return [nil] def perform(site, usuarie) + @site = site + return unless site.repository.origin return unless site.repository.fetch.positive? diff --git a/app/jobs/git_push_job.rb b/app/jobs/git_push_job.rb index d8c811ba..4df9f5aa 100644 --- a/app/jobs/git_push_job.rb +++ b/app/jobs/git_push_job.rb @@ -6,6 +6,8 @@ class GitPushJob < ApplicationJob # @param :site [Site] # @return [nil] def perform(site) + @site = site + site.repository.push if site.repository.origin end end From 4ccf37c370cdb3eac19b1ae8b1d222e3a8b7d52c Mon Sep 17 00:00:00 2001 From: f Date: Mon, 15 Apr 2024 11:54:28 -0300 Subject: [PATCH 08/14] =?UTF-8?q?fix:=20informar=20la=20tarea=20que=20fall?= =?UTF-8?q?=C3=B3=20de=20forma=20gen=C3=A9rica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #16052 closes #16058 closes #16059 --- app/jobs/application_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 37ec0f76..d527c9b9 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -7,7 +7,7 @@ class ApplicationJob < ActiveJob::Base attr_reader :site # Si falla por cualquier cosa informar y descartar - discard_on(Exception) do |error| - ExceptionNotifier.notify_exception(error, data: { site: @site&.name }) + discard_on(Exception) do |job, error| + ExceptionNotifier.notify_exception(error, data: { job: job }) end end From fb4228b873e5e1873b82c38498c18f992df73fdb Mon Sep 17 00:00:00 2001 From: f Date: Mon, 15 Apr 2024 16:58:55 -0300 Subject: [PATCH 09/14] =?UTF-8?q?fix:=20no=20filtrar=20informaci=C3=B3n=20?= =?UTF-8?q?privada!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/application_record.rb | 7 +++++++ config/initializers/filter_parameter_logging.rb | 1 + 2 files changed, 8 insertions(+) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 71fbba5b..27ed3d56 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -2,4 +2,11 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + + # Obtener una lista filtrada de atributos al momento de serializar + # + # @return [Hash] + def to_yaml(options = {}) + self.class.inspection_filter.filter attributes + end end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 2fc446ff..8ef6ca49 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -5,4 +5,5 @@ # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += %i[ password passw secret token _key crypt salt certificate otp ssn key + _pem _ciphertext ] From 7f437f9e0659ae648c9d90e4c3ebf1d8ac760a3f Mon Sep 17 00:00:00 2001 From: f Date: Mon, 15 Apr 2024 17:00:58 -0300 Subject: [PATCH 10/14] =?UTF-8?q?fix:=20filtrar=20informaci=C3=B3n=20perso?= =?UTF-8?q?nal=20tambi=C3=A9n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/filter_parameter_logging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 8ef6ca49..b1d9f2b0 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -5,5 +5,5 @@ # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += %i[ password passw secret token _key crypt salt certificate otp ssn key - _pem _ciphertext + _pem _ciphertext email ] From e8cf50b9d22154294b7ca03782d9ffa001273467 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 15 Apr 2024 17:10:19 -0300 Subject: [PATCH 11/14] fix: convertir a yaml --- app/models/application_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 27ed3d56..985df966 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -5,8 +5,8 @@ class ApplicationRecord < ActiveRecord::Base # Obtener una lista filtrada de atributos al momento de serializar # - # @return [Hash] + # @return [String] def to_yaml(options = {}) - self.class.inspection_filter.filter attributes + self.class.inspection_filter.filter(attributes).to_yaml(options) end end From 83add8dd7def7b58dfb741d5c51106576f3a0882 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 15 Apr 2024 17:26:40 -0300 Subject: [PATCH 12/14] =?UTF-8?q?fix:=20usar=20una=20versi=C3=B3n=20m?= =?UTF-8?q?=C3=A1s=20corta=20del=20hash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/application_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 985df966..f09c4dd4 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -7,6 +7,6 @@ class ApplicationRecord < ActiveRecord::Base # # @return [String] def to_yaml(options = {}) - self.class.inspection_filter.filter(attributes).to_yaml(options) + self.class.inspection_filter.filter(serializable_hash).to_yaml(options) end end From 2eb3145e1cf20581216b1ddcecebe6ee57f41e45 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 15 Apr 2024 17:28:30 -0300 Subject: [PATCH 13/14] fix: los atributos filtrados son por modelo --- app/models/site.rb | 2 ++ app/models/usuarie.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/site.rb b/app/models/site.rb index 7b93184f..c47a14a2 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -13,6 +13,8 @@ class Site < ApplicationRecord include Site::SocialDistributedPress include Tienda + self.filter_attributes += [/_key/, /_ciphertext\z/] + # Cifrar la llave privada que cifra y decifra campos ocultos. Sutty # tiene acceso pero los datos se guardan cifrados en el sitio. Esto # protege información privada en repositorios públicos, pero no la diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index 42f20c0b..4eba314a 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -21,6 +21,8 @@ class Usuarie < ApplicationRecord has_many :blazer_audits, foreign_key: 'user_id', class_name: 'Blazer::Audit' has_many :blazer_queries, foreign_key: 'creator_id', class_name: 'Blazer::Query' + self.filter_attributes += [/\Aemail\z/, /\Aencrypted_password\z/] + def name email.split('@', 2).first end From 8fba98f9fd0da1a1e5949e5a729d4de8d74059f8 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 2 May 2024 15:57:49 -0300 Subject: [PATCH 14/14] chore: rubocop --- app/jobs/backtrace_job.rb | 4 +--- app/jobs/deploy_job.rb | 17 +++++++---------- app/models/site.rb | 18 +++++++++--------- app/models/usuarie.rb | 10 +++++----- app/services/site_service.rb | 4 +--- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 5e9a05cf..4ef5287c 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -55,9 +55,7 @@ class BacktraceJob < ApplicationJob x['backtrace'] end.flatten.map do |x| x['file'].split('@').last - end.uniq.select do |x| - %r{\Ahttps://} =~ x - end + end.uniq.grep(%r{\Ahttps://}) end # Descarga y devuelve los datos de un archivo diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index f84dc55c..66cccd1b 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -27,12 +27,11 @@ class DeployJob < ApplicationJob if site.building? notify = false - if 10.minutes.ago >= time - raise DeployTimedOutException, - "#{site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" - else - raise DeployAlreadyRunningException - end + raise DeployAlreadyRunningException unless 10.minutes.ago >= time + + raise DeployTimedOutException, + "#{site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" + end @deployed = {} @@ -50,9 +49,7 @@ class DeployJob < ApplicationJob nil end.compact - if d == site.deployment_list.last && !status - raise DeployException, 'Falló la compilación' - end + raise DeployException, 'Falló la compilación' if d == site.deployment_list.last && !status rescue StandardError => e status = false seconds ||= 0 @@ -73,7 +70,7 @@ class DeployJob < ApplicationJob return unless output - puts (Terminal::Table.new do |t| + puts(Terminal::Table.new do |t| t << (%w[type] + @deployed.values.first.keys) t.add_separator @deployed.each do |type, row| diff --git a/app/models/site.rb b/app/models/site.rb index e3068734..f51d2c6f 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -292,11 +292,11 @@ class Site < ApplicationRecord # layouts. Si pasamos un layout que no existe, obtenemos un # NoMethodError @layouts_struct ||= Struct.new(*layout_keys, keyword_init: true) - @layouts ||= @layouts_struct.new(**data['layouts'].map do |name, metadata| + @layouts ||= @layouts_struct.new(**data['layouts'].to_h do |name, metadata| [name.to_sym, Layout.new(site: self, name: name.to_sym, meta: metadata.delete('meta')&.with_indifferent_access, metadata: metadata.with_indifferent_access)] - end.to_h) + end) end # TODO: Si la estructura de datos no existe, vamos a producir una @@ -389,7 +389,7 @@ class Site < ApplicationRecord end def reload - super.tap do |s| + super.tap do |_s| reload_jekyll! end self @@ -479,7 +479,7 @@ class Site < ApplicationRecord def clone_skel! return if jekyll? - Rugged::Repository.clone_at(ENV['SKEL_SUTTY'], path, checkout_branch: design.gem) + Rugged::Repository.clone_at(ENV.fetch('SKEL_SUTTY', nil), path, checkout_branch: design.gem) # Necesita un bloque repository.rugged.remotes.rename('origin', 'upstream') {} @@ -579,11 +579,11 @@ class Site < ApplicationRecord deploy_local = deploys.find_by_type('DeployLocal') deploy_local.git_lfs - if !gems_installed? || gemfile_updated? || gemfile_lock_updated? - deploy_local.bundle - touch - FileUtils.touch(gemfile_path) - end + return unless !gems_installed? || gemfile_updated? || gemfile_lock_updated? + + deploy_local.bundle + touch + FileUtils.touch(gemfile_path) end def gem_path diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index 4eba314a..4856f17f 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -76,10 +76,10 @@ class Usuarie < ApplicationRecord # Si le usuarie (re)confirma su cuenta con una invitación pendiente, # considerarla aceptada también. def accept_invitation_after_confirmation! - if confirmed? - self.invitation_token = nil - self.invitation_accepted_at ||= Time.now.utc - end + return unless confirmed? + + self.invitation_token = nil + self.invitation_accepted_at ||= Time.now.utc end # Muestra un error si el idioma no está disponible al cambiar el @@ -87,7 +87,7 @@ class Usuarie < ApplicationRecord # # @return [nil] def locale_available! - return if I18n.locale_available? self.lang + return if I18n.locale_available? lang errors.add(:lang, I18n.t('activerecord.errors.models.usuarie.attributes.lang.not_available')) nil diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 3a6b36f7..a28e5ee8 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -222,9 +222,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do end end - private - - def with_all_locales(&block) + def with_all_locales site.locales.map do |locale| next unless I18n.available_locales.include? locale