license-acceptance 1.0.18 → 1.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 857078f9f2d4c9d74fcb5a08876039fa5930c3f7286b1a7d03e2a84bda4d229b
4
- data.tar.gz: c7c4d34ac946733f0f980f33d1b5fd0dd518e1c8fc1927a9a406580f3ac491c0
3
+ metadata.gz: 8383c0bafd2717c7ff9f2af1b0cc6a28b83acb5001150249734e4194a927297a
4
+ data.tar.gz: 798ba0cdf60a7bd4e6ca8b680eeec5039eeca8caff3a993e48d3fded2875fa37
5
5
  SHA512:
6
- metadata.gz: c813cf96544c839b605631e587cad4ee3e798d6950022f454e417ac5f83234e969418f0d500f69ee730a102a046e5f20bf97782582fde203d58815d9dae30c9a
7
- data.tar.gz: 6b497916918c9537c1cc234e6abace8ed448713640ac937b34593a8ac69b93bec72cfe4cca184514b4fe667203c5ec9af1546b1dcaf696a23d3318a47c37b4dd
6
+ metadata.gz: df6e3ccef39dcfef85a6928954cd76d2b9e3ce574291a92f368080fe1594a56b9e30fe5a43ad224994b17ce930bc21cf21a5b2dbdfb3e877e267715ef6ac200e
7
+ data.tar.gz: 98a5f5e51bf72821399458d4c07f9acc6c0ba69eafe748c8d0bb34c60fec62fe06582430a4cce829fdf6bbef9c1a21b3c7ddb9df4367645410ff6af8fa5134f2
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in license-acceptance.gemspec
6
6
  gemspec
@@ -11,9 +11,9 @@ require "license_acceptance/strategy/provided_value"
11
11
 
12
12
  module LicenseAcceptance
13
13
 
14
- ACCEPT = "accept"
15
- ACCEPT_SILENT = "accept-silent"
16
- ACCEPT_NO_PERSIST = "accept-no-persist"
14
+ ACCEPT = "accept".freeze
15
+ ACCEPT_SILENT = "accept-silent".freeze
16
+ ACCEPT_NO_PERSIST = "accept-no-persist".freeze
17
17
 
18
18
  class Acceptor
19
19
  extend Forwardable
@@ -21,7 +21,7 @@ module LicenseAcceptance
21
21
 
22
22
  attr_reader :config, :product_reader, :env_strategy, :file_strategy, :arg_strategy, :prompt_strategy, :provided_strategy
23
23
 
24
- def initialize(opts={})
24
+ def initialize(opts = {})
25
25
  @config = Config.new(opts)
26
26
  Logger.initialize(config.logger)
27
27
  @product_reader = ProductReader.new
@@ -74,28 +74,28 @@ module LicenseAcceptance
74
74
  end
75
75
  end
76
76
  @acceptance_value = accepted_silent? ? ACCEPT_SILENT : ACCEPT
77
- return true
77
+ true
78
78
  elsif config.output.isatty && prompt_strategy.request(missing_licenses) do
79
79
  # We have to infer the acceptance value if they use the prompt to accept
80
- if config.persist
81
- @acceptance_value = ACCEPT
82
- file_strategy.persist(product_relationship, missing_licenses)
83
- else
84
- @acceptance_value = ACCEPT_NO_PERSIST
85
- []
86
- end
80
+ if config.persist
81
+ @acceptance_value = ACCEPT # rubocop: disable Lint/AssignmentInCondition
82
+ file_strategy.persist(product_relationship, missing_licenses)
83
+ else
84
+ @acceptance_value = ACCEPT_NO_PERSIST # rubocop: disable Lint/AssignmentInCondition
85
+ []
87
86
  end
88
- return true
87
+ end
88
+ true
89
89
  else
90
90
  raise LicenseNotAcceptedError.new(product_relationship.parent, missing_licenses)
91
91
  end
92
92
  end
93
93
 
