pdc 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 234203e23bbe2f53796496c2048352e4029c6821
4
- data.tar.gz: cd1c02de0fe5905a7312dc5f843b7ca7cc2986a9
3
+ metadata.gz: fd047fc7a9762e173273f35116a7ba835cdaa219
4
+ data.tar.gz: 627c88b0bd6f4c5ad0a0192b5e47055fec975499
5
5
  SHA512:
6
- metadata.gz: a85cc7e23ec88086c115e4071de94266f327ffdb05044205cf469b1c46e9aced707bfc21ab64c642136d59fd5b617e20ff2a6e2569c4e6262eaf8c0816982d0b
7
- data.tar.gz: 1f31b025816cebc99da89a81dd768a7fd9741ebcac826f69ced6b2a0a6f27093b0215fd81ff3be743321ea56bdf4fc96b162562e57b0cc89cf60cefbd84a491d
6
+ metadata.gz: 0d6b3965169451b4903d7e00dda6a067df65eeda6e6c944391db1c159f06953b2ea42ec42c7816125eafe25d3fb5184e8f98f49e5c42cd51fb3650890fff3724
7
+ data.tar.gz: 00f4ec8818140c9031cd748c1280e60b279724984e5a3fdcc26a1123e4f65cbea714ed5bdadb8e66c6a5a9ffa8b32cfd96432d8eff8d7cfefbab16f6fd5f0cd4
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'ap'
4
+ require 'pdc'
5
+
6
+ def main
7
+ PDC.configure do |config|
8
+ config.site = 'https://pdc.engineering.redhat.com/'
9
+ config.log_level = :debug
10
+ config.ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
11
+ end
12
+
13
+ puts "Release count: #{PDC::V1::Release.count}"
14
+ end
15
+
16
+ main if __FILE__ == $PROGRAM_NAME
data/lib/pdc/config.rb CHANGED
@@ -9,7 +9,6 @@ module PDC
9
9
  #
10
10
  # :site => 'http://localhost:2990',
11
11
  # :ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER,
12
- # :use_ssl => true,
13
12
  # :username => nil,
14
13
  # :password => nil,
15
14
  # :auth_type => :oauth
@@ -24,7 +23,6 @@ module PDC
24
23
  :site,
25
24
  :api_root,
26
25
 
27
- :use_ssl,
28
26
  :ssl_verify_mode,
29
27
 
30
28
  :requires_token,
@@ -42,7 +40,6 @@ module PDC
42
40
  # site config
43
41
  self.site = 'http://localhost:8000'
44
42
  self.api_root = 'rest_api/'
45
- self.use_ssl = true
46
43
  self.ssl_verify_mode = OpenSSL::SSL::VERIFY_PEER
47
44
 
48
45
  # token and authentication
@@ -90,13 +87,15 @@ module PDC
90
87
  end
91
88
 
92
89
  def token
93
- config.token || Request::TokenFetcher.fetch(token_url)
90
+ return unless config.requires_token
91
+ config.token || Request::TokenFetcher.fetch
94
92
  end
95
93
 
96
94
  private
97
95
 
98
96
  def apply_config
99
97
  reset_logger
98
+ reset_token_fetcher
100
99
  reset_base_connection
101
100
  end
102
101
 
@@ -105,6 +104,13 @@ module PDC
105
104
  logger.level = Logger.const_get(config.log_level.upcase)
106
105
  end
107
106
 
107
+ def reset_token_fetcher
108
+ Request::TokenFetcher.configure do |c|
109
+ c.url = token_url
110
+ c.ssl_verify_mode = config.ssl_verify_mode
111
+ end
112
+ end
113
+
108
114
  # resets and returns the +Faraday+ +connection+ object
109
115
  def reset_base_connection
110
116
 
@@ -116,7 +122,7 @@ module PDC
116
122
 
117
123
  PDC::Base.connection = Faraday.new(faraday_config) do |c|
118
124
  c.request :append_slash_to_path
119
- c.request :pdc_token, token: config.token, token_url: token_url if config.requires_token
125
+ c.request :pdc_token, token: config.token if config.requires_token
120
126
 
121
127
  c.response :logger, config.logger
122
128
  c.response :pdc_paginator
@@ -24,7 +24,7 @@ module PDC::Request
24
24
 
25
25
  # uses the token passed or fetches one only once
26
26
  def token
27
- @token ||= options[:token] || TokenFetcher.fetch(options[:token_url])
27
+ @token ||= options[:token] || TokenFetcher.fetch
28
28
  end
29
29
  end
