codeclimate 0.40.3 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cc/cli.rb +1 -0
- data/lib/cc/cli/dependencies.rb +94 -0
- data/lib/cc/cli/help.rb +1 -0
- data/lib/cc/resolv.rb +39 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2b2dcd339b86ee8c2046bcc25bc473a6f00bed
|
4
|
+
data.tar.gz: 96ac5a4abeddbce089aaee654c08e0489fbcf3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7440d7ea2157ba191d71c851f93542dbdb5bffa29678709536848505606f122b167bdf8ebe77059f65c2ac82223b6a0c4e079617da9c3ba941fd3015014b5e21
|
7
|
+
data.tar.gz: 7d1cc4c413306c30124164a5e88f425969ef106afe0eb6eb6aafc0b90c5914447fd6804e8a9afeb46a1992d8d0176bc1626dc230df6f325b0324d91d263f20bd
|
data/lib/cc/cli.rb
CHANGED
@@ -11,6 +11,7 @@ module CC
|
|
11
11
|
autoload :Command, "cc/cli/command"
|
12
12
|
autoload :Console, "cc/cli/console"
|
13
13
|
autoload :Engines, "cc/cli/engines"
|
14
|
+
autoload :Dependencies, "cc/cli/dependencies"
|
14
15
|
autoload :Help, "cc/cli/help"
|
15
16
|
autoload :Init, "cc/cli/init"
|
16
17
|
autoload :Runner, "cc/cli/runner"
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "cc/cli/config"
|
2
|
+
require "cc/resolv"
|
3
|
+
require "fileutils"
|
4
|
+
require "ipaddr"
|
5
|
+
require "json"
|
6
|
+
require "net/http"
|
7
|
+
require "pathname"
|
8
|
+
require "uri"
|
9
|
+
|
10
|
+
module CC
|
11
|
+
module CLI
|
12
|
+
class Dependencies < Command
|
13
|
+
InternalHostError = Class.new(StandardError)
|
14
|
+
FetchError = Class.new(StandardError)
|
15
|
+
|
16
|
+
PRIVATE_ADDRESS_SUBNETS = [
|
17
|
+
IPAddr.new("10.0.0.0/8"),
|
18
|
+
IPAddr.new("172.16.0.0/12"),
|
19
|
+
IPAddr.new("192.168.0.0/16"),
|
20
|
+
IPAddr.new("fd00::/8"),
|
21
|
+
IPAddr.new("127.0.0.1"),
|
22
|
+
IPAddr.new("0:0:0:0:0:0:0:1"),
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
def run
|
26
|
+
require_codeclimate_yml
|
27
|
+
fatal("No file dependencies configured") unless files.present?
|
28
|
+
|
29
|
+
::CC::Resolv.with_fixed_dns { fetch_all }
|
30
|
+
success("All file dependencies fetched")
|
31
|
+
rescue FetchError, InternalHostError => ex
|
32
|
+
fatal(ex.message)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def allow_internal_ips?
|
38
|
+
@args.include?("--allow-internal-ips")
|
39
|
+
end
|
40
|
+
|
41
|
+
def files
|
42
|
+
@files ||= config.dependencies && config.dependencies.files
|
43
|
+
end
|
44
|
+
|
45
|
+
def config
|
46
|
+
@config ||= CC::Yaml.parse(filesystem.read_path(CODECLIMATE_YAML))
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetch_all
|
50
|
+
files.each do |entry|
|
51
|
+
fetch(entry.url, entry.path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def fetch(url, target_path)
|
56
|
+
ensure_external!(url) unless allow_internal_ips?
|
57
|
+
|
58
|
+
uri = URI.parse(url)
|
59
|
+
resp = Net::HTTP.get_response(uri)
|
60
|
+
if resp.code == "200"
|
61
|
+
write_file(target_path, resp.body)
|
62
|
+
say("Wrote #{url} to #{target_path}")
|
63
|
+
else
|
64
|
+
raise FetchError, "Failed fetching #{url}: code=#{resp.code} body=#{resp.body}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def write_file(target_path, content)
|
69
|
+
FileUtils.mkdir_p(Pathname.new(target_path).parent.to_s)
|
70
|
+
File.write(target_path, content)
|
71
|
+
end
|
72
|
+
|
73
|
+
def ensure_external!(url)
|
74
|
+
uri = URI.parse(url)
|
75
|
+
|
76
|
+
if internal?(uri.host)
|
77
|
+
raise InternalHostError, "Won't fetch #{url.inspect}: it maps to an internal address"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# rubocop:disable Style/CaseEquality
|
82
|
+
def internal?(host)
|
83
|
+
address = ::Resolv.getaddress(host)
|
84
|
+
|
85
|
+
PRIVATE_ADDRESS_SUBNETS.any? do |subnet|
|
86
|
+
subnet === IPAddr.new(address.to_s)
|
87
|
+
end
|
88
|
+
rescue ::Resolv::ResolvError
|
89
|
+
true # localhost
|
90
|
+
end
|
91
|
+
# rubocop:enable Style/CaseEquality
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/cc/cli/help.rb
CHANGED
data/lib/cc/resolv.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "resolv-replace"
|
2
|
+
|
3
|
+
module CC
|
4
|
+
class Resolv
|
5
|
+
def self.with_fixed_dns(dns = ::Resolv::DNS.new)
|
6
|
+
::Resolv::DefaultResolver.replace_resolvers([Fixed.new(dns)])
|
7
|
+
|
8
|
+
yield if block_given?
|
9
|
+
ensure
|
10
|
+
# There's no way to ask what the current values are before we override
|
11
|
+
# them; hopefully going by the source is good enough.
|
12
|
+
# https://docs.ruby-lang.org/en/2.0.0/Resolv.html#method-c-new
|
13
|
+
default_resolvers = [::Resolv::Hosts.new, ::Resolv::DNS.new]
|
14
|
+
::Resolv::DefaultResolver.replace_resolvers(default_resolvers)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Fixed
|
18
|
+
def initialize(fallback)
|
19
|
+
@addresses = {}
|
20
|
+
@fallback = fallback
|
21
|
+
end
|
22
|
+
|
23
|
+
def each_address(name)
|
24
|
+
if addresses.key?(name)
|
25
|
+
yield addresses.fetch(name)
|
26
|
+
else
|
27
|
+
fallback.each_address(name) do |address|
|
28
|
+
addresses[name] ||= address
|
29
|
+
yield address
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :addresses, :fallback
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeclimate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.41.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code Climate
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/cc/cli/config.rb
|
213
213
|
- lib/cc/cli/config_generator.rb
|
214
214
|
- lib/cc/cli/console.rb
|
215
|
+
- lib/cc/cli/dependencies.rb
|
215
216
|
- lib/cc/cli/engines.rb
|
216
217
|
- lib/cc/cli/engines/disable.rb
|
217
218
|
- lib/cc/cli/engines/enable.rb
|
@@ -226,6 +227,7 @@ files:
|
|
226
227
|
- lib/cc/cli/upgrade_config_generator.rb
|
227
228
|
- lib/cc/cli/validate_config.rb
|
228
229
|
- lib/cc/cli/version.rb
|
230
|
+
- lib/cc/resolv.rb
|
229
231
|
- lib/cc/workspace.rb
|
230
232
|
- lib/cc/workspace/exclusion.rb
|
231
233
|
- lib/cc/workspace/path_tree.rb
|