-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added export/import of SmartState Analysis Profiles
Fixes BZ #1344589
- Loading branch information
Julian Cheal
committed
May 18, 2018
1 parent
e915a3f
commit ab4105c
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module TaskHelpers | ||
class Exports | ||
class ScanProfiles | ||
def export(options = {}) | ||
export_dir = options[:directory] | ||
|
||
ScanItemSet.all.each do |p| | ||
next if p.read_only | ||
next if p.members.map { |m| m.slice(:filename) } | ||
|
||
$log.send(level, "Exporting Scan Profile: #{p.name} (#{p.description})") | ||
|
||
profile = ScanItem.get_profile(p.name).first.dup | ||
|
||
%w(id created_on updated_on).each { |k| profile.delete(k) } | ||
profile['definition'].each do |dd| | ||
%w(id created_on updated_on description).each { |k| dd.delete(k) } | ||
end | ||
|
||
scan_profile = profile.to_yaml | ||
|
||
file = Exports.safe_filename(p.name, options[:keep_spaces]) | ||
File.write("#{export_dir}/ScanProfile_#{file}.yaml", scan_profile) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module TaskHelpers | ||
class Imports | ||
class ScanProfiles | ||
def import(options) | ||
return unless options[:source] | ||
|
||
glob = File.file?(options[:source]) ? options[:source] : "#{options[:source]}/ScanProfile_*.yaml" | ||
Dir.glob(glob) do |filename| | ||
begin | ||
import_scan_profile(filename) | ||
rescue => e | ||
$stderr.puts "Error importing #{filename} : #{e.message}" | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def import_scan_profile(filename) | ||
scan_profiles = YAML.load_file(filename) | ||
items = scan_profiles.delete("definition") | ||
|
||
profile = ScanItemSet.find_by(:name => scan_profiles["name"]) | ||
|
||
if profile.nil? | ||
if scan_profiles["guid"].nil? | ||
scan_profiles["guid"] = SecureRandom.uuid | ||
end | ||
profile = ScanItemSet.new(scan_profiles) | ||
else | ||
profile.attributes = scan_profiles | ||
end | ||
profile.save! | ||
|
||
items.each do |item| | ||
next if item['filename'] | ||
if item['guid'].nil? | ||
item['guid'] = SecureRandom.uuid | ||
end | ||
scan_item = ScanItem.create(item) | ||
profile.add_member(scan_item) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters