uricp 0.0.7 → 0.0.8
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.
- data/Gemfile.lock +1 -1
- data/bin/segment_upload +2 -1
- data/bin/uricp +10 -1
- data/features/segmented_upload.feature +5 -0
- data/features/segmented_upload_options.feature +6 -3
- data/features/step_definitions/orbit_steps.rb +9 -0
- data/lib/uricp/curl_primitives.rb +2 -2
- data/lib/uricp/orbit_auth.rb +37 -14
- data/lib/uricp/strategy/piped_remote_get.rb +1 -1
- data/lib/uricp/version.rb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/bin/segment_upload
CHANGED
@@ -14,6 +14,7 @@ class App
|
|
14
14
|
main do |to_uri,|
|
15
15
|
options['auth_uri'] = options['to_uri'] = URI(to_uri)
|
16
16
|
options['segment-size'] = Filesize.from(options['segment-size'])
|
17
|
+
puts options.inspect
|
17
18
|
Uricp::OrbitAuth.validate_options(options)
|
18
19
|
Uricp::OrbitAuth.add_auth_token(options)
|
19
20
|
validate_options
|
@@ -29,7 +30,7 @@ class App
|
|
29
30
|
raise Uricp::UnsupportedURLtype,
|
30
31
|
"unsupported url: Can only perform a segmented upload to an HTTP(S) URL"
|
31
32
|
end
|
32
|
-
unless options['
|
33
|
+
unless options['authenticator']
|
33
34
|
raise OptionParser::MissingArgument,
|
34
35
|
"Need authentication to proceed - supply 'auth-user' or 'auth-token'"
|
35
36
|
end
|
data/bin/uricp
CHANGED
@@ -20,13 +20,22 @@ class App
|
|
20
20
|
end
|
21
21
|
validate_options
|
22
22
|
Uricp::OrbitAuth.validate_options(options)
|
23
|
+
set_auth_env
|
23
24
|
Uricp::OrbitAuth.add_auth_token(options)
|
24
|
-
ENV['URICP'] = "--auth-token='#{options['auth-token']}'"
|
25
25
|
add_cache_name
|
26
26
|
add_temp_area
|
27
27
|
run_command
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.set_auth_env
|
31
|
+
cla = ""
|
32
|
+
cla << "--auth-user='#{options['auth-user']}' " if options['auth-user']
|
33
|
+
cla << "--auth-key='#{options['auth-key']}' " if options['auth-key']
|
34
|
+
cla << "--auth-token='#{options['auth-token']}' " if options['auth-token']
|
35
|
+
ENV['URICP'] = cla unless cla.empty?
|
36
|
+
debug "#{self.name} Environment Command Line Args are: #{ENV['URICP']}"
|
37
|
+
end
|
38
|
+
|
30
39
|
def self.run_command
|
31
40
|
command_list = build_command
|
32
41
|
if options['dry-run']
|
@@ -26,3 +26,8 @@ Feature: Segmented Upload Command
|
|
26
26
|
Then a 102400 byte entry should exist in container "temp_dlo" called "img-testb"
|
27
27
|
And the container "temp_dlo" should contain 11 entries
|
28
28
|
|
29
|
+
Scenario: Create DLO with bad token and fail
|
30
|
+
Given a 102400 byte file named "/tmp/uricp/srv-testc"
|
31
|
+
When I upload "img-testc" with segment size "10kib" into container "temp_dlo" from "/tmp/uricp/srv-testc" with token "abcdef"
|
32
|
+
Then the exit status should not be 0
|
33
|
+
And the stderr should contain "failed"
|
@@ -3,6 +3,9 @@ Feature: Documented Help for Segmented Upload
|
|
3
3
|
As a command line user
|
4
4
|
I want to get detailed usage information
|
5
5
|
|
6
|
+
Background:
|
7
|
+
Given the default aruba timeout is 15 seconds
|
8
|
+
|
6
9
|
Scenario: Basic UI
|
7
10
|
When I get help for "segment_upload"
|
8
11
|
Then the exit status should be 0
|
@@ -45,12 +48,12 @@ Feature: Documented Help for Segmented Upload
|
|
45
48
|
And the stderr should contain "unsupported url"
|
46
49
|
|
47
50
|
Scenario: authentication with normal http should fail
|
48
|
-
When I run `segment_upload --auth-user cli-xxxxx --auth-key fred http://orbit.brightbox.com/v1/acc-tqs4c/downloads`
|
51
|
+
When I run `segment_upload --from /dev/null --auth-user cli-xxxxx --auth-key fred http://orbit.brightbox.com/v1/acc-tqs4c/downloads`
|
49
52
|
Then the exit status should not be 0
|
50
53
|
And the stderr should contain "Cannot authenticate"
|
51
54
|
|
52
55
|
Scenario: bad authentication should fail against orbit
|
53
|
-
When I run `segment_upload --auth-user cli-xxxxx --auth-key fred https://orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
|
56
|
+
When I run `segment_upload --from /dev/null --auth-user cli-xxxxx --auth-key fred https://orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
|
54
57
|
Then the exit status should not be 0
|
55
58
|
And the stderr should contain "Cannot authenticate"
|
56
59
|
|
@@ -60,6 +63,6 @@ Feature: Documented Help for Segmented Upload
|
|
60
63
|
And the stderr should contain "Unparseable filesize"
|
61
64
|
|
62
65
|
Scenario: should trap attempts to open a command
|
63
|
-
When I run `segment_upload --segment-size 100MB --auth-token abcdef --from ' |fred' https
|
66
|
+
When I run `segment_upload --segment-size 100MB --auth-token abcdef --from ' |fred' https://orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
|
64
67
|
Then the exit status should not be 0
|
65
68
|
And the stderr should contain "invalid argument"
|
@@ -145,6 +145,15 @@ When(/^I upload "([^"]*)" with segment size "([^"]*)" into container "([^"]*)" f
|
|
145
145
|
}
|
146
146
|
end
|
147
147
|
|
148
|
+
When(/^I upload "([^"]*)" with segment size "([^"]*)" into container "([^"]*)" from "([^"]*)" with token "([^"]*)"$/) do |name, segment_size, container, source, token|
|
149
|
+
@current_container = container
|
150
|
+
@current_name = name
|
151
|
+
url = File.join(@current_storage_url, container, name)
|
152
|
+
steps %{
|
153
|
+
When I run `segment_upload --from #{source} --auth-token #{token} --segment-size #{segment_size} #{url}`
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
148
157
|
When(/^I upload "([^"]*)" with segment size "([^"]*)" into container "([^"]*)" from "([^"]*)" as a stream$/) do |name, segment_size, container, source|
|
149
158
|
@current_container = container
|
150
159
|
@current_name = name
|
@@ -23,11 +23,11 @@ module Uricp::CurlPrimitives
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def authentication
|
26
|
-
"-H X-Auth-Token:#{options['
|
26
|
+
"-H X-Auth-Token:#{options['authenticator'].call}" if http_authentication?
|
27
27
|
end
|
28
28
|
|
29
29
|
def http_authentication?
|
30
|
-
options['
|
30
|
+
options['authenticator']
|
31
31
|
end
|
32
32
|
|
33
33
|
def curl_upload_from(source, destination = to)
|
data/lib/uricp/orbit_auth.rb
CHANGED
@@ -6,19 +6,23 @@ module Uricp
|
|
6
6
|
AuthenticationFailure = Class.new(ArgumentError)
|
7
7
|
|
8
8
|
def initialize(auth_uri, auth_id, auth_key)
|
9
|
-
auth_uri
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
@auth_uri = auth_uri
|
10
|
+
@auth_id = auth_id
|
11
|
+
@auth_key = auth_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def storage_url
|
15
|
+
@storage_url ||
|
16
|
+
begin
|
17
|
+
authenticate
|
18
|
+
@storage_url
|
19
|
+
end
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
+
def token
|
23
|
+
authenticate
|
24
|
+
@token
|
25
|
+
end
|
22
26
|
|
23
27
|
def self.validate_options(options)
|
24
28
|
if options['auth-token'] && (options['auth-key'] || options['auth-user'])
|
@@ -39,10 +43,14 @@ module Uricp
|
|
39
43
|
if options['auth-user']
|
40
44
|
orbit_credentials = self.new(options['auth_uri'],
|
41
45
|
options['auth-user'], options['auth-key'])
|
42
|
-
options['
|
43
|
-
|
44
|
-
|
46
|
+
options['authenticator'] = orbit_credentials.method(:token)
|
47
|
+
elsif options['auth-token']
|
48
|
+
orbit_token = options['auth-token']
|
49
|
+
options['authenticator'] = lambda { orbit_token }
|
45
50
|
end
|
51
|
+
options.delete('auth-key')
|
52
|
+
options.delete('auth-user')
|
53
|
+
options.delete('auth-token')
|
46
54
|
end
|
47
55
|
|
48
56
|
def self.add_auth_to_optionparser(app)
|
@@ -54,6 +62,21 @@ module Uricp
|
|
54
62
|
"Use AUTH_KEY for authentication")
|
55
63
|
end
|
56
64
|
|
65
|
+
private
|
66
|
+
|
67
|
+
def authenticate
|
68
|
+
@auth_uri.open(
|
69
|
+
'X-Auth-User' => @auth_id,
|
70
|
+
'X-Auth-Key' => @auth_key,
|
71
|
+
'Range' => 'bytes=0-0'
|
72
|
+
) do |uri|
|
73
|
+
@storage_url = uri.meta['x-storage-url']
|
74
|
+
@token = uri.meta['x-auth-token']
|
75
|
+
end
|
76
|
+
rescue OpenURI::HTTPError => e
|
77
|
+
raise AuthenticationFailure, "Cannot authenticate against #{@auth_uri}"
|
78
|
+
end
|
79
|
+
|
57
80
|
end
|
58
81
|
|
59
82
|
end
|
data/lib/uricp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|