train-rest 0.3.0 → 0.3.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
2
  SHA256:
3
- metadata.gz: 807facd5f597c5fd42ed7044f360601931d8f2ca60cfd79b41969c777e0f631a
4
- data.tar.gz: 87a040c1f16c24f1efe30f7252e02f2100717b4cb241e4cce974a61f9dba095d
3
+ metadata.gz: fd4a52ed234249cf9ae6c2de31b9883061ca31a9d34eb155a5f11e09b461b239
4
+ data.tar.gz: af4665c3c3637eb4c961f5419af4f145c85a2a60ff4125cfa9bc49800e21dae1
5
5
  SHA512:
6
- metadata.gz: d08b4e78394e02f51701ac0927de49e541b38589508d8f28e4327579a296fb074049c706d56d302dd1cf1b03d930727f1b12720303bdceb986f06fb145e27888
7
- data.tar.gz: e518d02e65d85cc826c29f19619250246038e8ed329b72a6e3e9825e8078f594bdc7cb1f971d632574b6f766b899d0aee81b01bd5e6dc074444f021b6f858c54
6
+ metadata.gz: db180b1416450c343f28be8d2223d5610b4a7ec75216d43f4343842250a47149bad30f5f2436e336bff1d3504e5cb817916ef44adf95ae9c65663f8cc56af0ef
7
+ data.tar.gz: 586b34568e078702c3ecabf1f40c6a61bdd4557cf95b953389813563f9d023d5239574d621870f319092e7d33bd436bfc8674a8ca8dc4635d52ef8564f125814
@@ -1,4 +1,4 @@
1
- require_relative "../auth_handler.rb"
1
+ require_relative "../auth_handler"
2
2
 
3
3
  module TrainPlugins
4
4
  module Rest
@@ -1,4 +1,6 @@
1
- require_relative "../auth_handler.rb"
1
+ require "base64" unless defined?(Base64)
2
+
3
+ require_relative "../auth_handler"
2
4
 
3
5
  module TrainPlugins
4
6
  module Rest
@@ -11,8 +13,9 @@ module TrainPlugins
11
13
 
12
14
  def auth_parameters
13
15
  {
14
- user: options[:username],
15
- password: options[:password],
16
+ headers: {
17
+ "Authorization" => format("Basic %s", Base64.encode64(options[:username] + ":" + options[:password]).chomp),
18
+ },
16
19
  }
17
20
  end
18
21
  end
@@ -1,4 +1,4 @@
1
- require_relative "../auth_handler.rb"
1
+ require_relative "../auth_handler"
2
2
 
3
3
  module TrainPlugins
4
4
  module Rest
@@ -1,9 +1,9 @@
1
- require "json"
2
- require "ostruct"
3
- require "uri"
1
+ require "json" unless defined?(JSON)
2
+ require "ostruct" unless defined?(OpenStruct)
3
+ require "uri" unless defined?(URI)
4
4
 
5
- require "rest-client"
6
- require "train"
5
+ require "rest-client" unless defined?(RestClient)
6
+ require "train" unless defined?(Train)
7
7
 
8
8
  module TrainPlugins
9
9
  module Rest
@@ -27,7 +27,7 @@ module TrainPlugins
27
27
  def setup_vcr
28
28
  return unless options[:vcr_cassette]
29
29
 
30
- require "vcr"
30
+ require "vcr" unless defined?(VCR)
31
31
 
32
32
  # TODO: Starts from "/" :(
33
33
  library = options[:vcr_library]
@@ -62,10 +62,12 @@ module TrainPlugins
62
62
  components.to_s
63
63
  end
64
64
 
65
+ # Allow overwriting to refine the type of REST API
66
+ attr_writer :detected_os
67
+
65
68
  def inventory
66
- # Faking it for Chef Target Mode only
67
69
  OpenStruct.new({
68
- name: "rest",
70
+ name: @detected_os || "rest",
69
71
  release: TrainPlugins::Rest::VERSION,
70
72
  family_hierarchy: %w{rest api},
71
73
  family: "api",
@@ -98,8 +100,9 @@ module TrainPlugins
98
100
  parameters[:url] = full_url(path)
99
101
 
100
102
  if json_processing
103
+ parameters[:headers]["Accept"] = "application/json"
101
104
  parameters[:headers]["Content-Type"] = "application/json"
102
- parameters[:payload] = JSON.generate(data)
105
+ parameters[:payload] = JSON.generate(data) unless data.nil?
103
106
  else
104
107
  parameters[:payload] = data
105
108
  end
@@ -172,14 +175,14 @@ module TrainPlugins
172
175
  end
173
176
 
174
177
  def login
175
- logger.info format("REST Login via %s authentication handler", auth_type.to_s) if auth_type != :anonymous
178
+ logger.info format("REST Login via %s authentication handler", auth_type.to_s) unless %i{anonymous basic}.include? auth_type
176
179
 
177
180
  auth_handler.options = options
178
181
  auth_handler.login
179
182
  end
180
183
 
181
184
  def logout
182
- logger.info format("REST Logout via %s authentication handler", auth_type.to_s) if auth_type != :anonymous
185
+ logger.info format("REST Logout via %s authentication handler", auth_type.to_s) unless %i{anonymous basic}.include? auth_type
183
186
 
184
187
  auth_handler.logout
185
188
  end
@@ -1,4 +1,4 @@
1
- require "rubygems"
1
+ require "rubygems" unless defined?(Gem)
2
2
 
3
3
  require "train-rest/connection"
4
4
 
@@ -10,7 +10,7 @@ module TrainPlugins
10
10
  option :endpoint, required: true
11
11
  option :verify_ssl, default: true
12
12
  option :proxy, default: nil
13
- option :headers, default: nil
13
+ option :headers, default: {}
14
14
  option :timeout, default: 120
15
15
 
16
16
  option :auth_type, default: :anonymous
@@ -1,5 +1,5 @@
1
1
  module TrainPlugins
2
2
  module Rest
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "0.3.1".freeze
4
4
  end
5
5
  end
data/train-rest.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "train-rest/version"
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Heinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-24 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train