uricp 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/uricp +14 -3
- data/features/auth_download.feature +30 -0
- data/features/cacheable_from_uri.feature +20 -0
- data/features/documented_options.feature +11 -0
- data/lib/uricp/strategy/cache_common.rb +2 -2
- data/lib/uricp/strategy/piped_remote_get.rb +21 -4
- data/lib/uricp/version.rb +1 -1
- data/lib/uricp.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 054b98cbf8e67b76cc3e2b552677573fe5b5cbea
|
4
|
+
data.tar.gz: 85337e7757d5d33a03c72860770dbb10eea58bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b774aecb700c7e3b290e2fd3a7140baafe012b188a0f5c9d2166539af35c6f79e6f96cfb92056c1858c0e25e465859492e94e2c5317bfa68d7d5b8c210bca9f
|
7
|
+
data.tar.gz: f4bf7e1dc1c44c0a712720d54e0f86d4ab95f332b3cdfb20c0dcd431d5d65edfbc674921bba6debdcf8290bc0491ee1476a0686456cb0177d936ba141aed9836
|
data/Gemfile.lock
CHANGED
data/bin/uricp
CHANGED
@@ -18,6 +18,9 @@ class App
|
|
18
18
|
if options['segment-size']
|
19
19
|
options['segment-size'] = Filesize.from(options['segment-size'])
|
20
20
|
end
|
21
|
+
if options['max-cache']
|
22
|
+
options['max-cache'] = Filesize.from(options['max-cache'])
|
23
|
+
end
|
21
24
|
validate_options
|
22
25
|
Uricp::OrbitAuth.validate_options(options)
|
23
26
|
set_auth_env
|
@@ -53,9 +56,15 @@ class App
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def self.validate_options
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
unless options['cache']
|
60
|
+
case
|
61
|
+
when options['target-format']
|
62
|
+
raise ::OptionParser::MissingArgument,
|
63
|
+
"'target-format' requires 'cache' option"
|
64
|
+
when options['max-cache']
|
65
|
+
raise ::OptionParser::MissingArgument,
|
66
|
+
"'max-cache' requires 'cache' option"
|
67
|
+
end
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
@@ -90,6 +99,8 @@ class App
|
|
90
99
|
Uricp::OrbitAuth.add_auth_to_optionparser(self)
|
91
100
|
on("--cache CACHE_ROOT",
|
92
101
|
"Root directory of cache area")
|
102
|
+
on("--max-cache MAX_CACHE_SIZE",
|
103
|
+
"Maximum size of cached file in [GMk][i]B.")
|
93
104
|
on("--target-format FORMAT", [:qcow2, :raw, :qcow3, :qcow2v3],
|
94
105
|
"Image format of target", "[qcow2, raw, qcow3, qcow2v3]")
|
95
106
|
on("--segment-size SEGMENT_SIZE",
|
@@ -45,6 +45,21 @@ Feature: Authenticated download of images from orbit
|
|
45
45
|
And a file named "/tmp/uricp/cache/img-qcow2" should exist
|
46
46
|
And the file named "/tmp/uricp/cache/img-qcow2" should have a file format of "qcow2v3"
|
47
47
|
|
48
|
+
Scenario: qcow download convert to raw, cache, within size
|
49
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
50
|
+
When I retrieve "img-qcow2" with options "--target-format=raw --cache=/tmp/uricp --max-cache 10MB" from container "test" into "file:///tmp/uricp/srv-testq"
|
51
|
+
Then a file named "/tmp/uricp/srv-testq" should exist
|
52
|
+
And the file named "/tmp/uricp/srv-testq" should have a file format of "raw"
|
53
|
+
And a file named "/tmp/uricp/cache/img-qcow2" should exist
|
54
|
+
And the file named "/tmp/uricp/cache/img-qcow2" should have a file format of "qcow2v3"
|
55
|
+
|
56
|
+
Scenario: qcow download convert to raw, cache, size limited
|
57
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
58
|
+
When I retrieve "img-qcow2" with options "--target-format=raw --cache=/tmp/uricp --max-cache 100kB" from container "test" into "file:///tmp/uricp/srv-testj"
|
59
|
+
Then a file named "/tmp/uricp/srv-testj" should exist
|
60
|
+
And the file named "/tmp/uricp/srv-testj" should have a file format of "raw"
|
61
|
+
And a file named "/tmp/uricp/cache/img-qcow2" should not exist
|
62
|
+
|
48
63
|
Scenario: qcow download convert to qcow2, cache
|
49
64
|
Given a correctly initialised cache at "/tmp/uricp"
|
50
65
|
When I retrieve "img-qcow2" with options "--target-format=qcow2 --cache=/tmp/uricp" from container "test" into "file:///tmp/uricp/srv-test5"
|
@@ -88,6 +103,21 @@ Feature: Authenticated download of images from orbit
|
|
88
103
|
And a file named "/tmp/uricp/cache/img-lz4cy" should exist
|
89
104
|
And the file named "/tmp/uricp/cache/img-lz4cy" should have a file format of "lz4"
|
90
105
|
|
106
|
+
Scenario: lz4 download convert to raw, cache, size limited
|
107
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
108
|
+
When I retrieve "img-lz4cy" with options "--target-format=raw --cache=/tmp/uricp --max-cache 2MB" from container "test" into "file:///tmp/uricp/srv-testf"
|
109
|
+
Then a file named "/tmp/uricp/srv-testf" should exist
|
110
|
+
And the file named "/tmp/uricp/srv-testf" should have a file format of "raw"
|
111
|
+
And a file named "/tmp/uricp/cache/img-lz4cy" should not exist
|
112
|
+
|
113
|
+
Scenario: lz4 download convert to raw, cache, within size
|
114
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
115
|
+
When I retrieve "img-lz4cy" with options "--target-format=raw --cache=/tmp/uricp --max-cache 10MB" from container "test" into "file:///tmp/uricp/srv-test9"
|
116
|
+
Then a file named "/tmp/uricp/srv-test9" should exist
|
117
|
+
And the file named "/tmp/uricp/srv-test9" should have a file format of "raw"
|
118
|
+
And a file named "/tmp/uricp/cache/img-lz4cy" should exist
|
119
|
+
And the file named "/tmp/uricp/cache/img-lz4cy" should have a file format of "lz4"
|
120
|
+
|
91
121
|
Scenario: lz4 download convert to raw, from cache
|
92
122
|
Given a correctly initialised cache at "/tmp/uricp"
|
93
123
|
And a cache of "img-lz4cy" from container "test" at "/tmp/uricp"
|
@@ -20,6 +20,13 @@ Feature: Download Public VM images
|
|
20
20
|
And a file named "/tmp/uricp/cache/freedos.qcow2" should exist
|
21
21
|
And the file named "/tmp/uricp/cache/freedos.qcow2" should have a file format of "qcow2"
|
22
22
|
|
23
|
+
Scenario: HTTP URI qcow2 via cache - size limited
|
24
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
25
|
+
When I successfully run `uricp --cache=/tmp/uricp --max-cache=8MB http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
|
26
|
+
Then a file named "/tmp/uricp/srv-testy" should exist
|
27
|
+
And the file named "/tmp/uricp/srv-testy" should have a file format of "qcow2"
|
28
|
+
And a file named "/tmp/uricp/cache/freedos.qcow2" should not exist
|
29
|
+
|
23
30
|
Scenario: HTTP URI qcow2 to qcow2 via cache
|
24
31
|
Given a correctly initialised cache at "/tmp/uricp"
|
25
32
|
When I successfully run `uricp --target-format=qcow2 --cache=/tmp/uricp http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
|
@@ -28,6 +35,13 @@ Feature: Download Public VM images
|
|
28
35
|
And a file named "/tmp/uricp/cache/freedos.qcow2" should exist
|
29
36
|
And the file named "/tmp/uricp/cache/freedos.qcow2" should have a file format of "qcow2"
|
30
37
|
|
38
|
+
Scenario: HTTP URI qcow2 to qcow2 via cache - size limited
|
39
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
40
|
+
When I successfully run `uricp --target-format=qcow2 --cache=/tmp/uricp --max-cache=8Mb http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
|
41
|
+
Then a file named "/tmp/uricp/srv-testy" should exist
|
42
|
+
And the file named "/tmp/uricp/srv-testy" should have a file format of "qcow2"
|
43
|
+
And a file named "/tmp/uricp/cache/freedos.qcow2" should not exist
|
44
|
+
|
31
45
|
@new-qemu-image
|
32
46
|
Scenario: HTTP URI qcow2 to qcow2v3 via cache
|
33
47
|
Given a correctly initialised cache at "/tmp/uricp"
|
@@ -45,6 +59,12 @@ Feature: Download Public VM images
|
|
45
59
|
And a file named "/tmp/uricp/cache/freedos.qcow2" should exist
|
46
60
|
And the file named "/tmp/uricp/cache/freedos.qcow2" should have a file format of "qcow2"
|
47
61
|
|
62
|
+
Scenario: HTTP URI qcow2 to raw via cache - size limited
|
63
|
+
Given a correctly initialised cache at "/tmp/uricp"
|
64
|
+
When I successfully run `uricp --target-format=raw --cache=/tmp/uricp --max-cache=8Mb http://orbit.brightbox.com/v1/acc-tqs4c/downloads/freedos.qcow2 file:///tmp/uricp/srv-testy`
|
65
|
+
Then a file named "/tmp/uricp/srv-testy" should exist
|
66
|
+
And the file named "/tmp/uricp/srv-testy" should have a file format of "raw"
|
67
|
+
And a file named "/tmp/uricp/cache/freedos.qcow2" should not exist
|
48
68
|
|
49
69
|
Scenario: HTTP URI from cache
|
50
70
|
Given a correctly initialised cache at "/tmp/uricp"
|
@@ -16,6 +16,7 @@ Feature: Documented Help
|
|
16
16
|
|--auth-user|
|
17
17
|
|--auth-key|
|
18
18
|
|--segment|
|
19
|
+
|--max-cache|
|
19
20
|
And the option "compress" should be documented which is negatable
|
20
21
|
And the option "dry-run" should be documented which is negatable
|
21
22
|
And the option "force" should be documented which is negatable
|
@@ -72,3 +73,13 @@ Feature: Documented Help
|
|
72
73
|
When I run `uricp --segment-size 100 --auth-token abcdef file:///tmp/temp https:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
|
73
74
|
Then the exit status should not be 0
|
74
75
|
And the stderr should contain "Unparseable filesize"
|
76
|
+
|
77
|
+
Scenario: should not accept plain number for max-cache size
|
78
|
+
When I run `uricp --max-cache 100 --cache /tmp/uricp --auth-token abcdef file:///tmp/temp https:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
|
79
|
+
Then the exit status should not be 0
|
80
|
+
And the stderr should contain "Unparseable filesize"
|
81
|
+
|
82
|
+
Scenario: max-cache size requires cache
|
83
|
+
When I run `uricp --max-cache 100MB --auth-token abcdef file:///tmp/temp https:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
|
84
|
+
Then the exit status should not be 0
|
85
|
+
And the stderr should contain "missing argument"
|
@@ -6,9 +6,9 @@ module Uricp::Strategy
|
|
6
6
|
|
7
7
|
def validate_cache!
|
8
8
|
raise Uricp::MissingCache,
|
9
|
-
"
|
9
|
+
"no cache found at #{cache_root}. Expected a 'cache' and 'temp' directory" unless cache_exists?
|
10
10
|
raise Uricp::MissingCache,
|
11
|
-
"
|
11
|
+
"no cache name found" unless cache_name
|
12
12
|
end
|
13
13
|
|
14
14
|
def in_cache?
|
@@ -20,18 +20,26 @@ module Uricp::Strategy
|
|
20
20
|
def proposal
|
21
21
|
@proposed_options = options.dup
|
22
22
|
@proposed_options['from_uri'] = PIPE_URI
|
23
|
-
if
|
24
|
-
|
25
|
-
if @proposed_options['source-format'] == @proposed_options['target-format']
|
23
|
+
if conversion_required?
|
24
|
+
@proposed_options['source-format'] = format_peek
|
25
|
+
if @proposed_options['source-format'] == @proposed_options['target-format']
|
26
26
|
@proposed_options.delete('source-format')
|
27
27
|
@proposed_options.delete('target-format')
|
28
28
|
end
|
29
29
|
end
|
30
|
+
if options['max-cache'] &&
|
31
|
+
size_peek.to_i > options['max-cache'].to_i
|
32
|
+
@proposed_options.delete('cache')
|
33
|
+
@proposed_options.delete('cache_name')
|
34
|
+
@proposed_options.delete('max-cache')
|
35
|
+
end
|
30
36
|
self
|
31
37
|
end
|
32
38
|
|
33
39
|
def format_peek
|
34
|
-
options['from_uri'].open(headers)
|
40
|
+
options['from_uri'].open(headers) do |u|
|
41
|
+
encoding(u)
|
42
|
+
end
|
35
43
|
rescue OpenURI::HTTPError => e
|
36
44
|
case e.io.status[0]
|
37
45
|
when '416'
|
@@ -43,6 +51,15 @@ module Uricp::Strategy
|
|
43
51
|
raise SocketError, options['from_uri'].to_s+" inaccessible: "+e.message
|
44
52
|
end
|
45
53
|
|
54
|
+
def size_peek
|
55
|
+
options['from_uri'].open(headers) do |u|
|
56
|
+
match = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(u.meta['content-range'])
|
57
|
+
match && match[3].to_i
|
58
|
+
end
|
59
|
+
rescue SocketError => e
|
60
|
+
raise SocketError, options['from_uri'].to_s+" inaccessible: "+e.message
|
61
|
+
end
|
62
|
+
|
46
63
|
def headers
|
47
64
|
headers={'Range' => 'bytes=0-7'}
|
48
65
|
headers['X-Auth-Token'] = options['authenticator'].call if http_authentication?
|
data/lib/uricp/version.rb
CHANGED
data/lib/uricp.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uricp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|