kubeclient 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kubeclient might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57b03781d0875698e18791018710eb4c84dce1bf
4
- data.tar.gz: bff15e091daf39f5663b3cac73a28f92a3ed0cc2
3
+ metadata.gz: 06875bb69db97a971297a9623c7dddc960311aa7
4
+ data.tar.gz: e6fabf77ca3e62b6bbe8a4de5046bdbcacf4c91a
5
5
  SHA512:
6
- metadata.gz: f7f8e2ae7884ea7afbca1725905c764b5858d25dce119115b610e4707ec82312fc4e9f710466754fac05edf6da9a2e771422d254162ce7764dce5375e1ce35c2
7
- data.tar.gz: 3041056407fdc8d777bd7e5c32c55298d1c54919c3a10d5daa4e17d6aeb04069f9b12ba74680558768aac2a783bb4d110c77e4aa7cd35bddc4fbbb7c97ffd2ee
6
+ metadata.gz: cd8718be9eeff6a72038e92aade155552a4199ef13d7c8adbf94a4b4e828fee49098cfbf2fa69b997957ad138ec78d358c684036598c5118bd62d5d562c572ef
7
+ data.tar.gz: 6a257ee339f7268225e66e671401e54cc7c9179e31f3f44374a648d8eb5005e8c1fb4b2a746628bb5ab396f9b3bb4a43053472858533a0bd775093128d9ef282
data/README.md CHANGED
@@ -64,13 +64,18 @@ For testing and development purpose you can disable the ssl check with:
64
64
  client.ssl_options(verify_ssl: OpenSSL::SSL::VERIFY_NONE)
65
65
  ```
66
66
 
67
- If you are using bearer tokens for authentication as described
68
- [here](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/authentication.md) then you can specify the
69
- bearer token to use for authentication:
67
+ If you are using basic authentication or bearer tokens as described
68
+ [here](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/authentication.md) then you can specify one
69
+ of the following:
70
70
 
71
71
  ```ruby
72
72
  client.bearer_token('MDExMWJkMjItOWY1Ny00OGM5LWJlNDEtMjBiMzgxODkxYzYz')
73
73
  ```
74
+ <br>
75
+ or <br>
76
+ ```ruby
77
+ client.basic_auth('username', 'password')
78
+ ```
74
79
 
75
80
  If you are running your app using kubeclient inside a Kubernetes cluster, then you can have a bearer token file
76
81
  mounted inside your pod by using a
@@ -71,7 +71,9 @@ module Kubeclient
71
71
  verify_ssl: @ssl_options[:verify_ssl],
72
72
  ssl_client_cert: @ssl_options[:client_cert],
73
73
  ssl_client_key: @ssl_options[:client_key],
74
- bearer_token: @bearer_token
74
+ bearer_token: @bearer_token,
75
+ user: @basic_auth_user,
76
+ password: @basic_auth_password
75
77
  }
76
78
  RestClient::Resource.new(@api_endpoint.merge(path).to_s, options)
77
79
  end
@@ -100,7 +102,9 @@ module Kubeclient
100
102
  verify_mode: @ssl_options[:verify_ssl],
101
103
  cert: @ssl_options[:client_cert],
102
104
  key: @ssl_options[:client_key],
103
- bearer_token: @bearer_token
105
+ bearer_token: @bearer_token,
106
+ basic_auth_user: @basic_auth_user,
107
+ basic_auth_password: @basic_auth_password
104
108
  }
105
109
 
106
110
  WatchStream.new(uri, options)
@@ -224,6 +228,11 @@ module Kubeclient
224
228
  req['authorization'] = "Bearer #{@bearer_token}"
225
229
  end
226
230
  end
231
+
232
+ def basic_auth(user, password)
233
+ @basic_auth_user = user
234
+ @basic_auth_password = password
235
+ end
227
236
  end
228
237
  end
229
238
  end
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '0.1.15'
3
+ VERSION = '0.1.16'
4
4
  end
@@ -15,11 +15,7 @@ module Kubeclient
15
15
  @http = Net::HTTP.start(@uri.host, @uri.port, @options)
16
16
 
17
17
  buffer = ''
18
- request = Net::HTTP::Get.new(@uri)
19
-
20
- if @options[:bearer_token]
21
- request['authorization'] = "Bearer #{@options[:bearer_token]}"
22
- end
18
+ request = generate_request
23
19
 
24
20
  @http.request(request) do |response|
25
21
  unless response.is_a? Net::HTTPSuccess
@@ -36,6 +32,19 @@ module Kubeclient
36
32
  raise unless @finished
37
33
  end
38
34
 
35
+ def generate_request
36
+ request = Net::HTTP::Get.new(@uri)
37
+ if @options[:basic_auth_user] && @options[:basic_auth_password]
38
+ request.basic_auth @options[:basic_auth_user],
39
+ @options[:basic_auth_password]
40
+ end
41
+
42
+ if @options[:bearer_token]
43
+ request['authorization'] = "Bearer #{@options[:bearer_token]}"
44
+ end
45
+ request
46
+ end
47
+
39
48
  def finish
40
49
  @finished = true
41
50
  @http.finish if !@http.nil? && @http.started?
@@ -245,6 +245,7 @@ class KubeClientTest < MiniTest::Test
245
245
 
246
246
  assert_equal('Pod', pods.kind)
247
247
  assert_equal(1, pods.size)
248
+ RestClient.reset_before_execution_procs
248
249
  end
249
250
 
250
251
  def test_api_bearer_token_failure
@@ -261,6 +262,41 @@ class KubeClientTest < MiniTest::Test
261
262
  exception = assert_raises(KubeException) { client.get_pods }
262
263
  assert_equal(403, exception.error_code)
263
264
  assert_equal(error_message, exception.message)
265
+ RestClient.reset_before_execution_procs
266
+ end
267
+
268
+ def test_api_basic_auth_success
269
+ stub_request(:get, 'http://username:password@localhost:8080/api/v1beta3/pods')
270
+ .to_return(body: open_test_json_file('pod_list_b3.json'),
271
+ status: 200)
272
+
273
+ client = Kubeclient::Client.new 'http://localhost:8080/api/'
274
+ client.basic_auth('username', 'password')
275
+
276
+ pods = client.get_pods
277
+
278
+ assert_equal('Pod', pods.kind)
279
+ assert_equal(1, pods.size)
280
+ assert_requested(:get,
281
+ 'http://username:password@localhost:8080/api/v1beta3/pods',
282
+ times: 1)
283
+ end
284
+
285
+ def test_api_basic_auth_failure
286
+ error_message = 'HTTP status code 401, 401 Unauthorized'
287
+
288
+ stub_request(:get, 'http://username:password@localhost:8080/api/v1beta3/pods')
289
+ .to_raise(KubeException.new(401, error_message))
290
+
291
+ client = Kubeclient::Client.new 'http://localhost:8080/api/'
292
+ client.basic_auth('username', 'password')
293
+
294
+ exception = assert_raises(KubeException) { client.get_pods }
295
+ assert_equal(401, exception.error_code)
296
+ assert_equal(error_message, exception.message)
297
+ assert_requested(:get,
298
+ 'http://username:password@localhost:8080/api/v1beta3/pods',
299
+ times: 1)
264
300
  end
265
301
 
266
302
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubeclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alissa Bonas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler