Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chores: renovate deps & add CI #18

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true
- run: |
sudo apt-get update
sudo apt-get -y install libopenscap8
- run: |
bundle install
- run: |
./runtest.sh
29 changes: 20 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
inherit_from:
- .rubocop_todo.yml

require:
- rubocop-performance
- rubocop-thread_safety

AllCops:
NewCops: enable
TargetRubyVersion: 3.2.2
AllowSymlinksInCacheRootDirectory: true
SuggestExtensions:
rubocop-rake: false

Metrics/AbcSize:
Max: 16
Exclude:
- 'test/**/*'

Metrics/LineLength:
Layout/LineLength:
Max: 110
Exclude:
- 'test/**/*'

Lint/FloatComparison:
Exclude:
- 'test/**/*'

Metrics/MethodLength:
Max: 13
Exclude:
- 'test/**/*'

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/SymbolArray:
EnforcedStyle: brackets
Naming/MethodParameterName:
Enabled: false

Naming/UncommunicativeMethodParamName:
Exclude:
- '**/*'
Gemspec/RequireMFA:
Enabled: false
13 changes: 13 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

group :development do
gem 'rake'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-thread_safety'
gem 'test-unit'
end
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A FFI wrapper around the OpenSCAP library.

Features/problems
-------------
Current version supports minimal set of functions needed to build own scanner. This module
Current version supports minimal set of functions needed to build own scanner. This gem
is self documented by its test suite.

Sample Scanner Implementation
Expand All @@ -23,28 +23,17 @@ Sample Scanner Implementation

Development Requirements
-------------
On Fedora, command is
On Fedora, commands are

dnf install ruby-devel rubygem-rake rubygem-ffi rubygem-bundler openscap

On RHEL you can install requirements by issuing

yum install ruby-devel rubygem-rake rubygem-bundler openscap
gem install ffi # or install rubygem-ffi RPM package from EPEL
dnf install openscap
bundle install


Test Requirements
-------------
On Fedora, more packages are necessary, but rubocop can be of the latest version

dnf install rubygem-minitest rubygem-test-unit rubygems-devel bzip2
gem install rubocop

For tests on RHEL7, you need minitest package and specific older version of rubocop.
Newer versions of rubocop requires Ruby >= 2.1.0

yum install rubygem-minitest bzip2
gem install rubocop -v 0.50.0
dnf install bzip2

Tests are then performed using script

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

require 'bundler'

Bundler::GemHelper.install_tasks :name => 'openscap'
Bundler::GemHelper.install_tasks name: 'openscap'

task :test do
$LOAD_PATH.unshift('lib')
$LOAD_PATH.unshift('test')
Dir.glob('./test/**/*_test.rb') { |f| require f }
Dir.glob('./test/**/*_test.rb').each { |f| require f }
end
6 changes: 3 additions & 3 deletions lib/openscap/ds/arf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def html

attach_function :ds_rds_session_new_from_source, [:pointer], :pointer
attach_function :ds_rds_session_free, [:pointer], :void
attach_function :ds_rds_session_select_report, [:pointer, :string], :pointer
attach_function :ds_rds_session_replace_report_with_source, [:pointer, :pointer], :int
attach_function :ds_rds_session_select_report_request, [:pointer, :string], :pointer
attach_function :ds_rds_session_select_report, %i[pointer string], :pointer
attach_function :ds_rds_session_replace_report_with_source, %i[pointer pointer], :int
attach_function :ds_rds_session_select_report_request, %i[pointer string], :pointer
attach_function :ds_rds_session_get_html_report, [:pointer], :pointer
end
4 changes: 2 additions & 2 deletions lib/openscap/ds/sds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def destroy

attach_function :ds_sds_session_new_from_source, [:pointer], :pointer
attach_function :ds_sds_session_free, [:pointer], :void
attach_function :ds_sds_session_select_checklist, [:pointer, :string, :string, :string], :pointer
attach_function :ds_sds_session_get_html_guide, [:pointer, :string], :string
attach_function :ds_sds_session_select_checklist, %i[pointer string string string], :pointer
attach_function :ds_sds_session_get_html_guide, %i[pointer string], :string
end
8 changes: 4 additions & 4 deletions lib/openscap/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def create_from_memory(param)
end

attach_function :oscap_source_new_from_file, [:string], :pointer
attach_function :oscap_source_new_from_memory, [:pointer, :int, :string], :pointer
attach_function :oscap_source_new_from_memory, %i[pointer int string], :pointer
attach_function :oscap_source_get_scap_type, [:pointer], :int
attach_function :oscap_source_free, [:pointer], :void
attach_function :oscap_source_save_as, [:pointer, :string], :int
attach_function :oscap_source_save_as, %i[pointer string], :int