30
30
  end
@@ -4,23 +4,30 @@ require 'json'
4
4
  module PDC::Request
5
5
  module TokenFetcher
6
6
 
7
- # uses kerberos token to obtain token from pdc
8
- def self.fetch(token_url)
9
- PDC.logger.debug "Fetch token from: #{token_url}"
10
- curl = Curl::Easy.new(token_url.to_s) do |request|
11
- request.headers['Accept'] = 'application/json'
12
- request.http_auth_types = :gssnegotiate
7
+ module Configuration
8
+ VALID_KEYS = [:ssl_verify_mode, :url].freeze
13
9
 
14
- # The curl man page (http://curl.haxx.se/docs/manpage.html)
15
- # specifes setting a fake username when using Negotiate auth,
16
- # and use ':' in their example.
17
- request.username = ':'
10
+ attr_accessor(*VALID_KEYS)
11
+
12
+ def options
13
+ Hash[*VALID_KEYS.map { |k| [k, send(k)] }.flatten]
14
+ end
15
+
16
+ def configure
17
+ yield self
18
18
  end
19
+ end
20
+ extend Configuration
19
21
 
22
+ # uses kerberos token to obtain token from pdc
23
+ def self.fetch
24
+ PDC.logger.debug "Fetch token from: #{url}"
25
+
26
+ curl = curl_easy
20
27
  curl.perform
21
28
  if curl.response_code != 200
22
- PDC.logger.info "Obtain token from #{token_url} failed: #{curl.body_str}"
23
- error = { token_url: token_url, body: curl.body, code: curl.response_code }
29
+ PDC.logger.info "Obtain token from #{url} failed: #{curl.body_str}"
30
+ error = { url: url, body: curl.body, code: curl.response_code }
24
31
  raise PDC::TokenFetchFailed, error
25
32
  end
26
33
  result = JSON.parse(curl.body_str)
@@ -28,5 +35,17 @@ module PDC::Request
28
35
  result['token']
29
36
  end
30
37
 
38
+ def self.curl_easy
39
+ Curl::Easy.new(url.to_s) do |request|
40
+ request.ssl_verify_peer = ssl_verify_mode != OpenSSL::SSL::VERIFY_NONE
41
+ request.headers['Accept'] = 'application/json'
42
+ request.http_auth_types = :gssnegotiate
43
+
44
+ # The curl man page (http://curl.haxx.se/docs/manpage.html)
45
+ # specifes setting a fake username when using Negotiate auth,
46
+ # and use ':' in their example.
47
+ request.username = ':'
48
+ end
49
+ end
31
50
  end
32
51
  end
data/lib/pdc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PDC
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -57,6 +57,30 @@ describe PDC do
57
57
  assert_requested releases, times: 3
58
58
  end
59
59
 
60
+ it 'will not cache PDC.token call' do
61
+ token = stub_request(:get, token_url).to_return_json(token: 'foobar')
62
+
63
+ PDC.configure { |pdc| pdc.site = site }
64
+ assert_not_requested token
65
+
66
+ PDC.token.must_equal 'foobar'
67
+ PDC.token.must_equal 'foobar'
68
+
69
+ assert_requested token, times: 2
70
+ end
71
+
72
+ it 'will not fetch token if already set' do
73
+ token = stub_request(:get, token_url).to_return_json(token: 'foobar')
74
+
75
+ PDC.configure do |pdc|
76
+ pdc.site = site
77
+ pdc.token = :a_known_token
78
+ end
79
+
80
+ PDC.token.must_equal :a_known_token
81
+ assert_not_requested token
82
+ end
83
+
60
84
  it 'raises TokenFetchFailed when fails' do
61
85
  token = stub_request(:get, token_url).to_return_json(
62
86
  { detail: 'Not found' },
@@ -84,7 +108,6 @@ describe PDC do
84
108
  it 'allows default site to be overridden ' do
85
109
  PDC.configure do |config|
86
110
  config.site = 'http://localhost:8888'
87
- config.token = :foo
88
111
  end
89
112
  PDC.config.site.must_equal 'http://localhost:8888'
90
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunil Thaha
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-08 00:00:00.000000000 Z
12
+ date: 2016-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -163,6 +163,7 @@ files:
163
163
  - examples/pdc_test_cache.rb
164
164
  - examples/prod_failures.rb
165
165
  - examples/prod_pdc.rb
166
+ - examples/test_no_ssl_verification.rb
166
167
  - lib/pdc.rb
167
168
  - lib/pdc/base.rb
168
169
  - lib/pdc/config.rb