-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(APIv2): expose the TOML format of the tailoring_file
- Loading branch information
Showing
12 changed files
with
152 additions
and
21 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
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
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
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module V2 | ||
# Factory for selecting the right tailoring file format | ||
class TailoringFile | ||
def self.new(format: :xml, **hsh) | ||
return super if self != V2::TailoringFile | ||
|
||
case format | ||
when :json | ||
JsonTailoringFile.new(**hsh) | ||
when :toml | ||
TomlTailoringFile.new(**hsh) | ||
when :xml | ||
XccdfTailoringFile.new(**hsh) | ||
end | ||
end | ||
|
||
def filename | ||
"#{@tailoring.security_guide.ref_id}__#{@tailoring.profile.ref_id}__tailoring.#{extension}" | ||
end | ||
|
||
def empty? | ||
false | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'deep_merge' | ||
|
||
module V2 | ||
# A class representing a TOML Tailoring File | ||
class TomlTailoringFile < TailoringFile | ||
def initialize(profile:, **_hsh) | ||
@tailoring = profile | ||
end | ||
|
||
def mime | ||
'application/toml' | ||
end | ||
|
||
def extension | ||
'toml' | ||
end | ||
|
||
def output | ||
TOML::Generator.new(build_profile).body | ||
end | ||
|
||
private | ||
|
||
def build_profile | ||
{ | ||
'name' => @tailoring.profile.title, | ||
'description' => @tailoring.profile.description, | ||
'version' => @tailoring.profile.security_guide.version | ||
}.merge(build_fixes) | ||
end | ||
|
||
def build_fixes | ||
V2::Fix.where(rule: @tailoring.rules, system: V2::Fix::BLUEPRINT).reduce({}) do |obj, fix| | ||
obj.deep_merge(TOML.load(fix.text)) | ||
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
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,5 @@ | ||
class ResetDatastreamsFixes < ActiveRecord::Migration[7.1] | ||
def up | ||
Revision.find_by(name: 'datastreams')&.delete | ||
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