license-acceptance 2.0.0 → 2.1.1

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: eee8ab3bdb6b370c3b0c2dddb7a86f22cea5240eae5df17e58e4c367fc08a0fe
4
- data.tar.gz: 7f25c5f59f833808115dead1157b33f09c9fe4e4000c3c4e70dee586466d74a9
3
+ metadata.gz: 6c2e076dba9be610985535dca130a348b58d6beb27efba823d97fd86077d8d60
4
+ data.tar.gz: 6370bf24f3c58e13194975b9e0dbb06a2dc577cd5b632def8aa6b92acbaeeae4
5
5
  SHA512:
6
- metadata.gz: ef3af6247b87811c3796838e707d47b153c7828160a4dee699b3e95f2bef534c055fa34e828548a7e0dc9830b146014c2a8a7a4ac2cca4d94388e180d4fa5581
7
- data.tar.gz: aa6d132e77ecfb95a8c4e263d29d7731a44f2c8d40d4cd7eeb48fbf8964c5a9e807c6cde3fec5f757af3cb9de2e5fbfc1e8d60c5729598f204fa2829d6e1c42c
6
+ metadata.gz: 93edc97194f0dc6556867113a1faf12ff559c28ab4b5ad41b1eeeca6a8a84305db55d2be10f251b6f0cf760630867b08912eef9a33757fa51ad69fbec4b66996
7
+ data.tar.gz: 767e584dc945ff8e324a965a574cd174905089b2918c2a99ca28221edba28616a9a23fa9dea624f66c3d67d688583719ccb648fc7fa1e5d871737eb7875f6662
data/Gemfile CHANGED
@@ -6,9 +6,9 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  group :development do
9
- gem "chefstyle", "1.2.1"
9
+ gem "chefstyle", "1.3.2"
10
10
  gem "climate_control", "~> 0.2"
11
- gem "mixlib-cli", "~> 1.7"
11
+ gem "mixlib-cli", "~> 2.1"
12
12
  gem "rake", ">= 10.1.0"
13
13
  gem "rspec", "~> 3.0"
14
14
  gem "thor", ">= 0.20", "< 2.0" # validate 2.0 when it ships
@@ -1,4 +1,4 @@
1
- require "forwardable"
1
+ require "forwardable" unless defined?(Forwardable)
2
2
  require "license_acceptance/config"
3
3
  require "license_acceptance/logger"
4
4
  require "license_acceptance/product_reader"
@@ -74,21 +74,18 @@ module LicenseAcceptance
74
74
  end
75
75
  end
76
76
  @acceptance_value = accepted_silent? ? ACCEPT_SILENT : ACCEPT
77
- true
78
- elsif config.output.isatty && prompt_strategy.request(missing_licenses) do
79
- # We have to infer the acceptance value if they use the prompt to accept
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
- []
86
- end
77
+ return true
87
78
  end
88
- true
89
- else
79
+
80
+ if acceptance_value_provided?
81
+ value = provided_strategy.value || env_strategy.value || arg_strategy.value
82
+ output.puts("Unrecognized license acceptance value '#{value}', expected one of: '#{ACCEPT}', '#{ACCEPT_SILENT}', '#{ACCEPT_NO_PERSIST}'")
90
83
  raise LicenseNotAcceptedError.new(product_relationship.parent, missing_licenses)
91
84
  end
85
+
86
+ return true if output.isatty && accepted_license_prompt?(product_relationship, missing_licenses)
87
+
88
+ raise LicenseNotAcceptedError.new(product_relationship.parent, missing_licenses)
92
89
  end
93
90
 
94
91
  def self.check_and_persist!(product_id, version, opts = {})
@@ -99,6 +96,19 @@ module LicenseAcceptance
99
96
  new(opts).check_and_persist(product_id, version)
100
97
  end
101
98
 
99
+ def accepted_license_prompt?(product_relationship, missing_licenses)
100
+ prompt_strategy.request(missing_licenses) do
101
+ # We have to infer the acceptance value if they use the prompt to accept
102
+ if config.persist
103
+ @acceptance_value = ACCEPT
104
+ file_strategy.persist(product_relationship, missing_licenses)
105
+ else
106
+ @acceptance_value = ACCEPT_NO_PERSIST
107
+ []
108
+ end
109
+ end
110
+ end
111
+
102
112
  # Check whether the specified product requires license acceptance for the given version.
103
113
  def license_required?(mixlib_name, version)
104
114
  product = product_reader.lookup_by_mixlib(mixlib_name)
@@ -140,6 +150,10 @@ module LicenseAcceptance
140
150
  provided_strategy.silent? || env_strategy.silent? || arg_strategy.silent?
141
151
  end
142
152
 
153
+ def acceptance_value_provided?
154
+ provided_strategy.value? || env_strategy.value? || arg_strategy.value?
155
+ end
156
+
143
157
  # In the case where users accept with a command line argument or environment variable
144
158
  # we still want to output the fact that the filesystem was changed.
145
159
  def output_num_persisted(count)
