ssrfs-up-v2 0.21.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/openapi_client/lib/openapi_client/api/default_api.rb +88 -0
- data/lib/openapi_client/lib/openapi_client/api_client.rb +426 -0
- data/lib/openapi_client/lib/openapi_client/api_error.rb +57 -0
- data/lib/openapi_client/lib/openapi_client/configuration.rb +306 -0
- data/lib/openapi_client/lib/openapi_client/models/content_type.rb +40 -0
- data/lib/openapi_client/lib/openapi_client/models/method.rb +40 -0
- data/lib/openapi_client/lib/openapi_client/models/redirect.rb +243 -0
- data/lib/openapi_client/lib/openapi_client/models/request.rb +381 -0
- data/lib/openapi_client/lib/openapi_client/models/response.rb +299 -0
- data/lib/openapi_client/lib/openapi_client/models/response_error.rb +225 -0
- data/lib/openapi_client/lib/openapi_client/models/response_success.rb +276 -0
- data/lib/openapi_client/lib/openapi_client/version.rb +15 -0
- data/lib/openapi_client/lib/openapi_client.rb +47 -0
- data/lib/ssrfs-up/version.rb +3 -0
- data/lib/ssrfs-up.rb +201 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f3d06eed09f220989de06bb3ff45767cebdb8df3efa9ded5bce6f9f0fb9f4f3
|
4
|
+
data.tar.gz: 629e351d578ea90365c13da1948ea15cc13245ad38f7c44b4bc469dc4387f173
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0cb1d7978e053a1f9bfc25d2c01a9b0278035172d5d9aa68eb1f6454b765f461ffd46fb4f9827761fa201088878a803cc4278d907e9f0b05849f415accd66ff
|
7
|
+
data.tar.gz: ab15873a7767564ecfa9f1fbd774fc2a4fffffc283c16042225df5c3b0f92e9c3d4d79bff39f75a9191cfeadad4ed93f5533e9c5c2eabe5960473776f4e6101a
|
@@ -0,0 +1,88 @@
|
|
1
|
+
=begin
|
2
|
+
#SSRF Forwarder
|
3
|
+
|
4
|
+
#This is an API that forwards request on behalf of other services.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0-oas3-oas3-oas3
|
7
|
+
Contact: jheath@chanzuckerberg.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.0.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'cgi'
|
14
|
+
|
15
|
+
module OpenapiClient
|
16
|
+
class DefaultApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
# initiates a request
|
23
|
+
# @param request [Request] By passing a URL and/or method and parameters, you can initate an HTTP request.
|
24
|
+
# @param [Hash] opts the optional parameters
|
25
|
+
# @return [Response]
|
26
|
+
def go_post(request, opts = {})
|
27
|
+
data, _status_code, _headers = go_post_with_http_info(request, opts)
|
28
|
+
data
|
29
|
+
end
|
30
|
+
|
31
|
+
# initiates a request
|
32
|
+
# @param request [Request] By passing a URL and/or method and parameters, you can initate an HTTP request.
|
33
|
+
# @param [Hash] opts the optional parameters
|
34
|
+
# @return [Array<(Response, Integer, Hash)>] Response data, response status code and response headers
|
35
|
+
def go_post_with_http_info(request, opts = {})
|
36
|
+
if @api_client.config.debugging
|
37
|
+
@api_client.config.logger.debug 'Calling API: DefaultApi.go_post ...'
|
38
|
+
end
|
39
|
+
# verify the required parameter 'request' is set
|
40
|
+
if @api_client.config.client_side_validation && request.nil?
|
41
|
+
fail ArgumentError, "Missing the required parameter 'request' when calling DefaultApi.go_post"
|
42
|
+
end
|
43
|
+
# resource path
|
44
|
+
local_var_path = '/go'
|
45
|
+
|
46
|
+
# query parameters
|
47
|
+
query_params = opts[:query_params] || {}
|
48
|
+
|
49
|
+
# header parameters
|
50
|
+
header_params = opts[:header_params] || {}
|
51
|
+
# HTTP header 'Accept' (if needed)
|
52
|
+
header_params['Accept'] = @api_client.select_header_accept(['any'])
|
53
|
+
# HTTP header 'Content-Type'
|
54
|
+
content_type = @api_client.select_header_content_type(['application/json'])
|
55
|
+
if !content_type.nil?
|
56
|
+
header_params['Content-Type'] = content_type
|
57
|
+
end
|
58
|
+
|
59
|
+
# form parameters
|
60
|
+
form_params = opts[:form_params] || {}
|
61
|
+
|
62
|
+
# http body (model)
|
63
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(request)
|
64
|
+
|
65
|
+
# return_type
|
66
|
+
return_type = opts[:debug_return_type] || 'Response'
|
67
|
+
|
68
|
+
# auth_names
|
69
|
+
auth_names = opts[:debug_auth_names] || []
|
70
|
+
|
71
|
+
new_options = opts.merge(
|
72
|
+
:operation => :"DefaultApi.go_post",
|
73
|
+
:header_params => header_params,
|
74
|
+
:query_params => query_params,
|
75
|
+
:form_params => form_params,
|
76
|
+
:body => post_body,
|
77
|
+
:auth_names => auth_names,
|
78
|
+
:return_type => return_type
|
79
|
+
)
|
80
|
+
|
81
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
82
|
+
if @api_client.config.debugging
|
83
|
+
@api_client.config.logger.debug "API called: DefaultApi#go_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
84
|
+
end
|
85
|
+
return data, status_code, headers
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,426 @@
|
|
1
|
+
=begin
|
2
|
+
#SSRF Forwarder
|
3
|
+
|
4
|
+
#This is an API that forwards request on behalf of other services.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0-oas3-oas3-oas3
|
7
|
+
Contact: jheath@chanzuckerberg.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.0.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'time'
|
18
|
+
require 'faraday'
|
19
|
+
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
20
|
+
|
21
|
+
module OpenapiClient
|
22
|
+
class ApiClient
|
23
|
+
# The Configuration object holding settings to be used in the API client.
|
24
|
+
attr_accessor :config
|
25
|
+
|
26
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
attr_accessor :default_headers
|
30
|
+
|
31
|
+
# Initializes the ApiClient
|
32
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
33
|
+
def initialize(config = Configuration.default)
|
34
|
+
@config = config
|
35
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
36
|
+
@default_headers = {
|
37
|
+
'Content-Type' => 'application/json',
|
38
|
+
'User-Agent' => @user_agent
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.default
|
43
|
+
@@default ||= ApiClient.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# Call an API with given options.
|
47
|
+
#
|
48
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
49
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
50
|
+
def call_api(http_method, path, opts = {})
|
51
|
+
begin
|
52
|
+
response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
|
53
|
+
build_request(http_method, path, req, opts)
|
54
|
+
end
|
55
|
+
|
56
|
+
if config.debugging
|
57
|
+
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
unless response.success?
|
61
|
+
if response.status == 0
|
62
|
+
# Errors from libcurl will be made visible here
|
63
|
+
fail ApiError.new(code: 0,
|
64
|
+
message: response.return_message)
|
65
|
+
else
|
66
|
+
fail ApiError.new(code: response.status,
|
67
|
+
response_headers: response.headers,
|
68
|
+
response_body: response.body),
|
69
|
+
response.reason_phrase
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue Faraday::TimeoutError
|
73
|
+
fail ApiError.new('Connection timed out')
|
74
|
+
end
|
75
|
+
|
76
|
+
if opts[:return_type]
|
77
|
+
data = deserialize(response, opts[:return_type])
|
78
|
+
else
|
79
|
+
data = nil
|
80
|
+
end
|
81
|
+
return data, response.status, response.headers
|
82
|
+
end
|
83
|
+
|
84
|
+
# Builds the HTTP request
|
85
|
+
#
|
86
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
87
|
+
# @param [String] path URL path (e.g. /account/new)
|
88
|
+
# @option opts [Hash] :header_params Header parameters
|
89
|
+
# @option opts [Hash] :query_params Query parameters
|
90
|
+
# @option opts [Hash] :form_params Query parameters
|
91
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
92
|
+
# @return [Faraday::Request] A Faraday Request
|
93
|
+
def build_request(http_method, path, request, opts = {})
|
94
|
+
url = build_request_url(path, opts)
|
95
|
+
http_method = http_method.to_sym.downcase
|
96
|
+
|
97
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
98
|
+
query_params = opts[:query_params] || {}
|
99
|
+
form_params = opts[:form_params] || {}
|
100
|
+
|
101
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
102
|
+
|
103
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
104
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
105
|
+
if config.debugging
|
106
|
+
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
request.headers = header_params
|
110
|
+
request.body = req_body
|
111
|
+
|
112
|
+
# Overload default options only if provided
|
113
|
+
request.options.params_encoder = config.params_encoder if config.params_encoder
|
114
|
+
request.options.timeout = config.timeout if config.timeout
|
115
|
+
request.options.verbose = config.debugging if config.debugging
|
116
|
+
|
117
|
+
request.url url
|
118
|
+
request.params = query_params
|
119
|
+
download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
120
|
+
request
|
121
|
+
end
|
122
|
+
|
123
|
+
# Builds the HTTP request body
|
124
|
+
#
|
125
|
+
# @param [Hash] header_params Header parameters
|
126
|
+
# @param [Hash] form_params Query parameters
|
127
|
+
# @param [Object] body HTTP body (JSON/XML)
|
128
|
+
# @return [String] HTTP body data in the form of string
|
129
|
+
def build_request_body(header_params, form_params, body)
|
130
|
+
# http form
|
131
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
132
|
+
data = URI.encode_www_form(form_params)
|
133
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
134
|
+
data = {}
|
135
|
+
form_params.each do |key, value|
|
136
|
+
case value
|
137
|
+
when ::File, ::Tempfile
|
138
|
+
# TODO hardcode to application/octet-stream, need better way to detect content type
|
139
|
+
data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
|
140
|
+
when ::Array, nil
|
141
|
+
# let Faraday handle Array and nil parameters
|
142
|
+
data[key] = value
|
143
|
+
else
|
144
|
+
data[key] = value.to_s
|
145
|
+
end
|
146
|
+
end
|
147
|
+
elsif body
|
148
|
+
data = body.is_a?(String) ? body : body.to_json
|
149
|
+
else
|
150
|
+
data = nil
|
151
|
+
end
|
152
|
+
data
|
153
|
+
end
|
154
|
+
|
155
|
+
def download_file(request)
|
156
|
+
@stream = []
|
157
|
+
|
158
|
+
# handle streaming Responses
|
159
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
160
|
+
@stream << chunk
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def connection(opts)
|
165
|
+
opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
|
166
|
+
end
|
167
|
+
|
168
|
+
def connection_multipart
|
169
|
+
@connection_multipart ||= build_connection do |conn|
|
170
|
+
conn.request :multipart
|
171
|
+
conn.request :url_encoded
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def connection_regular
|
176
|
+
@connection_regular ||= build_connection
|
177
|
+
end
|
178
|
+
|
179
|
+
def build_connection
|
180
|
+
Faraday.new(url: config.base_url, ssl: ssl_options) do |conn|
|
181
|
+
basic_auth(conn)
|
182
|
+
config.configure_middleware(conn)
|
183
|
+
yield(conn) if block_given?
|
184
|
+
conn.adapter(Faraday.default_adapter)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def ssl_options
|
189
|
+
{
|
190
|
+
ca_file: config.ssl_ca_file,
|
191
|
+
verify: config.ssl_verify,
|
192
|
+
verify_mode: config.ssl_verify_mode,
|
193
|
+
client_cert: config.ssl_client_cert,
|
194
|
+
client_key: config.ssl_client_key
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
def basic_auth(conn)
|
199
|
+
if config.username && config.password
|
200
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
201
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
202
|
+
else
|
203
|
+
conn.request(:basic_auth, config.username, config.password)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Check if the given MIME is a JSON MIME.
|
209
|
+
# JSON MIME examples:
|
210
|
+
# application/json
|
211
|
+
# application/json; charset=UTF8
|
212
|
+
# APPLICATION/JSON
|
213
|
+
# */*
|
214
|
+
# @param [String] mime MIME
|
215
|
+
# @return [Boolean] True if the MIME is application/json
|
216
|
+
def json_mime?(mime)
|
217
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
218
|
+
end
|
219
|
+
|
220
|
+
# Deserialize the response to the given return type.
|
221
|
+
#
|
222
|
+
# @param [Response] response HTTP response
|
223
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
224
|
+
def deserialize(response, return_type)
|
225
|
+
body = response.body
|
226
|
+
|
227
|
+
# handle file downloading - return the File instance processed in request callbacks
|
228
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
229
|
+
if return_type == 'File'
|
230
|
+
if @config.return_binary_data == true
|
231
|
+
# return byte stream
|
232
|
+
encoding = body.encoding
|
233
|
+
return @stream.join.force_encoding(encoding)
|
234
|
+
else
|
235
|
+
# return file instead of binary data
|
236
|
+
content_disposition = response.headers['Content-Disposition']
|
237
|
+
if content_disposition && content_disposition =~ /filename=/i
|
238
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
239
|
+
prefix = sanitize_filename(filename)
|
240
|
+
else
|
241
|
+
prefix = 'download-'
|
242
|
+
end
|
243
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
244
|
+
encoding = body.encoding
|
245
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
246
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
247
|
+
@tempfile.close
|
248
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
249
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
250
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
251
|
+
"explicitly with `tempfile.delete`"
|
252
|
+
return @tempfile
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
return nil if body.nil? || body.empty?
|
257
|
+
|
258
|
+
# return response body directly for String return type
|
259
|
+
return body if return_type == 'String'
|
260
|
+
|
261
|
+
# ensuring a default content type
|
262
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
263
|
+
|
264
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
265
|
+
|
266
|
+
begin
|
267
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
268
|
+
rescue JSON::ParserError => e
|
269
|
+
if %w(String Date Time).include?(return_type)
|
270
|
+
data = body
|
271
|
+
else
|
272
|
+
raise e
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
convert_to_type data, return_type
|
277
|
+
end
|
278
|
+
|
279
|
+
# Convert data to the given return type.
|
280
|
+
# @param [Object] data Data to be converted
|
281
|
+
# @param [String] return_type Return type
|
282
|
+
# @return [Mixed] Data in a particular type
|
283
|
+
def convert_to_type(data, return_type)
|
284
|
+
return nil if data.nil?
|
285
|
+
case return_type
|
286
|
+
when 'String'
|
287
|
+
data.to_s
|
288
|
+
when 'Integer'
|
289
|
+
data.to_i
|
290
|
+
when 'Float'
|
291
|
+
data.to_f
|
292
|
+
when 'Boolean'
|
293
|
+
data == true
|
294
|
+
when 'Time'
|
295
|
+
# parse date time (expecting ISO 8601 format)
|
296
|
+
Time.parse data
|
297
|
+
when 'Date'
|
298
|
+
# parse date time (expecting ISO 8601 format)
|
299
|
+
Date.parse data
|
300
|
+
when 'Object'
|
301
|
+
# generic object (usually a Hash), return directly
|
302
|
+
data
|
303
|
+
when /\AArray<(.+)>\z/
|
304
|
+
# e.g. Array<Pet>
|
305
|
+
sub_type = $1
|
306
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
307
|
+
when /\AHash\<String, (.+)\>\z/
|
308
|
+
# e.g. Hash<String, Integer>
|
309
|
+
sub_type = $1
|
310
|
+
{}.tap do |hash|
|
311
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
312
|
+
end
|
313
|
+
else
|
314
|
+
# models (e.g. Pet) or oneOf
|
315
|
+
klass = OpenapiClient.const_get(return_type)
|
316
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
# Sanitize filename by removing path.
|
321
|
+
# e.g. ../../sun.gif becomes sun.gif
|
322
|
+
#
|
323
|
+
# @param [String] filename the filename to be sanitized
|
324
|
+
# @return [String] the sanitized filename
|
325
|
+
def sanitize_filename(filename)
|
326
|
+
filename.gsub(/.*[\/\\]/, '')
|
327
|
+
end
|
328
|
+
|
329
|
+
def build_request_url(path, opts = {})
|
330
|
+
# Add leading and trailing slashes to path
|
331
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
332
|
+
@config.base_url(opts[:operation]) + path
|
333
|
+
end
|
334
|
+
|
335
|
+
# Update header and query params based on authentication settings.
|
336
|
+
#
|
337
|
+
# @param [Hash] header_params Header parameters
|
338
|
+
# @param [Hash] query_params Query parameters
|
339
|
+
# @param [String] auth_names Authentication scheme name
|
340
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
341
|
+
Array(auth_names).each do |auth_name|
|
342
|
+
auth_setting = @config.auth_settings[auth_name]
|
343
|
+
next unless auth_setting
|
344
|
+
case auth_setting[:in]
|
345
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
346
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
347
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
# Sets user agent in HTTP header
|
353
|
+
#
|
354
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
355
|
+
def user_agent=(user_agent)
|
356
|
+
@user_agent = user_agent
|
357
|
+
@default_headers['User-Agent'] = @user_agent
|
358
|
+
end
|
359
|
+
|
360
|
+
# Return Accept header based on an array of accepts provided.
|
361
|
+
# @param [Array] accepts array for Accept
|
362
|
+
# @return [String] the Accept header (e.g. application/json)
|
363
|
+
def select_header_accept(accepts)
|
364
|
+
return nil if accepts.nil? || accepts.empty?
|
365
|
+
# use JSON when present, otherwise use all of the provided
|
366
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
367
|
+
json_accept || accepts.join(',')
|
368
|
+
end
|
369
|
+
|
370
|
+
# Return Content-Type header based on an array of content types provided.
|
371
|
+
# @param [Array] content_types array for Content-Type
|
372
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
373
|
+
def select_header_content_type(content_types)
|
374
|
+
# return nil by default
|
375
|
+
return if content_types.nil? || content_types.empty?
|
376
|
+
# use JSON when present, otherwise use the first one
|
377
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
378
|
+
json_content_type || content_types.first
|
379
|
+
end
|
380
|
+
|
381
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
382
|
+
# @param [Object] model object to be converted into JSON string
|
383
|
+
# @return [String] JSON string representation of the object
|
384
|
+
def object_to_http_body(model)
|
385
|
+
return model if model.nil? || model.is_a?(String)
|
386
|
+
local_body = nil
|
387
|
+
if model.is_a?(Array)
|
388
|
+
local_body = model.map { |m| object_to_hash(m) }
|
389
|
+
else
|
390
|
+
local_body = object_to_hash(model)
|
391
|
+
end
|
392
|
+
local_body.to_json
|
393
|
+
end
|
394
|
+
|
395
|
+
# Convert object(non-array) to hash.
|
396
|
+
# @param [Object] obj object to be converted into JSON string
|
397
|
+
# @return [String] JSON string representation of the object
|
398
|
+
def object_to_hash(obj)
|
399
|
+
if obj.respond_to?(:to_hash)
|
400
|
+
obj.to_hash
|
401
|
+
else
|
402
|
+
obj
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
# Build parameter value according to the given collection format.
|
407
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
408
|
+
def build_collection_param(param, collection_format)
|
409
|
+
case collection_format
|
410
|
+
when :csv
|
411
|
+
param.join(',')
|
412
|
+
when :ssv
|
413
|
+
param.join(' ')
|
414
|
+
when :tsv
|
415
|
+
param.join("\t")
|
416
|
+
when :pipes
|
417
|
+
param.join('|')
|
418
|
+
when :multi
|
419
|
+
# return the array directly as typhoeus will handle it as expected
|
420
|
+
param
|
421
|
+
else
|
422
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
=begin
|
2
|
+
#SSRF Forwarder
|
3
|
+
|
4
|
+
#This is an API that forwards request on behalf of other services.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0-oas3-oas3-oas3
|
7
|
+
Contact: jheath@chanzuckerberg.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.0.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module OpenapiClient
|
14
|
+
class ApiError < StandardError
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
16
|
+
|
17
|
+
# Usage examples:
|
18
|
+
# ApiError.new
|
19
|
+
# ApiError.new("message")
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
22
|
+
def initialize(arg = nil)
|
23
|
+
if arg.is_a? Hash
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
25
|
+
super(arg[:message] || arg['message'])
|
26
|
+
else
|
27
|
+
super arg
|
28
|
+
end
|
29
|
+
|
30
|
+
arg.each do |k, v|
|
31
|
+
instance_variable_set "@#{k}", v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super arg
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Override to_s to display a friendly error message
|
39
|
+
def to_s
|
40
|
+
message
|
41
|
+
end
|
42
|
+
|
43
|
+
def message
|
44
|
+
if @message.nil?
|
45
|
+
msg = "Error message: the server returns an error"
|
46
|
+
else
|
47
|
+
msg = @message
|
48
|
+
end
|
49
|
+
|
50
|
+
msg += "\nHTTP status code: #{code}" if code
|
51
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
52
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
53
|
+
|
54
|
+
msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|