You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
8.3 KiB

2 years ago
  1. =begin
  2. #Seaweedfs Master Server API
  3. #The Seaweedfs Master Server API allows you to store blobs
  4. The version of the OpenAPI document: 3.43.0
  5. Generated by: https://openapi-generator.tech
  6. OpenAPI Generator version: 6.4.0
  7. =end
  8. module OpenapiClient
  9. class Configuration
  10. # Defines url scheme
  11. attr_accessor :scheme
  12. # Defines url host
  13. attr_accessor :host
  14. # Defines url base path
  15. attr_accessor :base_path
  16. # Define server configuration index
  17. attr_accessor :server_index
  18. # Define server operation configuration index
  19. attr_accessor :server_operation_index
  20. # Default server variables
  21. attr_accessor :server_variables
  22. # Default server operation variables
  23. attr_accessor :server_operation_variables
  24. # Defines API keys used with API Key authentications.
  25. #
  26. # @return [Hash] key: parameter name, value: parameter value (API key)
  27. #
  28. # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
  29. # config.api_key['api_key'] = 'xxx'
  30. attr_accessor :api_key
  31. # Defines API key prefixes used with API Key authentications.
  32. #
  33. # @return [Hash] key: parameter name, value: API key prefix
  34. #
  35. # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
  36. # config.api_key_prefix['api_key'] = 'Token'
  37. attr_accessor :api_key_prefix
  38. # Defines the username used with HTTP basic authentication.
  39. #
  40. # @return [String]
  41. attr_accessor :username
  42. # Defines the password used with HTTP basic authentication.
  43. #
  44. # @return [String]
  45. attr_accessor :password
  46. # Defines the access token (Bearer) used with OAuth2.
  47. attr_accessor :access_token
  48. # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
  49. # Overrides the access_token if set
  50. # @return [Proc]
  51. attr_accessor :access_token_getter
  52. # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
  53. # details will be logged with `logger.debug` (see the `logger` attribute).
  54. # Default to false.
  55. #
  56. # @return [true, false]
  57. attr_accessor :debugging
  58. # Defines the logger used for debugging.
  59. # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
  60. #
  61. # @return [#debug]
  62. attr_accessor :logger
  63. # Defines the temporary folder to store downloaded files
  64. # (for API endpoints that have file response).
  65. # Default to use `Tempfile`.
  66. #
  67. # @return [String]
  68. attr_accessor :temp_folder_path
  69. # The time limit for HTTP request in seconds.
  70. # Default to 0 (never times out).
  71. attr_accessor :timeout
  72. # Set this to false to skip client side validation in the operation.
  73. # Default to true.
  74. # @return [true, false]
  75. attr_accessor :client_side_validation
  76. ### TLS/SSL setting
  77. # Set this to false to skip verifying SSL certificate when calling API from https server.
  78. # Default to true.
  79. #
  80. # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
  81. #
  82. # @return [true, false]
  83. attr_accessor :verify_ssl
  84. ### TLS/SSL setting
  85. # Set this to false to skip verifying SSL host name
  86. # Default to true.
  87. #
  88. # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
  89. #
  90. # @return [true, false]
  91. attr_accessor :verify_ssl_host
  92. ### TLS/SSL setting
  93. # Set this to customize the certificate file to verify the peer.
  94. #
  95. # @return [String] the path to the certificate file
  96. #
  97. # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
  98. # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
  99. attr_accessor :ssl_ca_cert
  100. ### TLS/SSL setting
  101. # Client certificate file (for client certificate)
  102. attr_accessor :cert_file
  103. ### TLS/SSL setting
  104. # Client private key file (for client certificate)
  105. attr_accessor :key_file
  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. attr_accessor :inject_format
  113. attr_accessor :force_ending_format
  114. def initialize
  115. @scheme = 'https'
  116. @host = '127.0.0.1:9333'
  117. @base_path = ''
  118. @server_index = 0
  119. @server_operation_index = {}
  120. @server_variables = {}
  121. @server_operation_variables = {}
  122. @api_key = {}
  123. @api_key_prefix = {}
  124. @client_side_validation = true
  125. @verify_ssl = true
  126. @verify_ssl_host = true
  127. @cert_file = nil
  128. @key_file = nil
  129. @timeout = 0
  130. @params_encoding = nil
  131. @debugging = false
  132. @inject_format = false
  133. @force_ending_format = false
  134. @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
  135. yield(self) if block_given?
  136. end
  137. # The default Configuration object.
  138. def self.default
  139. @@default ||= Configuration.new
  140. end
  141. def configure
  142. yield(self) if block_given?
  143. end
  144. def scheme=(scheme)
  145. # remove :// from scheme
  146. @scheme = scheme.sub(/:\/\//, '')
  147. end
  148. def host=(host)
  149. # remove http(s):// and anything after a slash
  150. @host = host.sub(/https?:\/\//, '').split('/').first
  151. end
  152. def base_path=(base_path)
  153. # Add leading and trailing slashes to base_path
  154. @base_path = "/#{base_path}".gsub(/\/+/, '/')
  155. @base_path = '' if @base_path == '/'
  156. end
  157. # Returns base URL for specified operation based on server settings
  158. def base_url(operation = nil)
  159. index = server_operation_index.fetch(operation, server_index)
  160. return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
  161. server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
  162. end
  163. # Gets API key (with prefix if set).
  164. # @param [String] param_name the parameter name of API key auth
  165. def api_key_with_prefix(param_name, param_alias = nil)
  166. key = @api_key[param_name]
  167. key = @api_key.fetch(param_alias, key) unless param_alias.nil?
  168. if @api_key_prefix[param_name]
  169. "#{@api_key_prefix[param_name]} #{key}"
  170. else
  171. key
  172. end
  173. end
  174. # Gets access_token using access_token_getter or uses the static access_token
  175. def access_token_with_refresh
  176. return access_token if access_token_getter.nil?
  177. access_token_getter.call
  178. end
  179. # Gets Basic Auth token string
  180. def basic_auth_token
  181. 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
  182. end
  183. # Returns Auth Settings hash for api client.
  184. def auth_settings
  185. {
  186. }
  187. end
  188. # Returns an array of Server setting
  189. def server_settings
  190. [
  191. {
  192. url: "https://127.0.0.1:9333",
  193. description: "No description provided",
  194. }
  195. ]
  196. end
  197. def operation_server_settings
  198. {
  199. }
  200. end
  201. # Returns URL based on server settings
  202. #
  203. # @param index array index of the server settings
  204. # @param variables hash of variable and the corresponding value
  205. def server_url(index, variables = {}, servers = nil)
  206. servers = server_settings if servers == nil
  207. # check array index out of bound
  208. if (index < 0 || index >= servers.size)
  209. fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
  210. end
  211. server = servers[index]
  212. url = server[:url]
  213. return url unless server.key? :variables
  214. # go through variable and assign a value
  215. server[:variables].each do |name, variable|
  216. if variables.key?(name)
  217. if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
  218. url.gsub! "{" + name.to_s + "}", variables[name]
  219. else
  220. fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
  221. end
  222. else
  223. # use default value
  224. url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
  225. end
  226. end
  227. url
  228. end
  229. end
  230. end