Module: LaunchDarkly::Impl::Util
- Defined in:
- lib/ldclient-rb/impl/util.rb
Overview
Class Method Summary collapse
-
.application_header_value(application) ⇒ String
Generate an HTTP Header value containing the application meta information (@see #application).
- .bool?(aObject) ⇒ Boolean
- .current_time_millis ⇒ Object
- .default_http_headers(sdk_key, config) ⇒ Object
- .validate_application_info(app, logger) ⇒ Hash
- .validate_application_value(value, name, logger) ⇒ String
- .validate_payload_filter_key(value, logger) ⇒ String?
Class Method Details
.application_header_value(application) ⇒ String
Generate an HTTP Header value containing the application meta information (@see #application).
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ldclient-rb/impl/util.rb', line 30 def self.application_header_value(application) parts = [] unless application[:id].empty? parts << "application-id/#{application[:id]}" end unless application[:version].empty? parts << "application-version/#{application[:version]}" end parts.join(" ") end |
.bool?(aObject) ⇒ Boolean
4 5 6 |
# File 'lib/ldclient-rb/impl/util.rb', line 4 def self.bool?(aObject) [true,false].include? aObject end |
.current_time_millis ⇒ Object
8 9 10 |
# File 'lib/ldclient-rb/impl/util.rb', line 8 def self.current_time_millis (Time.now.to_f * 1000).to_i end |
.default_http_headers(sdk_key, config) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ldclient-rb/impl/util.rb', line 12 def self.default_http_headers(sdk_key, config) ret = { "Authorization" => sdk_key, "User-Agent" => "RubyClient/" + LaunchDarkly::VERSION } if config.wrapper_name ret["X-LaunchDarkly-Wrapper"] = config.wrapper_name + (config.wrapper_version ? "/" + config.wrapper_version : "") end app_value = application_header_value config.application ret["X-LaunchDarkly-Tags"] = app_value unless app_value.nil? || app_value.empty? ret end |
.validate_application_info(app, logger) ⇒ Hash
72 73 74 75 76 77 |
# File 'lib/ldclient-rb/impl/util.rb', line 72 def self.validate_application_info(app, logger) { id: validate_application_value(app[:id], :id, logger), version: validate_application_value(app[:version], :version, logger), } end |
.validate_application_value(value, name, logger) ⇒ String
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ldclient-rb/impl/util.rb', line 49 def self.validate_application_value(value, name, logger) value = value.to_s return "" if value.empty? if value.length > 64 logger.warn { "Value of application[#{name}] was longer than 64 characters and was discarded" } return "" end if /[^a-zA-Z0-9._-]/.match?(value) logger.warn { "Value of application[#{name}] contained invalid characters and was discarded" } return "" end value end |
.validate_payload_filter_key(value, logger) ⇒ String?
84 85 86 87 88 89 90 91 92 |
# File 'lib/ldclient-rb/impl/util.rb', line 84 def self.validate_payload_filter_key(value, logger) return nil if value.nil? return value if value.is_a?(String) && /^[a-zA-Z0-9][._\-a-zA-Z0-9]*$/.match?(value) logger.warn { "Invalid payload filter configured, full environment will be fetched. Ensure the filter key is not empty and was copied correctly from LaunchDarkly settings." } nil end |