class NewRelic::Agent::NewRelicService::SecurityPolicySettings::Validator

Public Class Methods

new(preconnect_response) click to toggle source
# 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

Public Instance Methods

validate_matching_agent_config!() click to toggle source
# 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