setsuzoku 0.11.0 → 0.11.5

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: 36e5b7968d72649e85fed697caf9d4b04613faa1b69e347bc347712743ddb55a
4
- data.tar.gz: 11b0433cee31db3ffb7ee39d36c3c31dd4bab600b238a57a51519770d3453eff
3
+ metadata.gz: 576427e8c71dfaf7306d5c7de069440bc47f4d8d9de185f3eb230a8304ea8162
4
+ data.tar.gz: 24fc28270185bca4db25ac804b783e28ec2e6c505c17e545e35625cc2695ca8e
5
5
  SHA512:
6
- metadata.gz: 27c41fe87bebe18b575359b471c3e7497292c5ba730b8698704352ad7f43f7a6d9824a8ee7d81c8d52e6d3dbb3247e7c4d3024b19cb1909c1e3bfc888fb0f823
7
- data.tar.gz: 1352f256aacaeaa77d3565c5d14992bba7689717ea2c928485f3a4304b62b110db47b1c532ccb0266909f02719539c19ca8165c828973c4a8528ef8e74f23437
6
+ metadata.gz: 66c24bc8e924754a8b47fff0180ebd8ea73c7f42d1ddfe9694c3600850870514b6357a87f86c6b820b657e5393a081ab68d635534a2555dcc10419243540c2d7
7
+ data.tar.gz: f55aae400065ab41b8f5d98e66154f80ca044c8de60cd552b3e29fd3d8d9895d09a930bf9a3e7253d2d5ce835062a75ec89f26cde7275419bda7f0a389dc11f9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- setsuzoku (0.11.0)
4
+ setsuzoku (0.11.5)
5
5
  activesupport (~> 5.0)
6
6
  faraday (~> 0.11)
7
7
  httparty (~> 0.16.4)
@@ -80,7 +80,7 @@ module Setsuzoku
80
80
  self.external_api_handler.call_external_api_wrapper(plugin: self.plugin, request: request, action_details: action_details) do
81
81
  begin
82
82
  # raise if the token is invalid and needs refreshed, but don't raise if we are trying to get a refresh token
83
- raise Setsuzoku::Exception::InvalidAuthCredentials.new unless (request.action == :refresh_token || self.auth_strategy.auth_credential_valid?)
83
+ raise Setsuzoku::Exception::InvalidAuthCredentials.new unless (strategy == :auth || self.auth_strategy.auth_credential_valid?)
84
84
  raw_response = self.perform_external_call(request: request, action_details: action_details, **options)
85
85
  formatted_response = self.parse_response(response: raw_response, response_type: action_details[:actions][request.action][:response_type])
86
86
  success = true
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'active_support/core_ext/class/subclasses'
4
4
  require 'active_support/inflector/methods'
5
+ require 'faraday'
6
+
5
7
  module Setsuzoku
6
8
  module DynamicSpecHelper
7
9
 
@@ -150,20 +152,21 @@ module Setsuzoku
150
152
  stub.each do |action_name, props|
151
153
  props.each do |propz|
152
154
  plugin.api_strategy.current_action = action_name
153
- default_headers = plugin.api_strategy.request_options(propz[:request_format])[:headers] || { 'Authorization' => 'Bearer stubbed_token', 'Content-Type' => "application/#{propz[:request_format]}" }
155
+ default_headers = plugin.api_strategy.request_options(propz[:request_format])[:headers] || { 'Content-Type' => "application/#{propz[:request_format]}" }
154
156
  if plugin.auth_strategy.is_a?(Setsuzoku::Service::WebService::AuthStrategies::BasicAuthStrategy)
155
157
  basic_auth = plugin.api_strategy.request_options(propz[:request_format])[:basic_auth]