94
- def self.check_and_persist!(product_id, version, opts={})
94
+ def self.check_and_persist!(product_id, version, opts = {})
95
95
  new(opts).check_and_persist!(product_id, version)
96
96
  end
97
97
 
98
- def self.check_and_persist(product_id, version, opts={})
98
+ def self.check_and_persist(product_id, version, opts = {})
99
99
  new(opts).check_and_persist(product_id, version)
100
100
  end
101
101
 
@@ -105,7 +105,8 @@ module LicenseAcceptance
105
105
  return false if product.nil?
106
106
  # If they don't pass a version we assume they want latest
107
107
  # All versions in all channels require license acceptance
108
- return true if ["latest", "unstable", "current", "stable"].include?(version.to_s) || version.nil?
108
+ return true if %w{latest unstable current stable}.include?(version.to_s) || version.nil?
109
+
109
110
  Gem::Version.new(version) >= Gem::Version.new(product.license_required_version)
110
111
  end
111
112
 
@@ -114,6 +115,7 @@ module LicenseAcceptance
114
115
  def id_from_mixlib(mixlib_name)
115
116
  product = product_reader.lookup_by_mixlib(mixlib_name)
116
117
  return nil if product.nil?
118
+
117
119
  product.id
118
120
  end
119
121
 
@@ -141,20 +143,20 @@ module LicenseAcceptance
141
143
  # In the case where users accept with a command line argument or environment variable
142
144
  # we still want to output the fact that the filesystem was changed.
143
145
  def output_num_persisted(count)
144
- s = count > 1 ? "s": ""
146
+ s = count > 1 ? "s" : ""
145
147
  output.puts <<~EOM
146
- #{Strategy::Prompt::BORDER}
147
- #{Strategy::Prompt::CHECK} #{count} product license#{s} accepted.
148
- #{Strategy::Prompt::BORDER}
148
+ #{Strategy::Prompt::BORDER}
149
+ #{Strategy::Prompt::CHECK} #{count} product license#{s} accepted.
150
+ #{Strategy::Prompt::BORDER}
149
151
  EOM
150
152
  end
151
153
 
152
154
  def output_persist_failed(errs)
153
155
  output.puts <<~EOM
154
- #{Strategy::Prompt::BORDER}
155
- #{Strategy::Prompt::CHECK} Product license accepted.
156
- Could not persist acceptance:\n\t* #{errs.map(&:message).join("\n\t* ")}
157
- #{Strategy::Prompt::BORDER}
156
+ #{Strategy::Prompt::BORDER}
157
+ #{Strategy::Prompt::CHECK} Product license accepted.
158
+ Could not persist acceptance:\n\t* #{errs.map(&:message).join("\n\t* ")}
159
+ #{Strategy::Prompt::BORDER}
158
160
  EOM
159
161
  end
160
162
 
@@ -1,5 +1,5 @@
1
1
  begin
2
- require 'mixlib/cli'
2
+ require "mixlib/cli"
3
3
  rescue => exception
4
4
  raise "Must have mixlib-cli gem installed to use this mixin"
5
5
  end
@@ -1,5 +1,5 @@
1
1
  begin
2
- require 'thor'
2
+ require "thor"
3
3
  rescue => exception
4
4
  raise "Must have thor gem installed to use this mixin"
5
5
  end
@@ -12,7 +12,7 @@ module LicenseAcceptance
12
12
  def self.included(klass)
13
13
  klass.class_option :chef_license,
14
14
  type: :string,
15
- desc: 'Accept the license for this product and any contained products: accept, accept-no-persist, accept-silent'
15
+ desc: "Accept the license for this product and any contained products: accept, accept-no-persist, accept-silent"
16
16
  end
17
17
 
18
18
  end
@@ -1,10 +1,10 @@
1
- require 'logger'
1
+ require "logger"
2
2
 
3
3
  module LicenseAcceptance
4
4
  class Config
