Skip to content

Commit 785d1a5

Browse files
committed
add option to set ssl host setting in ruby client
1 parent 7de7c6d commit 785d1a5

File tree

10 files changed

+84
-158
lines changed

10 files changed

+84
-158
lines changed

modules/swagger-codegen/src/main/resources/ruby/api_client.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,23 @@ module {{moduleName}}
8282
update_params_for_auth! header_params, query_params, opts[:auth_names]
8383
{{/hasAuthMethods}}
8484

85+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
86+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
87+
8588
req_opts = {
8689
:method => http_method,
8790
:headers => header_params,
8891
:params => query_params,
8992
:params_encoding => @config.params_encoding,
9093
:timeout => @config.timeout,
9194
:ssl_verifypeer => @config.verify_ssl,
95+
:ssl_verifyhost => _verify_ssl_host,
9296
:sslcert => @config.cert_file,
9397
:sslkey => @config.key_file,
9498
:verbose => @config.debugging
9599
}
96100

101+
# set custom cert, if provided
97102
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
98103

99104
if [:post, :patch, :put, :delete].include?(http_method)

modules/swagger-codegen/src/main/resources/ruby/configuration.mustache

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module {{moduleName}}
6868
# Default to 0 (never times out).
6969
attr_accessor :timeout
7070

71-
### TLS/SSL
71+
### TLS/SSL setting
7272
# Set this to false to skip verifying SSL certificate when calling API from https server.
7373
# Default to true.
7474
#
@@ -77,13 +77,16 @@ module {{moduleName}}
7777
# @return [true, false]
7878
attr_accessor :verify_ssl
7979

80-
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
81-
# Default to nil.
80+
### TLS/SSL setting
81+
# Set this to false to skip verifying SSL host name
82+
# Default to true.
8283
#
83-
# @see The params_encoding option of Ethon. Related source code:
84-
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
85-
attr_accessor :params_encoding
84+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
85+
#
86+
# @return [true, false]
87+
attr_accessor :verify_ssl_host
8688

89+
### TLS/SSL setting
8790
# Set this to customize the certificate file to verify the peer.
8891
#
8992
# @return [String] the path to the certificate file
@@ -92,12 +95,21 @@ module {{moduleName}}
9295
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
9396
attr_accessor :ssl_ca_cert
9497

98+
### TLS/SSL setting
9599
# Client certificate file (for client certificate)
96100
attr_accessor :cert_file
97101

102+
### TLS/SSL setting
98103
# Client private key file (for client certificate)
99104
attr_accessor :key_file
100105

106+
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
107+
# Default to nil.
108+
#
109+
# @see The params_encoding option of Ethon. Related source code:
110+
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
111+
attr_accessor :params_encoding
112+
101113
attr_accessor :inject_format
102114

103115
attr_accessor :force_ending_format
@@ -110,6 +122,7 @@ module {{moduleName}}
110122
@api_key_prefix = {}
111123
@timeout = 0
112124
@verify_ssl = true
125+
@verify_ssl_host = true
113126
@params_encoding = nil
114127
@cert_file = nil
115128
@key_file = nil

samples/client/petstore/ruby/README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
88

99
- API version: 1.0.0
1010
- Package version: 1.0.0
11-
- Build date: 2016-06-29T13:19:03.533-07:00
11+
- Build date: 2016-07-04T22:10:18.328+08:00
1212
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
1313

1414
## Installation
@@ -57,15 +57,30 @@ require 'petstore'
5757

5858
api_instance = Petstore::FakeApi.new
5959

60+
number = 3.4 # Float | None
61+
62+
double = 1.2 # Float | None
63+
64+
string = "string_example" # String | None
65+
66+
byte = "B" # String | None
67+
6068
opts = {
61-
test_code_inject__end: "test_code_inject__end_example" # String | To test code injection */
69+
integer: 56, # Integer | None
70+
int32: 56, # Integer | None
71+
int64: 789, # Integer | None
72+
float: 3.4, # Float | None
73+
binary: "B", # String | None
74+
date: Date.parse("2013-10-20"), # Date | None
75+
date_time: DateTime.parse("2013-10-20T19:20:30+01:00"), # DateTime | None
76+
password: "password_example" # String | None
6277
}
6378

6479
begin
65-
#To test code injection */
66-
api_instance.test_code_inject__end(opts)
80+
#Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
81+
api_instance.test_endpoint_parameters(number, double, string, byte, opts)
6782
rescue Petstore::ApiError => e
68-
puts "Exception when calling FakeApi->test_code_inject__end: #{e}"
83+
puts "Exception when calling FakeApi->test_endpoint_parameters: #{e}"
6984
end
7085