callback :xml_reporter, [:string, :int, :string, :pointer], :int
attach_function :oscap_source_validate, [:pointer, :xml_reporter, :pointer], :int
callback :xml_reporter, %i[string int string pointer], :int
attach_function :oscap_source_validate, %i[pointer xml_reporter pointer], :int
XmlReporterCallback = proc do |filename, line_number, error_message, e|
offset = e.get_string(0).length
msg = "#{filename}:#{line_number}: #{error_message}"
Expand Down
4 changes: 2 additions & 2 deletions lib/openscap/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def destroy
end

attach_function :oscap_text_new, [], :pointer
attach_function :oscap_text_set_text, [:pointer, :string], :bool
attach_function :oscap_text_set_text, %i[pointer string], :bool
attach_function :oscap_text_get_text, [:pointer], :string
attach_function :oscap_text_free, [:pointer], :void

attach_function :oscap_textlist_get_preferred_plaintext, [:pointer, :string], :string
attach_function :oscap_textlist_get_preferred_plaintext, %i[pointer string], :string
attach_function :oscap_text_iterator_free, [:pointer], :void
end
2 changes: 1 addition & 1 deletion lib/openscap/xccdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module OpenSCAP
module Xccdf
NUMERIC = :float

class Item
class Item # rubocop:disable Lint/EmptyClass
end
end
end
8 changes: 4 additions & 4 deletions lib/openscap/xccdf/fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def content

def to_hash
{
:id => id,
:platform => platform,
:system => fix_system,
:content => content
id:,
platform:,
system: fix_system,
content:
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/openscap/xccdf/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.build(t)
end

def initialize(t)
if self.class == OpenSCAP::Xccdf::Item
if instance_of?(OpenSCAP::Xccdf::Item)
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} abstract base class."
end

Expand Down
6 changes: 3 additions & 3 deletions lib/openscap/xccdf/reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def html_link

def to_hash
{
:title => title,
:href => href,
:html_link => html_link
title:,
href:,
html_link:
}
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/openscap/xccdf/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class Rule < Item
def severity
severity = OpenSCAP.xccdf_rule_get_severity(@raw)
severity_mapping = {
:xccdf_level_not_defined => 'Not defined',
:xccdf_unknown => 'Unknown',
:xccdf_info => 'Info',
:xccdf_low => 'Low',
:xccdf_medium => 'Medium',
:xccdf_high => 'High'
xccdf_level_not_defined: 'Not defined',
xccdf_unknown: 'Unknown',
xccdf_info: 'Info',
xccdf_low: 'Low',
xccdf_medium: 'Medium',
xccdf_high: 'High'
}
severity_mapping[severity] || severity_mapping[:xccdf_unknown]
end
Expand Down
36 changes: 18 additions & 18 deletions lib/openscap/xccdf/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def sds?

def load(opts = {})
o = {
:datastream_id => nil,
:component_id => nil
datastream_id: nil,
component_id: nil
}.merge(opts)
if sds?
OpenSCAP.xccdf_session_set_datastream_id(@s, o[:datastream_id])
Expand All @@ -31,7 +31,7 @@ def load(opts = {})
def profile=(p)
@profile = p
if OpenSCAP.xccdf_session_set_profile_id(@s, p) == false
raise OpenSCAPError, "No profile '" + p + "' found"
raise OpenSCAPError, "No profile '#{p}' found"
end
end

Expand All @@ -45,12 +45,12 @@ def remediate

def export_results(opts = {})
o = {
:rds_file => nil,
:xccdf_file => nil,
:report_file => nil,
:oval_results => false,
:oval_variables => false,
:engines_results => false
rds_file: nil,
xccdf_file: nil,
report_file: nil,
oval_results: false,
oval_variables: false,
engines_results: false
}.merge!(opts)
export_targets o
export
Expand Down Expand Up @@ -94,13 +94,13 @@ def export_targets(opts = {})

attach_function :xccdf_session_is_sds, [:pointer], :bool

