-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgraphql_build.rb
More file actions
69 lines (59 loc) · 1.98 KB
/
graphql_build.rb
File metadata and controls
69 lines (59 loc) · 1.98 KB
1
2
3
4
5
6
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
require_relative 'printer'
require 'json'
require 'yaml'
require 'faraday'
require 'tempfile'
module GraphqlBuild
include Printer
def submit_report(report)
response = create_notification(report)
report[:evidence_temp].close
report[:evidence_temp].unlink
data = JSON.parse(response.body)
if response.status == 200 && data['errors'].nil?
{
sent: true,
message: "The notification '#{report[:matcher_name]}' was created LINK: #{mount_link(data)}"
}
else
{
sent: false,
message: "The template '#{report[:matcher_name]}' has errors #{data['errors']}"
}
end
end
def mount_link(data)
"#{@opts.host}/scopes/#{data['data']['createNotification']['notification']['companyId']}/projects/#{data['data']['createNotification']['notification']['projectId']}/occurrences/#{data['data']['createNotification']['notification']['id']}"
end
def create_notification(report)
query = {
"query": '''
mutation($input: CreateNotificationInput!) {
createNotification(input: $input) {
errors notification {
companyId
projectId
id
}
}
}
''',
"variables": {
"input": {
projectId: @opts.project_id.to_i,
vulnerabilityTemplateId: report[:vid].to_i,
description: report[:description],
evidenceArchives: [nil]
}
},
"operationName": nil
}
payload = {
operations: query.to_json,
map: '{"0":["variables.input.evidenceArchives.0"]}',
'0': Faraday::UploadIO.new(report[:evidence_temp].open, "text/plain")
}
@opts.client.post('/graphql', payload)
end
end