diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-10 07:53:40 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-10 07:53:40 +0000 |
commit | cfc792b9ca064990e6540cb742e80529ea669a81 (patch) | |
tree | 147cd4256319990cebbc02fe8e4fbbbe06f5720a /app/workers | |
parent | 93c6764dacd4c605027ef1cd367d3aebe420b223 (diff) | |
download | gitlab-ce-cfc792b9ca064990e6540cb742e80529ea669a81.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
4 files changed, 69 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 710998dcd1a..02acf360afc 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -16,6 +16,7 @@ - cronjob:pages_domain_verification_cron - cronjob:pages_domain_removal_cron - cronjob:pages_domain_ssl_renewal_cron +- cronjob:personal_access_tokens_expiring - cronjob:pipeline_schedule - cronjob:prune_old_events - cronjob:remove_expired_group_links @@ -51,6 +52,8 @@ - gcp_cluster:clusters_cleanup_app - gcp_cluster:clusters_cleanup_project_namespace - gcp_cluster:clusters_cleanup_service_account +- gcp_cluster:clusters_applications_activate_service +- gcp_cluster:clusters_applications_deactivate_service - github_import_advance_stage - github_importer:github_import_import_diff_note diff --git a/app/workers/clusters/applications/activate_service_worker.rb b/app/workers/clusters/applications/activate_service_worker.rb new file mode 100644 index 00000000000..4f285d55162 --- /dev/null +++ b/app/workers/clusters/applications/activate_service_worker.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Clusters + module Applications + class ActivateServiceWorker + include ApplicationWorker + include ClusterQueue + + def perform(cluster_id, service_name) + cluster = Clusters::Cluster.find_by_id(cluster_id) + return unless cluster + + cluster.all_projects.find_each do |project| + project.find_or_initialize_service(service_name).update!(active: true) + end + end + end + end +end diff --git a/app/workers/clusters/applications/deactivate_service_worker.rb b/app/workers/clusters/applications/deactivate_service_worker.rb new file mode 100644 index 00000000000..2c560cc998c --- /dev/null +++ b/app/workers/clusters/applications/deactivate_service_worker.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Clusters + module Applications + class DeactivateServiceWorker + include ApplicationWorker + include ClusterQueue + + def perform(cluster_id, service_name) + cluster = Clusters::Cluster.find_by_id(cluster_id) + raise cluster_missing_error(service_name) unless cluster + + service = "#{service_name}_service".to_sym + cluster.all_projects.with_service(service).find_each do |project| + project.public_send(service).update!(active: false) # rubocop:disable GitlabSecurity/PublicSend + end + end + + def cluster_missing_error(service) + ActiveRecord::RecordNotFound.new("Can't deactivate #{service} services, host cluster not found! Some inconsistent records may be left in database.") + end + end + end +end diff --git a/app/workers/personal_access_tokens/expiring_worker.rb b/app/workers/personal_access_tokens/expiring_worker.rb new file mode 100644 index 00000000000..f28109c4583 --- /dev/null +++ b/app/workers/personal_access_tokens/expiring_worker.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module PersonalAccessTokens + class ExpiringWorker + include ApplicationWorker + include CronjobQueue + + feature_category :authentication_and_authorization + + def perform(*args) + notification_service = NotificationService.new + limit_date = PersonalAccessToken::DAYS_TO_EXPIRE.days.from_now.to_date + + User.with_expiring_and_not_notified_personal_access_tokens(limit_date).find_each do |user| + notification_service.access_token_about_to_expire(user) + + Rails.logger.info "#{self.class}: Notifying User #{user.id} about expiring tokens" # rubocop:disable Gitlab/RailsLogger + + user.personal_access_tokens.expiring_and_not_notified(limit_date).update_all(expire_notification_delivered: true) + end + end + end +end |