Class: ESP::Signature

Inherits:
Resource
  • Object
show all
Defined in:
lib/esp/resources/signature.rb

Constant Summary

Constants inherited from Resource

Resource::PREDICATES

Instance Method Summary collapse

Methods inherited from Resource

arrange_options, filters, find, make_pageable, #serializable_hash, where

Instance Method Details

#destroyObject

Not Implemented. You cannot destroy a Signature.



13
14
15
# File 'lib/esp/resources/signature.rb', line 13

def destroy
  fail ESP::NotImplementedError
end

#run(arguments = {}) ⇒ Object

Run this signature. Returns a collection of alerts. If not successful, returns a Signature object with the errors object populated.

Parameters

arguments | Required | A hash of run arguments

Valid Arguments

See API documentation for valid arguments

Example

signature = ESP::Signature.find(3)
alerts = signature.run(external_account_id: 3, region: 'us_east_1')


54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/esp/resources/signature.rb', line 54

def run(arguments = {})
  arguments = arguments.with_indifferent_access
  attributes['external_account_id'] ||= arguments[:external_account_id]
  attributes['region'] ||= arguments[:region]

  response = connection.post("#{self.class.prefix}signatures/#{id}/run.json", to_json)
  ESP::Alert.send(:instantiate_collection, self.class.format.decode(response.body))
rescue ActiveResource::BadRequest, ActiveResource::ResourceInvalid, ActiveResource::ResourceNotFound => error
  load_remote_errors(error, true)
  self.code = error.response.code
  self
end

#run!(arguments = {}) ⇒ Object

Run this signature. Returns a collection of alerts. Throws an error if not successful.

Parameters

arguments | Required | A hash of run arguments

Valid Arguments

See API documentation for valid arguments

Example

signature = ESP::Signature.find(3)
alerts = signature.run!(external_account_id: 3, region: 'us_east_1')


32
33
34
35
36
37
# File 'lib/esp/resources/signature.rb', line 32

def run!(arguments = {})
  result = run(arguments)
  return result if result.is_a?(ActiveResource::Collection)
  result.message = result.errors.full_messages.join(' ')
  fail(ActiveResource::ResourceInvalid.new(result)) # rubocop:disable Style/RaiseArgs
end

#saveObject

Not Implemented. You cannot create or update a Signature.



8
9
10
# File 'lib/esp/resources/signature.rb', line 8

def save
  fail ESP::NotImplementedError
end

#serviceObject

The service this signature belongs to.



5
# File 'lib/esp/resources/signature.rb', line 5

belongs_to :service, class_name: 'ESP::Service'

#suppress(arguments = {}) ⇒ Object

Create a suppression for this signature.

Parameter

arguments | Required | A hash of signature suppression attributes

Valid Arguments

See API documentation for valid arguments

Example

suppress(regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')


79
80
81
82
# File 'lib/esp/resources/signature.rb', line 79

def suppress(arguments = {})
  arguments = arguments.with_indifferent_access
  ESP::Suppression::Signature.create(signature_ids: [id], regions: Array(arguments[:regions]), external_account_ids: Array(arguments[:external_account_ids]), reason: arguments[:reason])
end