webhdfs 0.8.0 → 0.10.2

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
- SHA1:
3
- metadata.gz: 3f165b8329507d5bd77e98e14b7b6406b5e74e7b
4
- data.tar.gz: 14a14eeb4a18cb0670e9966398ae9591e31a54bf
2
+ SHA256:
3
+ metadata.gz: 7f1fb40375edf3e4364001418a1c4bf364520c586fe4ba9cda1276e76da60137
4
+ data.tar.gz: eaa642e3f5b85c0d347f7691a88cdd48d441c5bbf8271b599fb246b4ff7e8b63
5
5
  SHA512:
6
- metadata.gz: bddf6b9166720a926de0f43855d7b24e512701a672e4a9c019a5154e20da22657084688eddaf6ac2f383a76321164fc843dc7af65996782ad946e4c9923144a0
7
- data.tar.gz: 6e988dd3694c2dfb015bf0901b890a44e67e0a504ac539a3efcf8979a33ff84769c38c894a3ed7bf287e56596c652eae0cf5b2c6af5f24c2db17e3342320ca18
6
+ metadata.gz: be479f32138f814ff961ce820d9b0af8c4d7ddf4a5a55c6e2aec6b9e093f654f6931ea53f19554a454372f51d5f6d47fbb80264255f1e5393fdc9102dbcdee65
7
+ data.tar.gz: b9081147028452f2e6dd46f14e7337a23fcb8067b8c7b8b7e5aefa79eef861b752c2448feeec9d2524c5ded2739fa807986f69f0e0c0ea8a046a3c5eed314127
data/README.md CHANGED
@@ -102,6 +102,9 @@ Note that net/https and openssl libraries must be available:
102
102
  Note that [gssapi](https://github.com/zenchild/gssapi) library must be available:
103
103
 
104
104
  client = WebHDFS::Client.new('hostname', 14000)
105
+ # or if you want to use client delegation token with renewing per 8 hours
106
+ client = WebHDFS::Client.new('hostname', 14000, username, nil, nil, nil, {}, 8)
107
+
105
108
  client.kerberos = true
106
109
  client.kerberos_keytab = "/path/to/project.keytab"
107
110
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.10.2
@@ -28,6 +28,7 @@ module WebHDFS
28
28
  attr_accessor :ssl_version
29
29
  attr_accessor :kerberos, :kerberos_keytab
30
30
  attr_accessor :http_headers
31
+ attr_accessor :kerberos_delegation_token
31
32
 
32
33
  SSL_VERIFY_MODES = [:none, :peer]
33
34
  def ssl_verify_mode=(mode)
@@ -37,7 +38,7 @@ module WebHDFS
37
38
  @ssl_verify_mode = mode
38
39
  end
39
40
 
40
- def initialize(host='localhost', port=50070, username=nil, doas=nil, proxy_address=nil, proxy_port=nil, http_headers={})
41
+ def initialize(host='localhost', port=50070, username=nil, doas=nil, proxy_address=nil, proxy_port=nil, http_headers={}, renew_kerberos_delegation_token_time_hour=nil)
41
42
  @host = host
42
43
  @port = port
43
44
  @username = username
@@ -59,32 +60,61 @@ module WebHDFS
59
60
 
60
61
  @kerberos = false
61
62
  @kerberos_keytab = nil
63
+ @renew_kerberos_delegation_token_time_hour = renew_kerberos_delegation_token_time_hour
64
+ @kerberos_delegation_token = nil
65
+ @kerberos_token_updated_at = Time.now
62
66
  @http_headers = http_headers
63
67
  end
64
68
 
69
+ def should_kerberos_token_updated?
70
+ @kerberos_token_updated_at + (@renew_kerberos_delegation_token_time_hour * 60 * 60) <= Time.now
71
+ end
72
+
73
+
74
+ def get_cached_kerberos_delegation_token(force_renew=nil)
75
+ return @kerberos_delegation_token if @kerberos_delegation_token && !should_kerberos_token_updated? && !force_renew
76
+
77
+ if !@kerberos_delegation_token || force_renew
78
+ @kerberos_delegation_token = get_kerberos_delegation_token(@username)
79
+ @kerberos_token_updated_at = Time.now
80
+ else
81
+ renew_kerberos_delegation_token(@kerberos_delegation_token)
82
+ @kerberos_token_updated_at = Time.now
83
+ end
84
+ @kerberos_delegation_token
85
+ end
86
+
65
87
  # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATE
66
88
  # [&overwrite=<true|false>][&blocksize=<LONG>][&replication=<SHORT>]
67
- # [&permission=<OCTAL>][&buffersize=<INT>]"
89
+ # [&permission=<OCTAL>][&buffersize=<INT>]
90
+ # [&delegation=<DELEGATION_TOKEN>]"
68
91
  def create(path, body, options={})
69
92
  if @httpfs_mode
70
93
  options = options.merge({'data' => 'true'})
71
94
  end
95
+ if @renew_kerberos_delegation_token_time_hour
96
+ options = options.merge('delegation' => get_cached_kerberos_delegation_token)
97
+ end
72
98
  check_options(options, OPT_TABLE['CREATE'])
73
99
  res = operate_requests('PUT', path, 'CREATE', options, body)
74
100
  res.code == '201'
75
101
  end
76
- OPT_TABLE['CREATE'] = ['overwrite', 'blocksize', 'replication', 'permission', 'buffersize', 'data']
102
+ OPT_TABLE['CREATE'] = ['overwrite', 'blocksize', 'replication', 'permission', 'buffersize', 'data', 'delegation']
77
103
 
78
- # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=APPEND[&buffersize=<INT>]"
104
+ # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=APPEND
105
+ # [&buffersize=<INT>][&delegation=<DELEGATION_TOKEN>]"
79
106
  def append(path, body, options={})
80
107
  if @httpfs_mode
81
108
  options = options.merge({'data' => 'true'})
82
109
  end
110
+ if @renew_kerberos_delegation_token_time_hour
111
+ options = options.merge('delegation' => get_cached_kerberos_delegation_token)
112
+ end
83
113
  check_options(options, OPT_TABLE['APPEND'])
84
114
  res = operate_requests('POST', path, 'APPEND', options, body)
85
115
  res.code == '200'
86
116
  end
87
- OPT_TABLE['APPEND'] = ['buffersize', 'data']
117
+ OPT_TABLE['APPEND'] = ['buffersize', 'data', 'delegation']
88
118
 
89
119
  # curl -i -L "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=OPEN
90
120
  # [&offset=<LONG>][&length=<LONG>][&buffersize=<INT>]"
@@ -164,6 +194,13 @@ module WebHDFS
164
194
  end
165
195
  alias :gethomedirectory :homedir
166
196
 
197
+ # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETTRASHROOT"
198
+ def gettrashroot(options={})
199
+ check_options(options, OPT_TABLE['GETTRASHROOT'])
200
+ res = operate_requests('GET', '/', 'GETTRASHROOT', options)
201
+ check_success_json(res, 'Path')
202
+ end
203
+
167
204
  # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION
168
205
  # [&permission=<OCTAL>]"
169
206
  def chmod(path, mode, options={})
@@ -212,12 +249,25 @@ module WebHDFS
212
249
  OPT_TABLE['SETTIMES'] = ['modificationtime', 'accesstime']
213
250
  alias :settimes :touch
214
251
 
215
- # def delegation_token(user, options={}) # GETDELEGATIONTOKEN
216
- # raise NotImplementedError
217
- # end
218
- # def renew_delegation_token(token, options={}) # RENEWDELEGATIONTOKEN
219
- # raise NotImplementedError
220
- # end
252
+ # curl -i "http://<HOST>:<PORT>/webhdfs/v1/?op=GETDELEGATIONTOKEN&renewer=<USER>"
253
+ def get_kerberos_delegation_token(user, options={})
254
+ options = options.merge({ 'renewer' => user })
255
+ check_options(options, OPT_TABLE['GETDELEGATIONTOKEN'])
256
+ res = operate_requests('GET', '/', 'GETDELEGATIONTOKEN', options)
257
+ check_success_json(res, 'Token')
258
+ JSON.parse(res.body)['Token']['urlString']
259
+ end
260
+ OPT_TABLE['GETDELEGATIONTOKEN'] = ['renewer']
261
+
262
+ # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=<DELEGATION_TOKEN>"
263
+ def renew_kerberos_delegation_token(token, options={})
264
+ options = options.merge({ 'token' => token })
265
+ check_options(options, OPT_TABLE['RENEWDELEGATIONTOKEN'])
266
+ res = operate_requests('PUT', '/', 'RENEWDELEGATIONTOKEN', options)
267
+ check_success_json(res, 'long')
268
+ end
269
+ OPT_TABLE['RENEWDELEGATIONTOKEN'] = ['token']
270
+
221
271
  # def cancel_delegation_token(token, options={}) # CANCELDELEGATIONTOKEN
222
272
  # raise NotImplementedError
223
273
  # end
@@ -352,7 +402,8 @@ module WebHDFS
352
402
  end
353
403
  end
354
404
 
355
- if @kerberos and res.code == '307'
405
+ # if delegation token param settled, namenode do not response WWW-Authenticate header
406
+ if @kerberos and res.code == '307' and not params.key?('delegation')
356
407
  itok = (res.header.get_fields('WWW-Authenticate') || ['']).pop.split(/\s+/).last
357
408
  unless itok
358
409
  raise WebHDFS::KerberosError, 'Server does not return WWW-Authenticate header'
@@ -377,6 +428,18 @@ module WebHDFS
377
428
  'Response body is empty...'
378
429
  end
379
430
 
431
+ # when delegation token is invalid
432
+ if res.code == '403' and @renew_kerberos_delegation_token_time_hour && retries < @retry_times
433
+ if message.include?('{"RemoteException":{')
434
+ detail = JSON.parse(message) rescue nil
435
+ if detail&.dig('RemoteException', 'message')&.include?('HDFS_DELEGATION_TOKEN')
436
+ params = params.merge('token' => get_cached_kerberos_delegation_token(true))
437
+ sleep @retry_interval if @retry_interval > 0
438
+ return request(host, port, method, path, op, params, payload, header, retries+1)
439
+ end
440
+ end
441
+ end
442
+
380
443
  if @retry_known_errors && retries < @retry_times
381
444
  detail = nil
382
445
  if message =~ /^\{"RemoteException":\{/
data/webhdfs.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.files = Dir['lib/**/*','test/**/*','*.gemspec','*.md','AUTHORS','COPYING','Gemfile','VERSION']
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
15
  gem.require_paths = ['lib']
16
+ gem.licenses = ["Apache-2.0"]
16
17
 
17
18
  gem.add_development_dependency "rake"
18
19
  gem.add_development_dependency "rdoc"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhdfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuki Ohta
8
8
  - Satoshi Tagomori
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-03 00:00:00.000000000 Z
12
+ date: 2021-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -104,9 +104,10 @@ files:
104
104
  - test/webhdfs/fileutils.rb
105
105
  - webhdfs.gemspec
106
106
  homepage: https://github.com/kzk/webhdfs/
107
- licenses: []
107
+ licenses:
108
+ - Apache-2.0
108
109
  metadata: {}
109
- post_install_message:
110
+ post_install_message:
110
111
  rdoc_options: []
111
112
  require_paths:
112
113
  - lib
@@ -121,12 +122,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.5.1
126
- signing_key:
125
+ rubygems_version: 3.3.0.dev
126
+ signing_key:
127
127
  specification_version: 4
128
128
  summary: Ruby WebHDFS/HttpFs client
129
129
  test_files:
130
130
  - test/test_helper.rb
131
131
  - test/webhdfs/fileutils.rb
132
- has_rdoc: false