Class: NewRelic::Agent::NewRelicService::SecurityPolicySettings::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/new_relic_service/security_policy_settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(preconnect_response) ⇒ Validator

Returns a new instance of Validator.



29
30
31
# File 'lib/new_relic/agent/new_relic_service/security_policy_settings.rb', line 29

def initialize(preconnect_response)
  @preconnect_policies = preconnect_response['security_policies'] || {}
end

Instance Method Details

#validate_matching_agent_config!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/new_relic/agent/new_relic_service/security_policy_settings.rb', line 33

def validate_matching_agent_config!
  agent_keys = EXPECTED_SECURITY_POLICIES
  all_server_keys = @preconnect_policies.keys
  required = 'required'
  required_server_keys = @preconnect_policies.keys.select do |key|
    key if @preconnect_policies[key][required]
  end

  missing_from_agent = required_server_keys - agent_keys
  unless missing_from_agent.empty?
    message = "The agent received one or more required security policies \
that it does not recognize and will shut down: #{missing_from_agent.join(',')}. \
Please check if a newer agent version supports these policies or contact support."
    raise NewRelic::Agent::UnrecoverableAgentException.new(message)
  end

  missing_from_server = agent_keys - all_server_keys
  unless missing_from_server.empty?
    message = "The agent did not receive one or more security policies \
that it expected and will shut down: #{missing_from_server.join(',')}. Please \
contact support."
    raise NewRelic::Agent::UnrecoverableAgentException.new(message)
  end
end