debian-mirror-gitlab/app/finders/ci/auth_job_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.2 KiB
Ruby
Raw Normal View History

2020-09-03 11:15:55 +05:30
# 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)
2021-09-04 01:27:46 +05:30
2022-01-26 12:08:38 +05:30
if job.user
2021-09-04 01:27:46 +05:30
job.user.set_ci_job_token_scope!(job)
end
2020-09-03 11:15:55 +05:30
end
end
def execute
execute!
rescue AuthError
end
private
2022-08-13 15:12:31 +05:30
attr_reader :token
2020-09-03 11:15:55 +05:30
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