156
158
  auth_header = { 'Authorization' => "Basic #{Base64.encode64("#{basic_auth[:username]}:#{basic_auth[:password]}").gsub("\n", '')}" }
157
- default_headers.merge!(auth_header)
159
+ elsif plugin.auth_strategy.is_a?(Setsuzoku::Service::WebService::AuthStrategies::OAuthStrategy)
160
+ auth_header = { 'Authorization' => "Bearer #{plugin.api_strategy.request_options(propz[:request_format])[:token]}" }
158
161
  end
162
+ default_headers.merge!(auth_header) if auth_header
159
163
  headers = propz[:headers] ? [propz[:headers]] : [default_headers]
160
164
  stub_directory ||= "#{plugin.class.plugin_namespace}/#{provider}"
165
+
161
166
  headers.each do |header|
162
- header = {
163
- 'Accept'=>'*/*',
164
- 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
165
- 'User-Agent'=>'Ruby'
166
- }.merge(header.deep_stringify_keys)
167
+ header = Faraday.new.headers
168
+ .merge({'Accept'=>'*/*','Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'})
169
+ .merge(header.deep_stringify_keys)
167
170
 
168
171
  if propz[:stub_data]
169
172
  # we have specified specific stub data for this action
@@ -33,7 +33,7 @@ module Setsuzoku
33
33
  # media_type - 'json'
34
34
  #
35
35
  # @return [Hash] the parsed response object.
36
- sig { override.params(request: T.untyped, action_details: T::Hash[T.untyped, T.untyped], options: T.untyped).returns(Faraday::Response) }
36
+ sig { override.params(request: RestAPIRequest, action_details: T::Hash[T.untyped, T.untyped], options: T.untyped).returns(Faraday::Response) }
37
37
  def perform_external_call(request:, action_details:, **options)
38
38
  request_properties = self.get_request_properties(action_name: request.action, action_details: action_details, req_params: request.body)
39
39
  request_options = self.request_options(request_properties[:request_format], action_details[:actions][request.action])
@@ -43,11 +43,14 @@ module Setsuzoku
43
43
  @faraday = Faraday.new(url: request_properties[:formatted_full_url], request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
44
44
  faraday.request(:multipart) if options[:attachments].present?
45
45
  faraday.request(:url_encoded)
46
- # faraday.basic_auth(request_options[:basic_auth][:username], request_options[:basic_auth][:password]) if request_options[:basic_auth]
47
- faraday.request(:basic_auth, request_options[:basic_auth][:username], request_options[:basic_auth][:password]) if request_options[:basic_auth]
48
- # faraday.response request_properties[:response_format] if request_properties[:response_format]
49
- faraday.authorization(:Bearer, request_properties[:token]) if request_properties[:token]
50
- # request_options[:headers][:Authorization].prepend('Bearer ') if request_options[:headers][:Authorization]
46
+ #TODO: change these to faraday = self.auth_strategy.set_authorization!(request: faraday)
47
+ unless request.without_headers
48
+ if request_options[:token]
49
+ faraday.authorization(:Bearer, request_options[:token])
50
+ elsif request_options[:basic_auth]
51
+ faraday.request(:basic_auth, request_options[:basic_auth][:username], request_options[:basic_auth][:password])
52
+ end
53
+ end
51
54
  faraday.adapter Faraday.default_adapter
52
55
  end
53
56
 
@@ -60,7 +63,11 @@ module Setsuzoku
60
63
  req.body = payload
61
64
  end
62
65
  else
63
- @faraday.headers = request_options[:headers] if request_options[:headers]
66
+ if request.without_headers
67
+ @faraday.headers = {}
68
+ elsif request_options[:headers]
69
+ @faraday.headers = (@faraday.headers || {}).merge(request_options[:headers])
70
+ end
64
71
  resp = @faraday.send(request_properties[:request_method], request_properties[:formatted_full_url], full_request)
65
72
  end
66
73
  resp
@@ -81,7 +88,6 @@ module Setsuzoku
81
88
  request_method = request_method.downcase.to_sym
82
89
  request_format = action[:request_type]
83
90
  response_format = action[:response_type]
84
- token = action[:token]
85
91
  stub_data = action[:stub_data] if for_stub
86
92
  full_url = url + endpoint
87
93
  formatted_full_url, req_params = self.replace_dynamic_vars(full_url: full_url, req_params: req_params)
@@ -93,7 +99,6 @@ module Setsuzoku
93
99
  formatted_full_url: formatted_full_url,
94
100
  req_params: req_params,
95
101
  stub_data: stub_data,
96
- token: token
97
102
  }
98
103
  end
99
104
 
@@ -31,9 +31,7 @@ module Setsuzoku
31
31
  sig { override.returns(T::Hash[Symbol, T.untyped]) }
32
32
  def auth_headers
33
33
  {
34
- headers: {
35
- 'Authorization': "Bearer #{self.credential.token}"
36
- }
34
+ token: self.credential.token
37
35
  }
38
36
  end
39
37
 
@@ -112,7 +110,7 @@ module Setsuzoku
112
110
  sig { params(body: T::Hash[Symbol, String], action: Symbol).void }
113
111
  def get_token!(body, action)
114
112
  success = false
115
- request = self.api_strategy.request_class.new(action: action, body: body)
113
+ request = self.api_strategy.request_class.new(action: action, body: body, without_headers: true)
116
114
 
117
115
  resp = self.api_strategy.call_external_api(request: request, strategy: :auth)
118
116
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Setsuzoku
5
- VERSION = '0.11.0'
5
+ VERSION = '0.11.5'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setsuzoku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Stadtler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-11 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler