Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-29 00:20:15 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-29 00:20:15 +0300
commit92d5172ad42ebc62eb78cac21b1e236ad6ace580 (patch)
treeca89437d4725caeb4e27682522061d3bab7e05b0 /app/finders
parentf4a969f7f495978a7e656c69c929c9fdac111cff (diff)
Add latest changes from gitlab-org/security/gitlab@13-3-stable-ee
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/ci/auth_job_finder.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/finders/ci/auth_job_finder.rb b/app/finders/ci/auth_job_finder.rb
new file mode 100644
index 00000000000..aee7dd16341
--- /dev/null
+++ b/app/finders/ci/auth_job_finder.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+module Ci
+ class AuthJobFinder
+ AuthError = Class.new(StandardError)
+ NotRunningJobError = Class.new(AuthError)
+ ErasedJobError = Class.new(AuthError)
+ DeletedProjectError = Class.new(AuthError)
+
+ def initialize(token:)
+ @token = token
+ end
+
+ def execute!
+ find_job_by_token.tap do |job|
+ next unless job
+
+ validate_job!(job)
+ end
+ end
+
+ def execute
+ execute!
+ rescue AuthError
+ end
+
+ private
+
+ attr_reader :token, :require_running, :raise_on_missing
+
+ def find_job_by_token
+ ::Ci::Build.find_by_token(token)
+ end
+
+ def validate_job!(job)
+ validate_running_job!(job)
+ validate_job_not_erased!(job)
+ validate_project_presence!(job)
+
+ true
+ end
+
+ def validate_running_job!(job)
+ raise NotRunningJobError, 'Job is not running' unless job.running?
+ end
+
+ def validate_job_not_erased!(job)
+ raise ErasedJobError, 'Job has been erased!' if job.erased?
+ end
+
+ def validate_project_presence!(job)
+ if job.project.nil? || job.project.pending_delete?
+ raise DeletedProjectError, 'Project has been deleted!'
+ end
+ end
+ end
+end