Skip to content

Commit

Permalink
Merge pull request #678 from chef/sersut/fatal-licensing
Browse files Browse the repository at this point in the history
Add :fatal_licensing_warnings configuration option
  • Loading branch information
Serdar Sutay committed May 17, 2016
2 parents 7c98e2b + ee98f4a commit ea5273b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/omnibus/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def reset!
#
# For example:
#
# /PATH/files/my_map_file
# /PATH/files/my_map_file
#
# @return [String, nil]
default(:solaris_linker_mapfile, "files/mapfiles/solaris")
Expand Down Expand Up @@ -509,6 +509,11 @@ def reset!
end
end

# Fail the build or warn when build encounters a licensing warning.
#
# @return [true, false]
default(:fatal_licensing_warnings, false)

# --------------------------------------------------
# @!endgroup
#
Expand Down
16 changes: 16 additions & 0 deletions lib/omnibus/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,20 @@ def initialize
super("Failed to sign Windows Package.")
end
end

class LicensingError < Error
def initialize(errors)
@errors = errors
end

def to_s
<<-EOH
Encountered error(s) with project's licensing information.
Failing the build because :fatal_licensing_warnings is set in the configuration.
Error(s):
#{@errors.join("\n ")}
EOH
end
end
end
33 changes: 30 additions & 3 deletions lib/omnibus/licensing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ def create!(project)
#
attr_reader :project

#
# The warnings encountered while preparing the licensing information
#
# @return [Array<String>]
#
attr_reader :licensing_warnings

#
# @param [Project] project
# the project to create licenses for.
#
def initialize(project)
@project = project
@licensing_warnings = []
end

#
Expand All @@ -59,6 +67,10 @@ def create!
validate_license_info
create_software_license_files
create_project_license_file

if Config.fatal_licensing_warnings && !licensing_warnings.empty?
raise LicensingError.new(licensing_warnings)
end
end

#
Expand Down Expand Up @@ -92,7 +104,7 @@ def validate_license_info

# Check used license is a standard license
if project.license != "Unspecified" && !STANDARD_LICENSES.include?(project.license)
licensing_warning("Project '#{project.name}' is using '#{project.license}' which is not one of the standard licenses identified in https://opensource.org/licenses/alphabetical. Consider using one of the standard licenses.")
licensing_info("Project '#{project.name}' is using '#{project.license}' which is not one of the standard licenses identified in https://opensource.org/licenses/alphabetical. Consider using one of the standard licenses.")
end

# Now let's check the licensing info for software components
Expand All @@ -109,7 +121,7 @@ def validate_license_info

# Check if the software license is one of the standard licenses
if license_info[:license] != "Unspecified" && !STANDARD_LICENSES.include?(license_info[:license])
licensing_warning("Software '#{software_name}' uses license '#{license_info[:license]}' which is not one of the standard licenses identified in https://opensource.org/licenses/alphabetical. Consider using one of the standard licenses.")
licensing_info("Software '#{software_name}' uses license '#{license_info[:license]}' which is not one of the standard licenses identified in https://opensource.org/licenses/alphabetical. Consider using one of the standard licenses.")
end
end
end
Expand Down Expand Up @@ -294,11 +306,26 @@ def local?(license)
end

#
# Logs the given message as warning.
# Logs the given message as info.
#
# This method should only be used for detecting in a license is known or not.
# In the future, we will introduce a configurable way to whitelist or blacklist
# the allowed licenses. Once we implement that we need to stop using this method.
#
# @param [String] message
# message to log as warning
def licensing_info(message)
log.info(log_key) { message }
end

#
# Logs the given message as warning or fails the build depending on the
# :fatal_licensing_warnings configuration setting.
#
# @param [String] message
# message to log as warning
def licensing_warning(message)
licensing_warnings << message
log.warn(log_key) { message }
end

Expand Down
10 changes: 10 additions & 0 deletions spec/functional/licensing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,15 @@ def create_licenses
expect(output).to include("Project 'test-project' does not point to a license file.")
end
end

describe "with :fatal_licensing_warnings set and without license definitions in the project" do
before do
Omnibus::Config.fatal_licensing_warnings(true)
end

it "fails the omnibus build" do
expect{create_licenses}.to raise_error(Omnibus::LicensingError, /Project 'test-project' does not contain licensing information.\s{1,}Software 'private_code' does not contain licensing information./)
end
end
end
end
1 change: 1 addition & 0 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module Omnibus
include_examples 'a configurable', :use_git_caching, true
include_examples 'a configurable', :fetcher_read_timeout, 60
include_examples 'a configurable', :fetcher_retries, 5
include_examples 'a configurable', :fatal_licensing_warnings, false

describe '#workers' do
context 'when the Ohai data is not present' do
Expand Down

0 comments on commit ea5273b

Please sign in to comment.