Class: DatadogBackup::Synthetics

Inherits:
Resources show all
Defined in:
lib/datadog_backup/synthetics.rb

Overview

Synthetic specific overrides for backup and restore.

Constant Summary

Constants inherited from Resources

Resources::RETRY_OPTIONS

Instance Method Summary collapse

Methods inherited from Resources

#body_with_2xx, #diff, #except, #get, #get_all, #get_and_write_file, #myclass, #restore

Methods included from Options

#action, #backup_dir, #concurrency_limit, #diff_format, #disable_array_sort, #force_restore, #output_format, #resources

Methods included from LocalFilesystem

#all_file_ids, #all_file_ids_for_selected_resources, #all_files, #class_from_id, #dump, #file_type, #filename, #find_file_by_id, #load_from_file, #load_from_file_by_id, #mydir, #purge, #write_file

Constructor Details

#initialize(options) ⇒ Synthetics

Returns a new instance of Synthetics.



22
23
24
25
# File 'lib/datadog_backup/synthetics.rb', line 22

def initialize(options)
  super(options)
  @banlist = %w[creator created_at modified_at monitor_id public_id].freeze
end

Instance Method Details

#allObject



6
7
8
# File 'lib/datadog_backup/synthetics.rb', line 6

def all
  get_all.fetch('tests')
end

#backupObject



10
11
12
13
14
15
# File 'lib/datadog_backup/synthetics.rb', line 10

def backup
  all.map do |synthetic|
    id = synthetic[id_keyname]
    get_and_write_file(id)
  end
end

#create(body) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/datadog_backup/synthetics.rb', line 27

def create(body)
  create_api_resource_name = api_resource_name(body)
  headers = {}
  response = api_service.post("/api/#{api_version}/#{create_api_resource_name}", body, headers)
  resbody = body_with_2xx(response)
  LOGGER.warn "Successfully created #{resbody.fetch(id_keyname)} in datadog."
  LOGGER.info 'Invalidating cache'
  @get_all = nil
  resbody
end

#get_by_id(id) ⇒ Object



17
18
19
20
# File 'lib/datadog_backup/synthetics.rb', line 17

def get_by_id(id)
  synthetic = all.select { |s| s[id_keyname].to_s == id.to_s }.first
  synthetic.nil? ? {} : except(synthetic)
end

#update(id, body) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/datadog_backup/synthetics.rb', line 38

def update(id, body)
  update_api_resource_name = api_resource_name(body)
  headers = {}
  response = api_service.put("/api/#{api_version}/#{update_api_resource_name}/#{id}", body, headers)
  resbody = body_with_2xx(response)
  LOGGER.warn "Successfully restored #{id} to datadog."
  LOGGER.info 'Invalidating cache'
  @get_all = nil
  resbody
end