Class: Sqreen::EndpointTesting

Inherits:
Object
  • Object
show all
Extended by:
Log::Loggable
Defined in:
lib/sqreen/endpoint_testing.rb

Defined Under Namespace

Classes: ChosenEndpoints, Endpoint

Constant Summary collapse

MAIN_CONTROL_HOST =
'back.sqreen.com'.freeze
MAIN_INJECTION_HOST =
'ingestion.sqreen.com'.freeze
FALLBACK_ENDPOINT_URL =
'https://back.sqreen.io/'.freeze
GLOBAL_TIMEOUT =
30
CONTROL_ERROR_KIND =
'back_sqreen_com_unavailable'.freeze
INGESTION_ERROR_KIND =
'ingestion_sqreen_com_unavailable'.freeze

Class Method Summary collapse

Methods included from Log::Loggable

included, logger

Class Method Details

.no_test_endpoints(config_url, config_ingestion_url) ⇒ Object

reproduces behaviour before endpoint testing was introduced



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sqreen/endpoint_testing.rb', line 45

def no_test_endpoints(config_url, config_ingestion_url)
  endpoints = ChosenEndpoints.new

  endpoints.control = Endpoint.new(
    config_url || "https://#{MAIN_CONTROL_HOST}/", cert_store
  )
  endpoints.ingestion = Endpoint.new(
    config_ingestion_url || "https://#{MAIN_INJECTION_HOST}/", nil
  )

  endpoints
end

.test_endpoints(proxy_url, config_url, config_ingestion_url) ⇒ Object



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
# File 'lib/sqreen/endpoint_testing.rb', line 58

def test_endpoints(proxy_url, config_url, config_ingestion_url)
  proxy_params = create_proxy_params(proxy_url)

  # execute the tests in separate threads and wait for them
  thread_control = Thread.new do
    thread_main(config_url, proxy_params, MAIN_CONTROL_HOST)
  end
  thread_injection = Thread.new do
    thread_main(config_ingestion_url, proxy_params, MAIN_INJECTION_HOST)
  end

  wait_for_threads(thread_control, thread_injection)

  # build and return result
  fallback = Endpoint.new(FALLBACK_ENDPOINT_URL, cert_store)
  endpoints = ChosenEndpoints.new
  endpoints.control = thread_control[:endpoint] || fallback
  endpoints.ingestion = thread_injection[:endpoint] || fallback

  if thread_control[:endpoint_error]
    msg = AgentMessage.new(CONTROL_ERROR_KIND, thread_control[:endpoint_error])
    endpoints.add_message msg
  end
  if thread_injection[:endpoint_error]
    msg = AgentMessage.new(INGESTION_ERROR_KIND, thread_injection[:endpoint_error])
    endpoints.add_message msg
  end

  endpoints
end