webhdfs 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/lib/webhdfs/client_v1.rb +13 -7
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 202827bff28692693795a0b47541acfa5198fdc375401cdcdae0509ac1b01440
4
- data.tar.gz: 5b23890cae46ba9363aa3facedd60c083e0bfaf74ba59aae233c866a949ba8bf
3
+ metadata.gz: 1d66d42e71b87236b2c3724f9d30b282ed01a5bd42ec471a56af560e494ce425
4
+ data.tar.gz: 9c230c32273448bc62e8359fe0849189e5ffcabb3adf15951c3f0c4614ea2e1c
5
5
  SHA512:
6
- metadata.gz: 85dc05b030202720b9baf7d4f60232232ff121fff4e7b49a4e6a9fd563df6ccb0293a52f793781aa2d48b2ecd9516e8851eca1b316d002af2dc5d6734dd8a977
7
- data.tar.gz: edef2f1401b86df2b57fc253e9418837a331df79c4a5c388f41e5d88755c1a9944689107faaaee65849a6a7c481d0cd9c9df3b4f14b65598ec54f8daa7ef0f49
6
+ metadata.gz: f034571c3ba98a201df86159e0ab60a8f17359d5f6dc8d761e1a06370f40dd66ce166418d13c4ffe860078a33d528ea11c5c1d558c41d03d637cc89f8a96c698
7
+ data.tar.gz: b198731f0f369bcd83ba931babe7ec6d145975ef4138eb7c2515ff169c962e64767313bb10668bd73db4d4e1e5e2210ef2da2da406a10d51c53098616875ac82
data/README.md CHANGED
@@ -102,8 +102,8 @@ 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)
105
+ # or if you want to use client delegation token with renewing per 8 hours and delegation token max-lifetime is 7 days
106
+ client = WebHDFS::Client.new('hostname', 14000, username, nil, nil, nil, {}, 8, 168)
107
107
 
108
108
  client.kerberos = true
109
109
  client.kerberos_keytab = "/path/to/project.keytab"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.1
1
+ 0.11.0
@@ -2,7 +2,7 @@ require 'net/http'
2
2
  require 'uri'
3
3
  require 'json'
4
4
  require 'addressable/uri'
5
-
5
+ require "base64"
6
6
  require_relative 'exceptions'
7
7
 
8
8
  module WebHDFS
@@ -38,7 +38,7 @@ module WebHDFS
38
38
  @ssl_verify_mode = mode
39
39
  end
40
40
 
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
+ 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,kerberos_delegation_token_max_lifetime_hour=nil)
42
42
  @host = host
43
43
  @port = port
44
44
  @username = username
@@ -61,21 +61,27 @@ module WebHDFS
61
61
  @kerberos = false
62
62
  @kerberos_keytab = nil
63
63
  @renew_kerberos_delegation_token_time_hour = renew_kerberos_delegation_token_time_hour
64
+ @kerberos_delegation_token_max_lifetime_hour = kerberos_delegation_token_max_lifetime_hour
64
65
  @kerberos_delegation_token = nil
66
+ @kerberos_token_created_at = Time.now
65
67
  @kerberos_token_updated_at = Time.now
66
68
  @http_headers = http_headers
67
69
  end
68
70
 
69
71
  def should_kerberos_token_updated?
70
- @kerberos_token_updated_at + (@renew_kerberos_delegation_token_time_hour * 60 * 60) <= Time.now
72
+ (@kerberos_token_updated_at + (@renew_kerberos_delegation_token_time_hour * 60 * 60) <= Time.now) || is_delegation_token_lifetime_expired?
71
73
  end
72
74
 
75
+ def is_delegation_token_lifetime_expired?
76
+ (@kerberos_token_created_at + (@kerberos_delegation_token_max_lifetime_hour * 60 * 60 ) <= Time.now)
77
+ end
73
78
 
74
79
  def get_cached_kerberos_delegation_token(force_renew=nil)
75
80
  return @kerberos_delegation_token if @kerberos_delegation_token && !should_kerberos_token_updated? && !force_renew
76
81
 
77
- if !@kerberos_delegation_token || force_renew
82
+ if !@kerberos_delegation_token || force_renew || is_delegation_token_lifetime_expired?
78
83
  @kerberos_delegation_token = get_kerberos_delegation_token(@username)
84
+ @kerberos_token_created_at = Time.now
79
85
  @kerberos_token_updated_at = Time.now
80
86
  else
81
87
  renew_kerberos_delegation_token(@kerberos_delegation_token)
@@ -428,11 +434,11 @@ module WebHDFS
428
434
  'Response body is empty...'
429
435
  end
430
436
 
431
- # when delegation token is expired
432
- if res.code == '403' and @renew_kerberos_delegation_token_time_hour
437
+ # when delegation token is invalid
438
+ if res.code == '403' and @renew_kerberos_delegation_token_time_hour && retries < @retry_times
433
439
  if message.include?('{"RemoteException":{')
434
440
  detail = JSON.parse(message) rescue nil
435
- if detail&.dig('RemoteException', 'exception') == 'InvalidToken' and detail&.dig('RemoteException', 'message')&.include?('HDFS_DELEGATION_TOKEN')
441
+ if detail&.dig('RemoteException', 'message')&.include?('HDFS_DELEGATION_TOKEN')
436
442
  params = params.merge('token' => get_cached_kerberos_delegation_token(true))
437
443
  sleep @retry_interval if @retry_interval > 0
438
444
  return request(host, port, method, path, op, params, payload, header, retries+1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhdfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuki Ohta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-12 00:00:00.000000000 Z
12
+ date: 2024-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
- rubygems_version: 3.2.3
125
+ rubygems_version: 3.4.10
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Ruby WebHDFS/HttpFs client