Module: TempmailSdk::Config
- Defined in:
- lib/tempmail_sdk/config.rb
Overview
配置模块:全局配置读写与版本号(供 HTTP 客户端缓存失效判断)
Class Method Summary collapse
-
.config_version ⇒ Integer
当前配置版本号.
-
.get_config ⇒ SDKConfig
当前全局配置.
-
.load_env_config ⇒ SDKConfig
从环境变量读取默认配置.
-
.set_config(config = nil, **kwargs) ⇒ Object
设置 SDK 全局配置 设置后自动使已缓存的 HTTP 客户端失效,下次请求按新配置重建.
Class Method Details
.config_version ⇒ Integer
Returns 当前配置版本号.
99 100 101 |
# File 'lib/tempmail_sdk/config.rb', line 99 def config_version @config_version end |
.get_config ⇒ SDKConfig
Returns 当前全局配置.
94 95 96 |
# File 'lib/tempmail_sdk/config.rb', line 94 def get_config @global_config end |
.load_env_config ⇒ SDKConfig
从环境变量读取默认配置
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tempmail_sdk/config.rb', line 48 def load_env_config timeout_str = ENV.fetch("TEMPMAIL_TIMEOUT", nil) timeout = timeout_str&.match?(/\A\d+\z/) ? timeout_str.to_i : 15 insecure = %w[1 true True TRUE].include?(ENV.fetch("TEMPMAIL_INSECURE", "")) dm_tok = (ENV["DROPMAIL_AUTH_TOKEN"] || ENV["DROPMAIL_API_TOKEN"] || "").strip dm_tok = nil if dm_tok.empty? dm_no = %w[1 true yes].include?((ENV["DROPMAIL_NO_AUTO_TOKEN"] || "").strip.downcase) dm_renew = (ENV["DROPMAIL_RENEW_LIFETIME"] || "").strip dm_renew = nil if dm_renew.empty? te_raw = (ENV["TEMPMAIL_TELEMETRY_ENABLED"] || "").strip.downcase telemetry_enabled = nil telemetry_enabled = false if %w[false 0 no].include?(te_raw) telemetry_enabled = true if %w[true 1 yes].include?(te_raw) tu = (ENV["TEMPMAIL_TELEMETRY_URL"] || "").strip tu = nil if tu.empty? apihz_id = (ENV["APIHZ_ID"] || "").strip apihz_id = nil if apihz_id.empty? apihz_key = (ENV["APIHZ_KEY"] || "").strip apihz_key = nil if apihz_key.empty? proxy = ENV.fetch("TEMPMAIL_PROXY", nil) proxy = nil if proxy && proxy.empty? SDKConfig.new( proxy: proxy, timeout: timeout, insecure: insecure, dropmail_auth_token: dm_tok, dropmail_disable_auto_token: dm_no, dropmail_renew_lifetime: dm_renew, telemetry_enabled: telemetry_enabled, telemetry_url: tu, apihz_id: apihz_id, apihz_key: apihz_key ) end |