Class: Aikido::Zen::RuntimeSettings

Inherits:
Struct
  • Object
show all
Defined in:
lib/aikido/zen/runtime_settings.rb

Overview

Stores the firewall configuration sourced from the Aikido dashboard. This object is updated by the Agent regularly.

Because the RuntimeSettings object can be modified in runtime, it implements the Observable API, allowing you to subscribe to updates. These are triggered whenever #update_from_json makes a change (i.e. if the settings don’t change, no update is triggered).

You can subscribe to changes with #add_observer(object, func_name), which will call the function passing the settings as an argument.

Defined Under Namespace

Classes: Endpoints, IPSet, ProtectionSettings, RateLimitSettings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRuntimeSettings

Returns a new instance of RuntimeSettings.



15
16
17
18
19
# File 'lib/aikido/zen/runtime_settings.rb', line 15

def initialize(*)
  super
  self.endpoints ||= RuntimeSettings::Endpoints.new
  self.skip_protection_for_ips ||= RuntimeSettings::IPSet.new
end

Instance Attribute Details

#blocked_user_idsArray

Returns:

  • (Array)


14
15
16
# File 'lib/aikido/zen/runtime_settings.rb', line 14

def blocked_user_ids
  @blocked_user_ids
end

#endpointsAikido::Zen::RuntimeSettings::Endpoints



14
15
16
# File 'lib/aikido/zen/runtime_settings.rb', line 14

def endpoints
  @endpoints
end

#heartbeat_intervalInteger

Returns duration in seconds between heartbeat requests to the Aikido server.

Returns:

  • (Integer)

    duration in seconds between heartbeat requests to the Aikido server.



14
15
16
# File 'lib/aikido/zen/runtime_settings.rb', line 14

def heartbeat_interval
  @heartbeat_interval
end

#received_any_statsBoolean

Returns whether the Aikido server has received any data from this application.

Returns:

  • (Boolean)

    whether the Aikido server has received any data from this application.



14
15
16
# File 'lib/aikido/zen/runtime_settings.rb', line 14

def received_any_stats
  @received_any_stats
end

#skip_protection_for_ipsAikido::Zen::RuntimeSettings::IPSet



14
15
16
# File 'lib/aikido/zen/runtime_settings.rb', line 14

def skip_protection_for_ips
  @skip_protection_for_ips
end

#updated_atTime

Returns when these settings were updated in the Aikido dashboard.

Returns:

  • (Time)

    when these settings were updated in the Aikido dashboard.



14
15
16
# File 'lib/aikido/zen/runtime_settings.rb', line 14

def updated_at
  @updated_at
end

Instance Method Details

#update_from_json(data) ⇒ void

This method returns an undefined value.

Parse and interpret the JSON response from the core API with updated settings, and apply the changes. This will also notify any subscriber to updates

Parameters:

  • data (Hash)

    the decoded JSON payload from the /api/runtime/config API endpoint.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aikido/zen/runtime_settings.rb', line 49

def update_from_json(data)
  last_updated_at = updated_at

  self.updated_at = Time.at(data["configUpdatedAt"].to_i / 1000)
  self.heartbeat_interval = (data["heartbeatIntervalInMS"].to_i / 1000)
  self.endpoints = RuntimeSettings::Endpoints.from_json(data["endpoints"])
  self.blocked_user_ids = data["blockedUserIds"]
  self.skip_protection_for_ips = RuntimeSettings::IPSet.from_json(data["allowedIPAddresses"])
  self.received_any_stats = data["receivedAnyStats"]

  Aikido::Zen.agent.updated_settings! if updated_at != last_updated_at
end