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 CHANGED
@@ -15,7 +15,7 @@ GEM
15
15
  cucumber (>= 1.1.1)
16
16
  rspec-expectations (>= 2.7.0)
17
17
  builder (3.2.2)
18
- childprocess (0.5.5)
18
+ childprocess (0.5.6)
19
19
  ffi (~> 1.0, >= 1.0.11)
20
20
  cucumber (1.3.19)
21
21
  builder (>= 2.1.2)
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['auth-token']
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:///orbit.brightbox.com/v1/acc-xxxxx/test/test.img`
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['auth-token']}" if http_authentication?
26
+ "-H X-Auth-Token:#{options['authenticator'].call}" if http_authentication?
27
27
  end
28
28
 
29
29
  def http_authentication?
30
- options['auth-token']
30
+ options['authenticator']
31
31
  end
32
32
 
33
33
  def curl_upload_from(source, destination = to)
@@ -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.open(
10
- 'X-Auth-User' => auth_id,
11
- 'X-Auth-Key' => auth_key,
12
- 'Range' => 'bytes=0-0'
13
- ) do |uri|
14
- @storage_url = uri.meta['x-storage-url']
15
- @token = uri.meta['x-auth-token']
16
- end
17
- rescue OpenURI::HTTPError => e
18
- raise AuthenticationFailure, "Cannot authenticate against #{auth_uri}"
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
- attr_reader :storage_url, :token
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['auth-token'] = orbit_credentials.token
43
- options.delete('auth-key')
44
- options.delete('auth-user')
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
@@ -43,7 +43,7 @@ module Uricp::Strategy
43
43
 
44
44
  def headers
45
45
  headers={'Range' => 'bytes=0-7'}
46
- headers['X-Auth-Token'] = options['auth-token'] if http_authentication?
46
+ headers['X-Auth-Token'] = options['authenticator'].call if http_authentication?
47
47
  headers
48
48
  end
49
49
 
data/lib/uricp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Uricp
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  DEFAULT_SEGMENT_SIZE = "5 GiB"
4
4
  end
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.7
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-04-01 00:00:00.000000000 Z
12
+ date: 2015-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler