Class: Datadog::Core::Remote::Transport::HTTP::Config::Response
- Inherits:
-
Object
- Object
- Datadog::Core::Remote::Transport::HTTP::Config::Response
- Includes:
- Transport::HTTP::Response
- Defined in:
- lib/datadog/core/remote/transport/http/config.rb
Overview
Response from HTTP transport for remote configuration
Defined Under Namespace
Classes: AgentErrorResponse, ConfigError, DecodeError, KeyError, ParseError, TypeError
Instance Attribute Summary collapse
-
#client_configs ⇒ Object
readonly
Returns the value of attribute client_configs.
-
#roots ⇒ Object
readonly
Returns the value of attribute roots.
-
#target_files ⇒ Object
readonly
Returns the value of attribute target_files.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(http_response, options = {}) ⇒ Response
constructor
standard:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #inspect ⇒ Object
Methods included from Transport::HTTP::Response
#client_error?, #code, #internal_error?, #not_found?, #ok?, #payload, #server_error?, #unsupported?
Constructor Details
#initialize(http_response, options = {}) ⇒ Response
standard:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 22 def initialize(http_response, = {}) # standard:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity super(http_response) raise AgentErrorResponse.new(http_response.code, http_response.payload) if http_response.code != 200 begin payload = JSON.parse(http_response.payload, symbolize_names: true) rescue JSON::ParserError => e raise ParseError.new(:roots, e) end raise TypeError.new(Hash, payload) unless payload.is_a?(Hash) @empty = true if payload.empty? # TODO: these fallbacks should be improved roots = payload[:roots] || [] targets = payload[:targets] || Datadog::Core::Utils::Base64.strict_encode64('{}') target_files = payload[:target_files] || [] client_configs = payload[:client_configs] || [] raise TypeError.new(Array, roots) unless roots.is_a?(Array) @roots = roots.map do |root| raise TypeError.new(String, root) unless root.is_a?(String) decoded = begin Datadog::Core::Utils::Base64.strict_decode64(root) # TODO: unprocessed, don't symbolize_names rescue ArgumentError raise DecodeError.new(:roots, root) end parsed = begin JSON.parse(decoded) rescue JSON::ParserError raise ParseError.new(:roots, decoded) end # TODO: perform more processing to validate content. til then, no freeze parsed end raise TypeError.new(String, targets) unless targets.is_a?(String) @targets = begin decoded = begin Datadog::Core::Utils::Base64.strict_decode64(targets) rescue ArgumentError raise DecodeError.new(:targets, targets) end parsed = begin JSON.parse(decoded) # TODO: unprocessed, don't symbolize_names rescue JSON::ParserError raise ParseError.new(:targets, decoded) end # TODO: perform more processing to validate content. til then, no freeze parsed end raise TypeError.new(Array, target_files) unless target_files.is_a?(Array) @target_files = target_files.map do |h| raise TypeError.new(Hash, h) unless h.is_a?(Hash) raise KeyError.new(:raw) unless h.key?(:raw) # rubocop:disable Style/RaiseArgs raise KeyError.new(:path) unless h.key?(:path) # rubocop:disable Style/RaiseArgs raw = h[:raw] raise TypeError.new(String, raw) unless raw.is_a?(String) content = begin Datadog::Core::Utils::Base64.strict_decode64(raw) rescue ArgumentError raise DecodeError.new(:target_files, raw) end { path: h[:path].freeze, content: StringIO.new(content.freeze), } end.freeze @client_configs = client_configs.map do |s| raise TypeError.new(String, s) unless s.is_a?(String) s.freeze end.freeze end |
Instance Attribute Details
#client_configs ⇒ Object (readonly)
Returns the value of attribute client_configs.
115 116 117 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 115 def client_configs @client_configs end |
#roots ⇒ Object (readonly)
Returns the value of attribute roots.
115 116 117 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 115 def roots @roots end |
#target_files ⇒ Object (readonly)
Returns the value of attribute target_files.
115 116 117 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 115 def target_files @target_files end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
115 116 117 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 115 def targets @targets end |
Instance Method Details
#empty? ⇒ Boolean
117 118 119 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 117 def empty? @empty end |
#inspect ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/datadog/core/remote/transport/http/config.rb', line 121 def inspect "#{super}, #{ { roots: @roots, targets: @targets, target_files: @target_files, client_configs: @client_configs, }}" end |