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

Commit 147224a

Browse files
authored
Merge pull request #134 from OpenCSPM/build
Build
2 parents bb23a0c + cb270cf commit 147224a

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

docker/app/jobs/lib/loader/asset/loaders/aws_loader/support.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#
24
# Load Support assets into RedisGraph
35
#

docker/app/jobs/runner_job.rb

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def perform
8181
puts "Processing results finished - #{guid}"
8282

8383
job.complete!
84+
job.send_webhook
8485
puts "Runner job finished - #{guid}"
8586
rescue StandardError => e
8687
job.failed!

docker/app/models/campaign.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Campaign
5+
#
16
class Campaign < ApplicationRecord
27
belongs_to :user
38
before_save :update_control_count
49

10+
validates :name, presence: true, length: { maximum: 120 }
11+
512
#
613
# Return the Controls that match this Campaign's filters
714
#
@@ -24,9 +31,7 @@ def controls
2431
# filters MAY have a Tags filter
2532
controls = controls.where(tags: { name: tags_filter }) if tags_filter && !tags_filter.empty?
2633
# filters MAY have "all" tags flag set
27-
if must_have_all_tags
28-
controls = controls.having('json_agg(tags.name)::jsonb @> ?::jsonb', tags_filter.to_s)
29-
end
34+
controls = controls.having('json_agg(tags.name)::jsonb @> ?::jsonb', tags_filter.to_s) if must_have_all_tags
3035

3136
controls
3237
end

docker/app/models/job.rb

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Generic Job
5+
#
16
class Job < ApplicationRecord
27
has_many :results
38

@@ -13,4 +18,29 @@ class Job < ApplicationRecord
1318
parse: 3,
1419
cleanup: 4
1520
}, _prefix: :job
21+
22+
#
23+
# Send an external webhook
24+
#
25+
def send_webhook
26+
config = Rails.application.config_for(:webhooks)
27+
28+
return unless config.webhooks
29+
30+
config.webhooks.each do |_k, webhook|
31+
next if webhook.nil?
32+
33+
url = URI(webhook)
34+
headers = {'content-type' => 'application/json'}
35+
payload = {
36+
'job_id' => id,
37+
'job_type' => kind,
38+
'status' => status,
39+
'results' => results.count
40+
}.to_json
41+
res = Net::HTTP.post(URI(url), payload, headers)
42+
43+
res.code
44+
end
45+
end
1646
end

docker/config/webhooks.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
development:
2+
webhooks:
3+
runner_job: <%= ENV['JOB_WEBHOOK_URL'] %>
4+
production:
5+
webhooks:
6+
runner_job: <%= ENV['JOB_WEBHOOK_URL'] %>

docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ x-app: &app
66
RAILS_ENV: ${RAILS_ENV:-production}
77
RAILS_SERVE_STATIC_FILES: 1
88
RAILS_LOG_TO_STDOUT: 1
9-
image: gcr.io/opencspm/engine:0.1.17
9+
image: gcr.io/opencspm/engine:0.1.18
1010
tmpfs:
1111
- /tmp
1212

0 commit comments

Comments
 (0)