attach_function :xccdf_session_set_profile_id, [:pointer, :string], :bool
attach_function :xccdf_session_set_datastream_id, [:pointer, :string], :void
attach_function :xccdf_session_set_component_id, [:pointer, :string], :void
attach_function :xccdf_session_set_arf_export, [:pointer, :string], :bool
attach_function :xccdf_session_set_xccdf_export, [:pointer, :string], :bool
attach_function :xccdf_session_set_report_export, [:pointer, :string], :bool
attach_function :xccdf_session_set_oval_variables_export, [:pointer, :bool], :void
attach_function :xccdf_session_set_oval_results_export, [:pointer, :bool], :void
attach_function :xccdf_session_set_check_engine_plugins_results_export, [:pointer, :bool], :void
attach_function :xccdf_session_set_profile_id, %i[pointer string], :bool
attach_function :xccdf_session_set_datastream_id, %i[pointer string], :void
attach_function :xccdf_session_set_component_id, %i[pointer string], :void
attach_function :xccdf_session_set_arf_export, %i[pointer string], :bool
attach_function :xccdf_session_set_xccdf_export, %i[pointer string], :bool
attach_function :xccdf_session_set_report_export, %i[pointer string], :bool
attach_function :xccdf_session_set_oval_variables_export, %i[pointer bool], :void
attach_function :xccdf_session_set_oval_results_export, %i[pointer bool], :void
attach_function :xccdf_session_set_check_engine_plugins_results_export, %i[pointer bool], :void
end
2 changes: 1 addition & 1 deletion lib/openscap/xccdf/tailoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def profiles_init
end
end

attach_function :xccdf_tailoring_import_source, [:pointer, :pointer], :pointer
attach_function :xccdf_tailoring_import_source, %i[pointer pointer], :pointer
attach_function :xccdf_tailoring_free, [:pointer], :void

attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer
Expand Down
13 changes: 6 additions & 7 deletions lib/openscap/xccdf/testresult.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
module OpenSCAP
module Xccdf
class TestResult
attr_reader :rr
attr_reader :raw
attr_reader :rr, :raw

def initialize(t)
case t
Expand Down Expand Up @@ -73,9 +72,9 @@ def score_init
while OpenSCAP.xccdf_score_iterator_has_more(scorit)
s = OpenSCAP.xccdf_score_iterator_next(scorit)
scores[OpenSCAP.xccdf_score_get_system(s)] = {
:system => OpenSCAP.xccdf_score_get_system(s),
:value => OpenSCAP.xccdf_score_get_score(s),
:max => OpenSCAP.xccdf_score_get_maximum(s)
system: OpenSCAP.xccdf_score_get_system(s),
value: OpenSCAP.xccdf_score_get_score(s),
max: OpenSCAP.xccdf_score_get_maximum(s)
}
end
OpenSCAP.xccdf_score_iterator_free(scorit)
Expand All @@ -88,8 +87,8 @@ def score_init
attach_function :xccdf_result_free, [:pointer], :void
attach_function :xccdf_result_get_id, [:pointer], :string
attach_function :xccdf_result_get_profile, [:pointer], :string
attach_function :xccdf_result_recalculate_scores, [:pointer, :pointer], :int
attach_function :xccdf_result_export_source, [:pointer, :string], :pointer
attach_function :xccdf_result_recalculate_scores, %i[pointer pointer], :int
attach_function :xccdf_result_export_source, %i[pointer string], :pointer

attach_function :xccdf_result_get_rule_results, [:pointer], :pointer
attach_function :xccdf_rule_result_iterator_has_more, [:pointer], :bool
Expand Down
5 changes: 2 additions & 3 deletions openscap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require File.expand_path('lib/openscap/version', __dir__)
GEMSPEC = Gem::Specification.new do |gem|
gem.name = 'openscap'
gem.version = OpenSCAP::VERSION
gem.date = Date.today.to_s
gem.platform = Gem::Platform::RUBY
gem.required_ruby_version = '>= 3.2.2'

gem.author = 'Simon Lukasik'
gem.email = '[email protected]'
Expand All @@ -18,8 +18,7 @@ GEMSPEC = Gem::Specification.new do |gem|
gem.description = "A FFI wrapper around the OpenSCAP library.
Currently it provides only subset of libopenscap functionality."

gem.add_development_dependency 'bundler', '>=1.0.0'
gem.add_runtime_dependency 'ffi', '>= 1.0.9'
gem.add_runtime_dependency 'ffi', '~> 1.15.5'

gem.files = Dir['{lib,test}/**/*'] + ['COPYING', 'README.md', 'Rakefile']
gem.require_path = 'lib'
Expand Down
7 changes: 4 additions & 3 deletions runtest.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
set -e -o pipefail
set -x

rm -f openscap-*.gem
gem build openscap.gemspec
gem install openscap-*.gem
rake test
rubocop
#gem install openscap-*.gem
bundle exec rake test
bundle exec rubocop
Loading