7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/google_cloud_run/jobs_controller.rb', line 7
def callback
return head :bad_request unless request.user_agent == "Google-Cloud-Tasks"
return head :bad_request unless request.["Content-type"].include?("application/json")
return head :bad_request unless request.["Authorization"].start_with?("Bearer")
begin
r = Google::Auth::IDTokens.verify_oidc request.["Authorization"]&.delete_prefix("Bearer")&.strip
rescue => e
Rails.logger.warning "Google Cloud Run Job callback failed: #{e.message}"
return head :bad_request
end
begin
body = JSON.parse(request.body.read)
rescue => e
raise "Google Cloud Run Job callback failed: Unable to parse JSON body: #{e.message}"
end
ActiveJob::Base.execute body
head :ok
end
|