forked from securityroots/dradispro-scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_project_from_api.rb
52 lines (45 loc) · 1.62 KB
/
load_project_from_api.rb
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
# load_project_from_api.rb - Query a JSON API endpoint to gather Client and
# Project name and create matching Client and Project objects in Dradis.
#
# The script assums that the JSON API response is of the form:
# [
# {
# "client": "Kobol Consulting",
# "name": "Annual PCI assessment"
# },
# {
# "client": "12Colonies Ltd",
# "name": "Early Warning System code review"
# }
# ...
# ]
#
# Copyright (C) 2016 Security Roots Ltd.
#
# This file is part of the Dradis Pro Scripting Examples (DPSE) collection.
# The collection can be found at
# https://github.com/securityroots/dradispro-scripting
#
# DPSE free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# DPSE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DPSE. If not, see <http://www.gnu.org/licenses/>.
require 'open-uri'
projects_endpoint = 'http://localhost:8000/api/projects'
puts "Loading projects from remote server..."
projects = JSON.load(open(projects_endpoint))
puts projects
projects.each do |project|
puts "Adding #{project['client']}: #{project['name']}"
client = Client.find_or_create_by_name(project['client'])
project = client.projects.create name: project['name']
end
puts "Done."