webhdfs 0.7.4 → 0.10.1

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: 3633c5408544086d96f4274e31f80e193227d3e5
4
- data.tar.gz: d882245ff5d655ba2fd87d54b80261859191b111
2
+ SHA256:
3
+ metadata.gz: 202827bff28692693795a0b47541acfa5198fdc375401cdcdae0509ac1b01440
4
+ data.tar.gz: 5b23890cae46ba9363aa3facedd60c083e0bfaf74ba59aae233c866a949ba8bf
5
5
  SHA512:
6
- metadata.gz: 5c3a6ddc8842f41bd40a6ff845059aae459d2e63bc2694b868fba029a8e7aa5ed7c64b097133b69f43986baf43930259303eb0f8d339d74a6cb1d0dd5730c35c
7
- data.tar.gz: 644c24ba30a07b4acf078e9ba222dcdfcfcec60e35f072b2b0fe1e61f547e4352a6efef646ff90677b8ea67cf98b4e884b79d15e1a3b285adf0cfc753b40d770
6
+ metadata.gz: 85dc05b030202720b9baf7d4f60232232ff121fff4e7b49a4e6a9fd563df6ccb0293a52f793781aa2d48b2ecd9516e8851eca1b316d002af2dc5d6734dd8a977
7
+ data.tar.gz: edef2f1401b86df2b57fc253e9418837a331df79c4a5c388f41e5d88755c1a9944689107faaaee65849a6a7c481d0cd9c9df3b4f14b65598ec54f8daa7ef0f49
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.7.4
1
+ 0.10.1
@@ -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 expired
432
+ if res.code == '403' and @renew_kerberos_delegation_token_time_hour
433
+ if message.include?('{"RemoteException":{')
434
+ detail = JSON.parse(message) rescue nil
435
+ if detail&.dig('RemoteException', 'exception') == 'InvalidToken' and 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
@@ -7,14 +7,13 @@ Gem::Specification.new do |gem|
7
7
  gem.homepage = "https://github.com/kzk/webhdfs/"
8
8
  gem.summary = gem.description
9
9
  gem.version = File.read("VERSION").strip
10
- gem.authors = ["Kazuki Ohta"]
11
- gem.email = "kazuki.ohta@gmail.com"
10
+ gem.authors = ["Kazuki Ohta", "Satoshi Tagomori"]
11
+ gem.email = ["kazuki.ohta@gmail.com", "tagomoris@gmail.com"]
12
12
  gem.has_rdoc = false
13
- #gem.platform = Gem::Platform::RUBY
14
- gem.files = `git ls-files`.split("\n")
15
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = Dir['lib/**/*','test/**/*','*.gemspec','*.md','AUTHORS','COPYING','Gemfile','VERSION']
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
15
  gem.require_paths = ['lib']
16
+ gem.licenses = ["Apache-2.0"]
18
17
 
19
18
  gem.add_development_dependency "rake"
20
19
  gem.add_development_dependency "rdoc"
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhdfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuki Ohta
8
- autorequire:
8
+ - Satoshi Tagomori
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-12-22 00:00:00.000000000 Z
12
+ date: 2021-08-12 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
@@ -81,17 +82,17 @@ dependencies:
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
84
  description: Ruby WebHDFS/HttpFs client
84
- email: kazuki.ohta@gmail.com
85
+ email:
86
+ - kazuki.ohta@gmail.com
87
+ - tagomoris@gmail.com
85
88
  executables: []
86
89
  extensions: []
87
90
  extra_rdoc_files: []
88
91
  files:
89
- - ".gitignore"
90
92
  - AUTHORS
91
93
  - COPYING
92
94
  - Gemfile
93
95
  - README.md
94
- - Rakefile
95
96
  - VERSION
96
97
  - lib/webhdfs.rb
97
98
  - lib/webhdfs/backport.rb
@@ -103,9 +104,10 @@ files:
103
104
  - test/webhdfs/fileutils.rb
104
105
  - webhdfs.gemspec
105
106
  homepage: https://github.com/kzk/webhdfs/
106
- licenses: []
107
+ licenses:
108
+ - Apache-2.0
107
109
  metadata: {}
108
- post_install_message:
110
+ post_install_message:
109
111
  rdoc_options: []
110
112
  require_paths:
111
113
  - lib
@@ -120,12 +122,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  - !ruby/object:Gem::Version
121
123
  version: '0'
122
124
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.4.5
125
- signing_key:
125
+ rubygems_version: 3.2.3
126
+ signing_key:
126
127
  specification_version: 4
127
128
  summary: Ruby WebHDFS/HttpFs client
128
129
  test_files:
129
130
  - test/test_helper.rb
130
131
  - test/webhdfs/fileutils.rb
131
- has_rdoc: false
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- /pkg/
2
- /coverage/
3
- /vendor/
4
- Gemfile.lock
data/Rakefile DELETED
@@ -1,21 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rake/testtask'
5
-
6
- Rake::TestTask.new(:test) do |test|
7
- test.libs << 'lib' << 'test'
8
- test.test_files = FileList['test/webhdfs/*.rb']
9
- test.verbose = true
10
- end
11
-
12
- task :doc do |t|
13
- `bundle exec rdoc --markup=tomdoc --visibility=public --include=lib --exclude=test`
14
- end
15
-
16
- task :coverage do |t|
17
- ENV['SIMPLE_COV'] = '1'
18
- Rake::Task["test"].invoke
19
- end
20
-
21
- task :default => [:build]