5
5
  attr_accessor :output, :logger, :license_locations, :persist_location, :persist
6
6
 
7
- def initialize(opts={})
7
+ def initialize(opts = {})
8
8
  @output = opts.fetch(:output, $stdout)
9
9
  @logger = opts.fetch(:logger, ::Logger.new(IO::NULL))
10
10
  @license_locations = opts.fetch(:license_locations, default_license_locations)
@@ -21,7 +21,7 @@ module LicenseAcceptance
21
21
 
22
22
  def default_license_locations
23
23
  if windows?
24
- root = ENV.fetch("SYSTEMDRIVE","C:")
24
+ root = ENV.fetch("SYSTEMDRIVE", "C:")
25
25
  l = [ File.join(root, "chef/accepted_licenses/") ]
26
26
  unless is_root?
27
27
  # Look through a list of possible user locations and pick the first one that exists
@@ -32,6 +32,7 @@ module LicenseAcceptance
32
32
  possible_dirs << ENV["HOMESHARE"] + ENV["HOMEPATH"] if ENV["HOMESHARE"] && ENV["HOMEPATH"]
33
33
  possible_dirs << ENV["USERPROFILE"] if ENV["USERPROFILE"]
34
34
  raise NoValidEnvironmentVar if possible_dirs.empty?
35
+
35
36
  possible_dirs.each do |possible_dir|
36
37
  if Dir.exist?(possible_dir)
37
38
  full_possible_dir = File.join(possible_dir, ".chef/accepted_licenses/")
@@ -42,7 +43,7 @@ module LicenseAcceptance
42
43
  end
43
44
  else
44
45
  l = [ "/etc/chef/accepted_licenses/" ]
45
- l << File.join(ENV['HOME'], ".chef/accepted_licenses/") unless is_root?
46
+ l << File.join(ENV["HOME"], ".chef/accepted_licenses/") unless is_root?
46
47
  end
47
48
  l
48
49
  end
@@ -14,14 +14,15 @@ module LicenseAcceptance
14
14
 
15
15
  def ==(other)
16
16
  return false if other.class != Product
17
+
17
18
  if other.id == id &&
18
- other.pretty_name == pretty_name &&
19
- other.filename == filename &&
20
- other.mixlib_name == mixlib_name
21
- other.license_required_version == license_required_version
22
- return true
19
+ other.pretty_name == pretty_name &&
20
+ other.filename == filename &&
21
+ other.mixlib_name == mixlib_name
22
+ other.license_required_version == license_required_version
23
+ return true
23
24
  end
24
- return false
25
+ false
25
26
  end
26
27
 
27
28
  end
@@ -18,7 +18,7 @@ module LicenseAcceptance
18
18
  toml = Tomlrb.load_file(location, symbolize_keys: false)
19
19
  raise InvalidProductInfo.new(location) if toml.empty? || toml["products"].nil? || toml["relationships"].nil?
20
20
 
21
- for product in toml["products"]
21
+ toml["products"].each do |product|
22
22
  products[product["id"]] = Product.new(
23
23
  product["id"], product["pretty_name"],
24
24
  product["filename"], product["mixlib_name"],
@@ -26,7 +26,7 @@ module LicenseAcceptance
26
26
  )
27
27
  end
28
28
 
29
- for parent_id, children in toml["relationships"]
29
+ toml["relationships"].each do |parent_id, children|
30
30
  parent = products[parent_id]
31
31
  raise UnknownParent.new(parent_id) if parent.nil?
32
32
  # Its fine to not have a relationship entry, but not fine to have
@@ -34,9 +34,11 @@ module LicenseAcceptance
34
34
  if children.nil? || children.empty? || !children.is_a?(Array)
35
35
  raise NoChildRelationships.new(parent)
36
36
  end
37
+
37
38
  children.map! do |child_id|
38
39
  child = products[child_id]
39
40
  raise UnknownChild.new(child_id) if child.nil?
41
+
40
42
  child
41
43
  end
