kataba 1.1.0 → 1.1.2
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/kataba/fetcher.rb +22 -1
- data/lib/kataba.rb +15 -3
- metadata +12 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e2048c2adaac9976b8feb4fcea1da32d937a7d39955152a579f18d81e9fe3f2
|
|
4
|
+
data.tar.gz: 806c80fff00c2a8dd637b42e1df485787e041a514ecc6372df5cb4902db8889e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 15b1a25d1ed46d7510f829f4a6b51ca6516ed29edfa011b4a8395cee0bc36092e37d4ecb925e24791da6d4790435896059cabd8fb375b17278c724dff61540c9
|
|
7
|
+
data.tar.gz: 64fa54356f4d0c0387a9c52898795462524363b6fccf6632259b635adb7d2c19544760c2e0b91256cf1e22b50a3e3836868ce5581c73499bda3184f32838b086
|
data/lib/kataba/fetcher.rb
CHANGED
|
@@ -12,6 +12,12 @@ module Kataba
|
|
|
12
12
|
# consumer already trusted this host by putting it in their
|
|
13
13
|
# schemaLocation. Cross-origin downgrades stay refused — that's
|
|
14
14
|
# the actual DNS-redirect attack vector.
|
|
15
|
+
# - /mods/xml.xsd: rewrite to /standards/mods/xml.xsd before the
|
|
16
|
+
# first request. The /mods/xml.xsd path is what every mods-3-N.xsd
|
|
17
|
+
# embeds in its xs:import, but LoC only serves the file from
|
|
18
|
+
# /standards/mods/xml.xsd today — the embedded path bounces
|
|
19
|
+
# HTTPS->HTTP and 503s. Applied here so transitive xs:import
|
|
20
|
+
# resolution benefits, not just top-level fetch_schema calls.
|
|
15
21
|
#
|
|
16
22
|
# mirror_list remains the consumer's backstop for URI-identity
|
|
17
23
|
# changes (path renames, host moves) that no delivery heuristic
|
|
@@ -19,6 +25,13 @@ module Kataba
|
|
|
19
25
|
class Fetcher
|
|
20
26
|
MAX_REDIRECTS = 5
|
|
21
27
|
|
|
28
|
+
# Map from a path that's embedded in published schemas but no longer
|
|
29
|
+
# serves the file, to the path that does. xml.xsd: every mods-3-N.xsd
|
|
30
|
+
# imports /mods/xml.xsd, but only /standards/mods/xml.xsd serves it.
|
|
31
|
+
PATH_REWRITES = {
|
|
32
|
+
'/mods/xml.xsd' => '/standards/mods/xml.xsd',
|
|
33
|
+
}.freeze
|
|
34
|
+
|
|
22
35
|
class FetchError < StandardError; end
|
|
23
36
|
|
|
24
37
|
def initialize(uri)
|
|
@@ -26,11 +39,19 @@ module Kataba
|
|
|
26
39
|
end
|
|
27
40
|
|
|
28
41
|
def fetch
|
|
29
|
-
attempt(@original_uri, alt_scheme_retry: true)
|
|
42
|
+
attempt(normalize(@original_uri), alt_scheme_retry: true)
|
|
30
43
|
end
|
|
31
44
|
|
|
32
45
|
private
|
|
33
46
|
|
|
47
|
+
def normalize(uri)
|
|
48
|
+
PATH_REWRITES.each do |from, to|
|
|
49
|
+
rewritten = uri.sub(%r{(\Ahttps?://[^/]+)#{Regexp.escape(from)}\z}i, "\\1#{to}")
|
|
50
|
+
return rewritten unless rewritten == uri
|
|
51
|
+
end
|
|
52
|
+
uri
|
|
53
|
+
end
|
|
54
|
+
|
|
34
55
|
def attempt(uri, alt_scheme_retry:)
|
|
35
56
|
response = request_with_redirects(uri, redirect_depth: 0)
|
|
36
57
|
|
data/lib/kataba.rb
CHANGED
|
@@ -61,6 +61,14 @@ module Kataba
|
|
|
61
61
|
# Arguments:
|
|
62
62
|
# xsd_uri: (String)
|
|
63
63
|
|
|
64
|
+
# Dir.chdir is process-wide state, not thread-local: if two threads each
|
|
65
|
+
# have a chdir block open at once, Ruby raises "conflicting chdir during
|
|
66
|
+
# another chdir block" rather than let one thread's cwd stomp on the
|
|
67
|
+
# other's. A shared Mutex serializes just that step across threads in one
|
|
68
|
+
# process — cheap, since by this point it's a local file read + a Nokogiri
|
|
69
|
+
# parse, not the network fetch (which stays outside the lock).
|
|
70
|
+
CHDIR_MUTEX = Mutex.new
|
|
71
|
+
|
|
64
72
|
def self.fetch_schema(xsd_uri)
|
|
65
73
|
uri_md5 = Digest::MD5.hexdigest(xsd_uri)
|
|
66
74
|
dir_path = "#{self.configuration.offline_storage}"
|
|
@@ -77,8 +85,10 @@ module Kataba
|
|
|
77
85
|
end
|
|
78
86
|
|
|
79
87
|
# Validate and return Nokogiri schema
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
CHDIR_MUTEX.synchronize do
|
|
89
|
+
Dir.chdir(dir_path) do
|
|
90
|
+
return Nokogiri::XML::Schema(IO.read(xsd_path))
|
|
91
|
+
end
|
|
82
92
|
end
|
|
83
93
|
rescue Nokogiri::XML::SyntaxError
|
|
84
94
|
# Poisoned cache (e.g. a pre-fix install that stored a bad fetch).
|
|
@@ -115,7 +125,9 @@ module Kataba
|
|
|
115
125
|
# orphaned 0-byte .part on disk — the file simply isn't created.
|
|
116
126
|
fetch_uri = xsd_uri
|
|
117
127
|
if !self.configuration.mirror_list.to_s.empty?
|
|
118
|
-
|
|
128
|
+
# YAML.load_file returns nil for a comments-only or empty file.
|
|
129
|
+
# Treat that as "no mirror configured" rather than NoMethodError.
|
|
130
|
+
mirror_list = YAML.load_file(self.configuration.mirror_list) || {}
|
|
119
131
|
mirror = mirror_list[xsd_uri]
|
|
120
132
|
fetch_uri = mirror unless mirror.to_s.empty?
|
|
121
133
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kataba
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Cliff
|
|
@@ -14,56 +14,56 @@ dependencies:
|
|
|
14
14
|
name: nokogiri
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- -
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.19'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- -
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.19'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: minitest
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: webmock
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- -
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- -
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
69
|
description: Kataba allows for mirroring and offline storage of XSD files, to enhance
|
|
@@ -85,16 +85,16 @@ require_paths:
|
|
|
85
85
|
- lib
|
|
86
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
87
|
requirements:
|
|
88
|
-
- -
|
|
88
|
+
- - ">="
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
90
|
version: '3.2'
|
|
91
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
|
-
- -
|
|
93
|
+
- - ">="
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '0'
|
|
96
96
|
requirements: []
|
|
97
|
-
rubygems_version: 3.
|
|
97
|
+
rubygems_version: 3.2.33
|
|
98
98
|
signing_key:
|
|
99
99
|
specification_version: 4
|
|
100
100
|
summary: XML Schema Definition (XSD) mirroring and offline validation for Nokogiri
|