config_server_agent 0.3.4 → 0.3.6

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
  SHA256:
3
- metadata.gz: 14de15ba41b3745d5e2bb54a29534d0a47aa58af4d5c029b2b9b611eec62865f
4
- data.tar.gz: 9f45eb09fa4ee9d0b3b4c9d12e374b42e65350502cf5d4c27cbcbe95fff92cdd
3
+ metadata.gz: 6c19545cad82df1e4454c662b5df2903dc657ce7fba1fe434beb5f5a8bc3465e
4
+ data.tar.gz: 9370374949fd090acaf8b7b1e1eb6b14131b563084b3a6bf393b9b70839b6036
5
5
  SHA512:
6
- metadata.gz: d5c12f02a2b353c43b38a62823c08b9f94ad138346544b660d127d5ec5bb1b40024c0e2e1ba8b9d942ff0ad95da85992605847cd1ed0a8ca73581dccccb56327
7
- data.tar.gz: 9d47199e4a9df1f295bfd29c598cd9fc8c5f4d8b701251378744198107e6dbd4a34a12d47406bc37142c7415b97659413e5afae2762172ad7ae7fdb9a5165dd2
6
+ metadata.gz: 64afbc8473f29730780fadad2f5dfa18c1c8c219b0892f943cdb0b775dfed6c2ac1481ce2faefec19325d34d725f6e7b5616c795e738065bc91ee1bb15523bff
7
+ data.tar.gz: ce866d94120d96437d2746d83cb6888c85fda5e7d310b7e5fdaf27e03110fe21b7ca05114c8e9eaa3f2934c8443f73d8484ad2443101417df22eeb9ba71992df
data/.travis.yml CHANGED
@@ -3,5 +3,11 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.17.1
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ - jruby
11
+ script:
12
+ - bundle exec rake
13
+ - bundle exec bundle-audit check --update
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 0.3.6
8
+ ### Changed
9
+ - Better error handling
10
+ - Tidier and more comprehensive unit tests
11
+
12
+ ## 0.3.5
13
+ ### Changed
14
+ - Set better cache file permissions
15
+
7
16
  ## 0.3.4 - 2019-06-12
8
17
  ### Changed
9
18
  - Added optional token caching
@@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
44
44
 
45
45
  spec.required_ruby_version = '>= 2.3.0'
46
46
 
47
- spec.add_dependency 'lockfile', '~> 2.1'
47
+ spec.add_runtime_dependency 'lockfile', '~> 2.1'
48
48
 
49
49
  spec.add_development_dependency 'bundler', '~> 1.17'
50
50
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,3 +1,3 @@
1
1
  class ConfigServerAgent
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.6'
3
3
  end
@@ -37,7 +37,7 @@ class ConfigServerAgent
37
37
  @token_expires = nil
38
38
  @token = nil
39
39
  @token_ttl = token_ttl
40
- @token_buffer = 10
40
+ @token_buffer = 10 # seconds
41
41
 
42
42
  @use_cache = use_cache
43
43
  @cache_file = cache_file || '/tmp/' + Digest::SHA1.hexdigest("#{auth0_client_id}/#{ConfigServerAgent::VERSION}") + '.json'
@@ -83,35 +83,45 @@ class ConfigServerAgent
83
83
  private
84
84
 
85
85
  def post_request(endpoint, data={})
86
- url = URI "#{@config_server_host}/api/#{endpoint}"
87
- http = Net::HTTP.new url.host, url.port
88
- http.use_ssl = url.scheme == 'https'
89
-
90
- request = Net::HTTP::Post.new url
91
- configure_request request
92
- request.body = data.to_json
93
-
94
- JSON.parse http.request(request).read_body
86
+ dispatch_request(endpoint) do |url|
87
+ request = Net::HTTP::Post.new url
88
+ request.body = data.to_json
89
+ request
90
+ end
95
91
  end
96
92
 
97
93
  def get_request(endpoint, data={})
94
+ dispatch_request(endpoint) do |url|
95
+ url.query = URI.encode_www_form data
96
+ Net::HTTP::Get.new url
97
+ end
98
+ end
99
+
100
+ def dispatch_request(endpoint)
98
101
  url = URI "#{@config_server_host}/api/#{endpoint}"
99
- url.query = URI.encode_www_form data
100
102
  http = Net::HTTP.new url.host, url.port
101
103
  http.use_ssl = url.scheme == 'https'
102
104
 
103
- request = Net::HTTP::Get.new url
104
- configure_request request
105
-
106
- JSON.parse http.request(request).read_body
107
- end
108
-
109
- def configure_request(request)
105
+ request = yield url
110
106
  request['user-agent'] = @user_agent
111
107
  request['authorization'] = "Bearer #{get_token}"
112
108
  request['content-type'] = 'application/json'
113
109
  request['accept'] = 'application/json'
114
110
  request['api-key'] = @config_server_api_key
111
+
112
+ process_response http.request(request)
113
+
114
+ end
115
+
116
+ def process_response(response)
117
+ raise Error, "Unexpected content-type from server: #{response['content-type']}" unless response['content-type'] == 'application/json'
118
+ data = JSON.parse response.read_body
119
+
120
+ raise Error, "Config Server error: #{data['error']}" unless Net::HTTPSuccess === response
121
+ data
122
+
123
+ rescue JSON::ParserError
124
+ raise Error, "Invalid JSON received from #{@config_server_host}"
115
125
  end
116
126
 
117
127
  def get_token
@@ -149,7 +159,7 @@ class ConfigServerAgent
149
159
  @token
150
160
 
151
161
  rescue JSON::ParserError
152
- raise Error, "Invalid response from #{@auth0_host}"
162
+ raise Error, "Invalid JSON received from #{@auth0_host}"
153
163
  end
154
164
 
155
165
  def read_token_cache
@@ -164,6 +174,7 @@ class ConfigServerAgent
164
174
  'token' => @token,
165
175
  'token_expires' => @token_expires
166
176
  }.to_json)
177
+ FileUtils.chmod 'ug=rw,o=', @cache_file
167
178
  end
168
179
  end
169
180
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_server_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aidan Samuel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-12 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lockfile