7186
```
@@ -76,7 +91,6 @@ All URIs are relative to *http://petstore.swagger.io/v2*
7691

7792
Class | Method | HTTP request | Description
7893
------------ | ------------- | ------------- | -------------
79-
*Petstore::FakeApi* | [**test_code_inject__end**](docs/FakeApi.md#test_code_inject__end) | **PUT** /fake | To test code injection */
8094
*Petstore::FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
8195
*Petstore::FakeApi* | [**test_enum_query_parameters**](docs/FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
8296
*Petstore::PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
@@ -134,6 +148,12 @@ Class | Method | HTTP request | Description
134148
## Documentation for Authorization
135149

136150

151+
### api_key
152+
153+
- **Type**: API key
154+
- **API key parameter name**: api_key
155+
- **Location**: HTTP header
156+
137157
### petstore_auth
138158

139159
- **Type**: OAuth
@@ -143,9 +163,3 @@ Class | Method | HTTP request | Description
143163
- write:pets: modify pets in your account
144164
- read:pets: read your pets
145165

146-
### api_key
147-
148-
- **Type**: API key
149-
- **API key parameter name**: api_key
150-
- **Location**: HTTP header
151-

samples/client/petstore/ruby/docs/FakeApi.md

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,10 @@ All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**test_code_inject__end**](FakeApi.md#test_code_inject__end) | **PUT** /fake | To test code injection */
87
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
98
[**test_enum_query_parameters**](FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
109

1110

12-
# **test_code_inject__end**
13-
> test_code_inject__end(opts)
14-
15-
To test code injection */
16-
17-
### Example
18-
```ruby
19-
# load the gem
20-
require 'petstore'
21-
22-
api_instance = Petstore::FakeApi.new
23-
24-
opts = {
25-
test_code_inject__end: "test_code_inject__end_example" # String | To test code injection */
26-
}
27-
28-
begin
29-
#To test code injection */
30-
api_instance.test_code_inject__end(opts)
31-
rescue Petstore::ApiError => e
32-
puts "Exception when calling FakeApi->test_code_inject__end: #{e}"
33-
end
34-
```
35-
36-
### Parameters
37-
38-
Name | Type | Description | Notes
39-
------------- | ------------- | ------------- | -------------
40-
**test_code_inject__end** | **String**| To test code injection */ | [optional]
41-
42-
### Return type
43-
44-
nil (empty response body)
45-
46-
### Authorization
47-
48-
No authorization required
49-
50-
### HTTP request headers
51-
52-
- **Content-Type**: application/json, */ =end));(phpinfo(
53-
- **Accept**: application/json, */ end
54-
55-
56-
5711
# **test_endpoint_parameters**
5812
> test_endpoint_parameters(number, double, string, byte, opts)
5913

samples/client/petstore/ruby/docs/MapTest.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**map_map_of_string** | **Hash<String, Hash<String, String>>** | | [optional]
7-
**map_map_of_enum** | **Hash<String, Hash<String, String>>** | | [optional]
87
**map_of_enum_string** | **Hash<String, String>** | | [optional]
98

109

samples/client/petstore/ruby/lib/petstore/api/fake_api.rb

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,61 +31,6 @@ def initialize(api_client = ApiClient.default)
3131
@api_client = api_client
3232
end
3333

34-
# To test code injection */
35-
#
36-
# @param [Hash] opts the optional parameters
37-
# @option opts [String] :test_code_inject__end To test code injection */
38-
# @return [nil]
39-
def test_code_inject__end(opts = {})
40-
test_code_inject__end_with_http_info(opts)
41-
return nil
42-
end
43-
44-
# To test code injection */
45-
#
46-
# @param [Hash] opts the optional parameters
47-
# @option opts [String] :test_code_inject__end To test code injection */
48-
# @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers
49-
def test_code_inject__end_with_http_info(opts = {})
50-
if @api_client.config.debugging
51-
@api_client.config.logger.debug "Calling API: FakeApi.test_code_inject__end ..."
52-
end
53-
# resource path
54-
local_var_path = "/fake".sub('{format}','json')
55-
56-
# query parameters
57-
query_params = {}
58-
59-
# header parameters
60-
header_params = {}
61-
62-
# HTTP header 'Accept' (if needed)
63-
local_header_accept = ['application/json', '*/ end']
64-
local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result
65-
66-
# HTTP header 'Content-Type'
67-
local_header_content_type = ['application/json', '*/ =end));(phpinfo(']
68-
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
69-
70-
# form parameters
71-
form_params = {}
72-
form_params["test code inject */ &#x3D;end"] = opts[:'test_code_inject__end'] if !opts[:'test_code_inject__end'].nil?
73-
74-
# http body (model)
75-
post_body = nil
76-
auth_names = []
77-
data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
78-
:header_params => header_params,
79-
:query_params => query_params,
80-
:form_params => form_params,
81-
:body => post_body,
82-
:auth_names => auth_names)
83-
if @api_client.config.debugging
84-
@api_client.config.logger.debug "API called: FakeApi#test_code_inject__end\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
85-
end
86-
return data, status_code, headers
87-
end
88-
8934
# Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
9035
# Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
9136
# @param number None

samples/client/petstore/ruby/lib/petstore/api_client.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,23 @@ def build_request(http_method, path, opts = {})
9999

100100
update_params_for_auth! header_params, query_params, opts[:auth_names]
101101

102+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
103+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
104+
102105
req_opts = {
103106
:method => http_method,
104107
:headers => header_params,
105108
:params => query_params,
106109
:params_encoding => @config.params_encoding,
107110
:timeout => @config.timeout,
108111
:ssl_verifypeer => @config.verify_ssl,
112+
:ssl_verifyhost => _verify_ssl_host,
109113
:sslcert => @config.cert_file,
110114
:sslkey => @config.key_file,
111115
:verbose => @config.debugging
112116
}
113117

118+
# set custom cert, if provided
114119
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
115120

116121
if [:post, :patch, :put, :delete].include?(http_method)
@@ -216,7 +221,7 @@ def convert_to_type(data, return_type)
216221
# @return [Tempfile] the file downloaded
217222
def download_file(response)
218223
content_disposition = response.headers['Content-Disposition']
219-
if content_disposition
224+
if content_disposition and content_disposition =~ /filename=/i
220225
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
221226
prefix = sanitize_filename(filename)
222227
else

0 commit comments

Comments
 (0)