Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #134 from OpenCSPM/build
Browse files Browse the repository at this point in the history
Build
  • Loading branch information
joshlarsen authored Feb 24, 2021
2 parents bb23a0c + cb270cf commit 147224a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Load Support assets into RedisGraph
#
Expand Down
1 change: 1 addition & 0 deletions docker/app/jobs/runner_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def perform
puts "Processing results finished - #{guid}"

job.complete!
job.send_webhook
puts "Runner job finished - #{guid}"
rescue StandardError => e
job.failed!
Expand Down
11 changes: 8 additions & 3 deletions docker/app/models/campaign.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# frozen_string_literal: true

#
# Campaign
#
class Campaign < ApplicationRecord
belongs_to :user
before_save :update_control_count

validates :name, presence: true, length: { maximum: 120 }

#
# Return the Controls that match this Campaign's filters
#
Expand All @@ -24,9 +31,7 @@ def controls
# filters MAY have a Tags filter
controls = controls.where(tags: { name: tags_filter }) if tags_filter && !tags_filter.empty?
# filters MAY have "all" tags flag set
if must_have_all_tags
controls = controls.having('json_agg(tags.name)::jsonb @> ?::jsonb', tags_filter.to_s)
end
controls = controls.having('json_agg(tags.name)::jsonb @> ?::jsonb', tags_filter.to_s) if must_have_all_tags

controls
end
Expand Down
30 changes: 30 additions & 0 deletions docker/app/models/job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# frozen_string_literal: true

#
# Generic Job
#
class Job < ApplicationRecord
has_many :results

Expand All @@ -13,4 +18,29 @@ class Job < ApplicationRecord
parse: 3,
cleanup: 4
}, _prefix: :job

#
# Send an external webhook
#
def send_webhook
config = Rails.application.config_for(:webhooks)

return unless config.webhooks

config.webhooks.each do |_k, webhook|
next if webhook.nil?

url = URI(webhook)
headers = {'content-type' => 'application/json'}
payload = {
'job_id' => id,
'job_type' => kind,
'status' => status,
'results' => results.count
}.to_json
res = Net::HTTP.post(URI(url), payload, headers)

res.code
end
end
end
6 changes: 6 additions & 0 deletions docker/config/webhooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
development:
webhooks:
runner_job: <%= ENV['JOB_WEBHOOK_URL'] %>
production:
webhooks:
runner_job: <%= ENV['JOB_WEBHOOK_URL'] %>
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ x-app: &app
RAILS_ENV: ${RAILS_ENV:-production}
RAILS_SERVE_STATIC_FILES: 1
RAILS_LOG_TO_STDOUT: 1
image: gcr.io/opencspm/engine:0.1.17
image: gcr.io/opencspm/engine:0.1.18
tmpfs:
- /tmp

Expand Down

0 comments on commit 147224a

Please sign in to comment.