@@ -1,5 +1,5 @@
1
1
  begin
2
- require "mixlib/cli"
2
+ require "mixlib/cli" unless defined?(Mixlib::CLI)
3
3
  rescue
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" unless defined?(Thor)
3
3
  rescue
4
4
  raise "Must have thor gem installed to use this mixin"
5
5
  end
@@ -1,4 +1,4 @@
1
- require "tomlrb"
1
+ autoload :Tomlrb, "tomlrb"
2
2
  require "license_acceptance/logger"
3
3
  require "license_acceptance/product"
4
4
  require "license_acceptance/product_relationship"
@@ -6,6 +6,8 @@ module LicenseAcceptance
6
6
  # Look for acceptance values in the ARGV
7
7
  class Argument < Base
8
8
 
9
+ FLAG = "--chef-license".freeze
10
+
9
11
  attr_reader :argv
10
12
 
11
13
  def initialize(argv)
@@ -13,32 +15,30 @@ module LicenseAcceptance
13
15
  end
14
16
 
15
17
  def accepted?
16
- look_for_value(ACCEPT)
18
+ String(value).downcase == ACCEPT
17
19
  end
18
20
 
19
21
  def silent?
20
- look_for_value(ACCEPT_SILENT)
22
+ String(value).downcase == ACCEPT_SILENT
21
23
  end
22
24
 
23
25
  def no_persist?
24
- look_for_value(ACCEPT_NO_PERSIST)
26
+ String(value).downcase == ACCEPT_NO_PERSIST
27
+ end
28
+
29
+ def value?
30
+ argv.any? { |s| s == FLAG || s.start_with?("#{FLAG}=") }
25
31
  end
26
32
 
27
- private
33
+ def value
34
+ match = argv.detect { |s| s.start_with?("#{FLAG}=") }
35
+ return match.split("=").last if match
28
36
 
29
- def look_for_value(sought)
30
- if argv.include?("--chef-license=#{sought}")
31
- return true
37
+ argv.each_cons(2) do |arg, value|
38
+ return value if arg == FLAG
32
39
  end
33
40
 
34
- i = argv.index("--chef-license")
35
- unless i.nil?
36
- val = argv[i + 1]
37
- if !val.nil? && val.downcase == sought
38
- return true
39
- end
40
- end
41
- false
41
+ nil
42
42
  end
43
43
  end
44
44
  end
@@ -6,6 +6,8 @@ module LicenseAcceptance
6
6
  # Look for acceptance values in the environment
7
7
  class Environment < Base
8
8
 
9
+ ENV_KEY = "CHEF_LICENSE".freeze
10
+
9
11
  attr_reader :env
10
12
 
11
13
  def initialize(env)
@@ -13,25 +15,23 @@ module LicenseAcceptance
13
15
  end
14
16
 
15
17
  def accepted?
16
- look_for_value(ACCEPT)
18
+ String(value).downcase == ACCEPT
17
19
  end
18
20
 
19
21
  def silent?
20
- look_for_value(ACCEPT_SILENT)
22
+ String(value).downcase == ACCEPT_SILENT
21
23
  end
22
24
 
23
25
  def no_persist?
24
- look_for_value(ACCEPT_NO_PERSIST)
26
+ String(value).downcase == ACCEPT_NO_PERSIST
25
27
  end
26
28
 
27
- private
28
-
29
- def look_for_value(sought)
30
- if env["CHEF_LICENSE"] && env["CHEF_LICENSE"].downcase == sought
31
- return true
32
- end
29
+ def value?
30
+ env.key?(ENV_KEY)
31
+ end
33
32
 
34
- false
33
+ def value
34
+ env[ENV_KEY]
35
35
  end
36
36
 
37
37
  end
@@ -1,7 +1,7 @@
1
1
  require "date"
2
- require "yaml"
3
- require "fileutils"
4
- require "etc"
2
+ autoload :YAML, "yaml"
3
+ require "fileutils" unless defined?(FileUtils)
4
+ require "etc" unless defined?(Etc)
5
5
  require "license_acceptance/logger"
6
6
  require "license_acceptance/strategy/base"
7
7
 
@@ -1,8 +1,8 @@
1
- require "tty-prompt"
1
+ autoload :TTY, "tty-prompt"
2
2
  require "pastel"
3
3
  require "license_acceptance/logger"
4
4
  require "license_acceptance/strategy/base"
5
- require "timeout"
5
+ require "timeout" unless defined?(Timeout)
6
6
 
7
7
  module LicenseAcceptance
8
8
  module Strategy
@@ -22,7 +22,10 @@ module LicenseAcceptance
22
22
  def no_persist?
23
23
  value == ACCEPT_NO_PERSIST
24
24
  end
25
- end
26
25
 
26
+ def value?
27
+ !!value
28
+ end
29
+ end
27
30
  end
28
31
  end
@@ -1,3 +1,3 @@
1
1
  module LicenseAcceptance
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.1.1".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: 2.0.0
4
+ version: 2.1.1
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-08-12 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel