webhdfs 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 079a9de419dc30c5280876fdb45dc4e6a3844fc1
4
- data.tar.gz: 915c3c102e9ae29a729d6498d2280b2fc94077f3
3
+ metadata.gz: 722d97c3cd885df9fcdf8d6dc6ffb53b85e0781c
4
+ data.tar.gz: 7048f1a9c7346a7e82caa942e71a5680cc930dad
5
5
  SHA512:
6
- metadata.gz: 514504c4024a57b80d81347634c33fa061c82ab28f6f55ff47f9dc5c3dde2efdca053161a912479bb64f2e8e6fef137af1f639848dbe5b1d506b349ac8f6045b
7
- data.tar.gz: 6135ce124d4619ed25a5f1aa790e9cbb7f9cc5a56085256d6bd386f9a9eb0c9fc3a9537b7e8ef72f8a7d19a95afc3f42098c2e3ce5874fcd7526dcb469903a25
6
+ metadata.gz: 404e0069c1e3b01fb74259ba9883ce5a3bb1655775af7481e5270ad8f148699cc689aa3049258161f8e86a6ae4f710509d994ac407323cd8e13fd36f47352efa
7
+ data.tar.gz: e7765eb4be5c4629c7c1f5b5f9bda3721cfb3b90b99e8d170a72f8107a7c1160f73a463aa770005a8f250d49ca7528be403cc35a87def3791e593302686f2846
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem "simplecov", :require => false
data/README.md CHANGED
@@ -87,6 +87,22 @@ For HttpFs instead of WebHDFS:
87
87
  client.proxy_user = 'jack' # if needed
88
88
  client.proxy_pass = 'secret' # if needed
89
89
 
90
+ ### For SSL
91
+
92
+ Note that net/https and openssl libraries must be available:
93
+
94
+ client = WebHDFS::Client.new('hostname', 4443)
95
+ client.ssl = true
96
+ client.ssl_ca_file = "/path/to/ca_file.pem" # if needed
97
+ client.ssl_varify_mode = :peer # if needed (:none or :peer)
98
+
99
+ ### For Kerberos Authentication
100
+
101
+ Note that [gssapi](https://github.com/zenchild/gssapi) library must be available:
102
+
103
+ client = WebHDFS::Client.new('hostname', 14000)
104
+ client.kerberos = true
105
+
90
106
  ## AUTHORS
91
107
 
92
108
  * Kazuki Ohta <kazuki.ohta@gmail.com>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.6.0
@@ -19,6 +19,18 @@ module WebHDFS
19
19
  attr_accessor :retry_known_errors # default false (not to retry)
20
20
  attr_accessor :retry_times # default 1 (ignored when retry_known_errors is false)
21
21
  attr_accessor :retry_interval # default 1 ([sec], ignored when retry_known_errors is false)
22
+ attr_accessor :ssl
23
+ attr_accessor :ssl_ca_file
24
+ attr_reader :ssl_verify_mode
25
+ attr_accessor :kerberos
26
+
27
+ SSL_VERIFY_MODES = [:none, :peer]
28
+ def ssl_verify_mode=(mode)
29
+ unless SSL_VERIFY_MODES.include? mode
30
+ raise ArgumentError, "Invalid SSL verify mode #{mode.inspect}"
31
+ end
32
+ @ssl_verify_mode = mode
33
+ end
22
34
 
23
35
  def initialize(host='localhost', port=50070, username=nil, doas=nil, proxy_address=nil, proxy_port=nil)
24
36
  @host = host
@@ -32,6 +44,12 @@ module WebHDFS
32
44
  @retry_interval = 1
33
45
 
34
46
  @httpfs_mode = false
47
+
48
+ @ssl = false
49
+ @ssl_ca_file = nil
50
+ @ssl_verify_mode = nil
51
+
52
+ @kerberos = false
35
53
  end
36
54
 
37
55
  # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATE
@@ -267,11 +285,39 @@ module WebHDFS
267
285
  else
268
286
  path
269
287
  end
288
+ if @ssl
289
+ conn.use_ssl = true
290
+ conn.ca_file = @ssl_ca_file if @ssl_ca_file
291
+ if @ssl_verify_mode
292
+ require 'openssl'
293
+ conn.verify_mode = case @ssl_verify_mode
294
+ when :none then OpenSSL::SSL::VERIFY_NONE
295
+ when :peer then OpenSSL::SSL::VERIFY_PEER
296
+ end
297
+ end
298
+ end
299
+
300
+ gsscli = nil
301
+ if @kerberos
302
+ require 'base64'
303
+ require 'gssapi'
304
+ gsscli = GSSAPI::Simple.new(@host, 'HTTP')
305
+ token = nil
306
+ begin
307
+ token = gsscli.init_context
308
+ rescue => e
309
+ raise WebHDFS::KerberosError, e.message
310
+ end
311
+ if header
312
+ header['Authorization'] = "Negotiate #{Base64.strict_encode64(token)}"
313
+ else
314
+ header = {'Authorization' => "Negotiate #{Base64.strict_encode64(token)}"}
315
+ end
316
+ end
270
317
 
271
318
  res = nil
272
- if !payload.nil? and payload.is_a?(IO)
319
+ if !payload.nil? and payload.respond_to? :read and payload.respond_to? :size
273
320
  req = Net::HTTPGenericRequest.new(method,(payload ? true : false),true,request_path,header)
274
- raise WebHDFS::IOError, 'Error reading given IO data source' unless payload.respond_to? :read and payload.respond_to? :size
275
321
  raise WebHDFS::ClientError, 'Error accepting given IO resource as data payload, Not valid in methods other than PUT and POST' unless (method == 'PUT' or method == 'POST')
276
322
 
277
323
  req.body_stream = payload
@@ -281,6 +327,19 @@ module WebHDFS
281
327
  res = conn.send_request(method, request_path, payload, header)
282
328
  end
283
329
 
330
+ if @kerberos
331
+ itok = (res.header.get_fields('WWW-Authenticate') || ['']).pop.split(/\s+/).last
332
+ unless itok
333
+ raise WebHDFS::KerberosError, 'Server does not return WWW-Authenticate header'
334
+ end
335
+
336
+ begin
337
+ gsscli.init_context(Base64.strict_decode64(itok))
338
+ rescue => e
339
+ raise WebHDFS::KerberosError, e.message
340
+ end
341
+ end
342
+
284
343
  case res
285
344
  when Net::HTTPSuccess
286
345
  res
@@ -10,3 +10,5 @@ class WebHDFS::ClientError < WebHDFS::Error; end
10
10
  class WebHDFS::ServerError < WebHDFS::Error; end
11
11
 
12
12
  class WebHDFS::RequestFailedError < WebHDFS::Error; end
13
+
14
+ class WebHDFS::KerberosError < WebHDFS::Error; end
@@ -8,6 +8,10 @@ module WebHDFS
8
8
  @fu_user = nil
9
9
  @fu_doas = nil
10
10
  @fu_httpfs_mode = false
11
+ @fu_ssl = false
12
+ @fu_ssl_ca_file = nil
13
+ @fu_ssl_verify_mode = nil
14
+ @fu_kerberos = false
11
15
 
12
16
  # Public: Set hostname and port number of WebHDFS
13
17
  #
@@ -45,6 +49,58 @@ module WebHDFS
45
49
  end
46
50
  module_function :set_httpfs_mode
47
51
 
52
+ # Public: Set ssl enable/disable
53
+ #
54
+ # mode - boolean (default true)
55
+ #
56
+ # Examples
57
+ #
58
+ # FileUtils.set_ssl
59
+ #
60
+ def set_ssl(mode=true)
61
+ @fu_ssl = mode
62
+ end
63
+ module_function :set_ssl
64
+
65
+ # Public: Set ssl ca_file
66
+ #
67
+ # ca_file - string
68
+ #
69
+ # Examples
70
+ #
71
+ # FileUtils.set_ca_file("/path/to/ca_file.pem")
72
+ #
73
+ def set_ssl_ca_file(ca_file)
74
+ @fu_ssl_ca_file = ca_file
75
+ end
76
+ module_function :set_ssl_ca_file
77
+
78
+ # Public: Set ssl verify mode
79
+ #
80
+ # mode - :none or :peer
81
+ #
82
+ # Examples
83
+ #
84
+ # FileUtils.set_ssl_verify_mode(:peer)
85
+ #
86
+ def set_ssl_verify_mode(mode)
87
+ @fu_ssl_verify_mode = mode
88
+ end
89
+ module_function :set_ssl_verify_mode
90
+
91
+ # Public: Set kerberos authentication enable/disable
92
+ #
93
+ # mode - boolean (default true)
94
+ #
95
+ # Examples
96
+ #
97
+ # FileUtils.set_kerberos
98
+ #
99
+ def set_kerberos(mode=true)
100
+ @fu_kerberos = mode
101
+ end
102
+ module_function :set_kerberos
103
+
48
104
  # Public: Copy local file into HDFS
49
105
  #
50
106
  # file - local file path
@@ -363,6 +419,10 @@ module WebHDFS
363
419
  if @fu_httpfs_mode
364
420
  client.httpfs_mode = true
365
421
  end
422
+ client.ssl = true if @fu_ssl
423
+ client.ssl_ca_file = @fu_ssl_ca_file if @fu_ssl_ca_file
424
+ client.ssl_verify_mode = @fu_ssl_verify_mode if @fu_ssl_verify_mode
425
+ client.kerberos = true if @fu_kerberos
366
426
  client
367
427
  end
368
428
  private_module_function :client
data/webhdfs.gemspec CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  gem.require_paths = ['lib']
18
18
 
19
- gem.add_development_dependency "rake", ">= 0.9.2"
20
- gem.add_development_dependency "rdoc", ">= 3.12"
21
- gem.add_development_dependency "simplecov", ">= 0.5.4"
22
- gem.add_development_dependency "rr", ">= 1.0.0"
19
+ gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "rdoc"
21
+ gem.add_development_dependency "simplecov"
22
+ gem.add_development_dependency "rr"
23
23
  end
metadata CHANGED
@@ -1,78 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhdfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuki Ohta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.2
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.2
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.12'
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
- version: '3.12'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.5.4
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
- version: 0.5.4
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rr
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.0
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
- version: 1.0.0
68
+ version: '0'
69
69
  description: Ruby WebHDFS/HttpFs client
70
70
  email: kazuki.ohta@gmail.com
71
71
  executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
- - .gitignore
75
+ - ".gitignore"
76
76
  - AUTHORS
77
77
  - COPYING
78
78
  - Gemfile
@@ -97,21 +97,20 @@ require_paths:
97
97
  - lib
98
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.0.3
110
+ rubygems_version: 2.2.2
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Ruby WebHDFS/HttpFs client
114
114
  test_files:
115
115
  - test/test_helper.rb
116
116
  - test/webhdfs/fileutils.rb
117
- has_rdoc: false