42
44
  relationships[parent] = children
@@ -52,6 +54,7 @@ module LicenseAcceptance
52
54
  if ENV["CHEF_LICENSE_PRODUCT_INFO"]
53
55
  return ENV["CHEF_LICENSE_PRODUCT_INFO"]
54
56
  end
57
+
55
58
  File.absolute_path(File.join(__FILE__, "../../../config/product_info.toml"))
56
59
  end
57
60
 
@@ -60,9 +63,10 @@ module LicenseAcceptance
60
63
  raise UnknownProduct.new(parent_id)
61
64
  end
62
65
  children = relationships.fetch(parent_product, [])
63
- if !parent_version.is_a? String
66
+ unless parent_version.is_a? String
64
67
  raise ProductVersionTypeError.new(parent_version)
65
68
  end
69
+
66
70
  ProductRelationship.new(parent_product, children, parent_version)
67
71
  end
68
72
 
@@ -30,14 +30,15 @@ module LicenseAcceptance
30
30
  if argv.include?("--chef-license=#{sought}")
31
31
  return true
32
32
  end
33
+
33
34
  i = argv.index("--chef-license")
34
35
  unless i.nil?
35
- val = argv[i+1]
36
- if val != nil && val.downcase == sought
36
+ val = argv[i + 1]
37
+ if !val.nil? && val.downcase == sought
37
38
  return true
38
39
  end
39
40
  end
40
- return false
41
+ false
41
42
  end
42
43
  end
43
44
  end
@@ -27,10 +27,11 @@ module LicenseAcceptance
27
27
  private
28
28
 
29
29
  def look_for_value(sought)
30
- if env['CHEF_LICENSE'] && env['CHEF_LICENSE'].downcase == sought
30
+ if env["CHEF_LICENSE"] && env["CHEF_LICENSE"].downcase == sought
31
31
  return true
32
32
  end
33
- return false
33
+
34
+ false
34
35
  end
35
36
 
36
37
  end
@@ -1,7 +1,7 @@
1
- require 'date'
2
- require 'yaml'
3
- require 'fileutils'
4
- require 'etc'
1
+ require "date"
2
+ require "yaml"
3
+ require "fileutils"
4
+ require "etc"
5
5
  require "license_acceptance/logger"
6
6
  require "license_acceptance/strategy/base"
7
7
 
@@ -49,7 +49,7 @@ module LicenseAcceptance
49
49
  parent_version = product_relationship.parent_version
50
50
  root_dir = config.persist_location
51
51
 
52
- if !Dir.exist?(root_dir)
52
+ unless Dir.exist?(root_dir)
53
53
  begin
54
54
  FileUtils.mkdir_p(root_dir)
55
55
  rescue StandardError => e
@@ -70,7 +70,7 @@ module LicenseAcceptance
70
70
  errs << err unless err.nil?
71
71
  end
72
72
  end
73
- return errs
73
+ errs
74
74
  end
75
75
 
76
76
  private
@@ -91,11 +91,11 @@ module LicenseAcceptance
91
91
  contents = Hash[contents.map { |k, v| [k.to_s, v] }]
92
92
  license_file << YAML.dump(contents)
93
93
  end
94
- return nil
94
+ nil
95
95
  rescue StandardError => e
96
96
  msg = "Could not persist license to #{path}"
97
97
  logger.info "#{msg}\n\t#{e.message}\n\t#{e.backtrace.join("\n\t")}"
98
- return e
98
+ e
99
99
  end
100
100
 
101
101
  end
@@ -1,5 +1,5 @@
1
- require 'tty-prompt'
2
- require 'pastel'
1
+ require "tty-prompt"
2
+ require "pastel"
3
3
  require "license_acceptance/logger"
4
4
  require "license_acceptance/strategy/base"
5
5
  require "timeout"
@@ -17,30 +17,30 @@ module LicenseAcceptance
17
17
  @output = config.output
18
18
  end
19
19
 
20
- WIDTH = 50.freeze
20
+ WIDTH = 50
21
21
  PASTEL = Pastel.new
22
22
  BORDER = "+---------------------------------------------+".freeze
23
23
  YES = PASTEL.green.bold("yes")
24
- CHECK = PASTEL.green("✔")
24
+ CHECK = PASTEL.green("✔")
25
25
 
26
26
  def request(missing_licenses, &persist_callback)
27
27
  logger.debug("Requesting a license for #{missing_licenses.map(&:id)}")
28
28
  c = missing_licenses.size
29
- s = c > 1 ? "s": ""
29
+ s = c > 1 ? "s" : ""
30
30
 
31
31
  acceptance_question = "Do you accept the #{c} product license#{s} (#{YES}/no)?"
32
32
  output.puts <<~EOM
33
- #{BORDER}
34
- Chef License Acceptance
33
+ #{BORDER}
34
+ Chef License Acceptance
35
35
 
36
- Before you can continue, #{c} product license#{s}
37
- must be accepted. View the license at
38
- https://www.chef.io/end-user-license-agreement/
36
+ Before you can continue, #{c} product license#{s}
37
+ must be accepted. View the license at
38
+ https://www.chef.io/end-user-license-agreement/
39
39
 
40
- License#{s} that need accepting:
41
- * #{missing_licenses.map(&:pretty_name).join("\n * ")}
40
+ License#{s} that need accepting:
41
+ * #{missing_licenses.map(&:pretty_name).join("\n * ")}
42
42
 
43
- #{acceptance_question}
43
+ #{acceptance_question}
44
44
 
45
45
  EOM
46
46
 
@@ -51,10 +51,10 @@ module LicenseAcceptance
51
51
 
52
52
  output.puts <<~EOM
53
53
 
54
- If you do not accept this license you will
55
- not be able to use Chef products.
54
+ If you do not accept this license you will
55
+ not be able to use Chef products.
56
56
 
57
- #{acceptance_question}
57
+ #{acceptance_question}
58
58
 
59
59
  EOM
60
60
 
@@ -62,7 +62,7 @@ module LicenseAcceptance
62
62
  if answer != "yes"
63
63
  output.puts BORDER
64
64
  end
65
- return answer
65
+ answer
66
66
  end
67
67
 
68
68
  private
@@ -73,7 +73,7 @@ module LicenseAcceptance
73
73
 
74
74
  answer = "no"
75
75
  begin
76
- Timeout::timeout(60, PromptTimeout) do
76
+ Timeout.timeout(60, PromptTimeout) do
77
77
  answer = prompt.ask(">") do |q|
78
78
  q.modify :down, :trim
79
79
  q.required true
@@ -95,13 +95,13 @@ module LicenseAcceptance
95
95
  output.puts "#{CHECK} #{c} product license#{s} persisted.\n\n"
96
96
  else
97
97
  output.puts <<~EOM
98
- #{CHECK} #{c} product license#{s} accepted.
99
- Could not persist acceptance:\n\t* #{errs.map(&:message).join("\n\t* ")}
98
+ #{CHECK} #{c} product license#{s} accepted.
99
+ Could not persist acceptance:\n\t* #{errs.map(&:message).join("\n\t* ")}
100
100
  EOM
101
101
  end
102
102
  return true
103
103
  end
104
- return false
104
+ false
105
105
  end
106
106
  end
107
107
 
@@ -1,3 +1,3 @@
1
1
  module LicenseAcceptance
2
- VERSION = "1.0.18"
2
+ VERSION = "1.0.19".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license-acceptance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - tyler-ball
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-14 00:00:00.000000000 Z
11
+ date: 2020-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -184,6 +184,20 @@ dependencies:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0.2'
187
+ - !ruby/object:Gem::Dependency
188
+ name: chefstyle
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
187
201
  description: Chef End User License Agreement Acceptance for Ruby products
188
202
  email:
189
203
  - tball@chef.io