Class: DatadogBackup::Synthetics
- Inherits:
-
Core
- Object
- Core
- DatadogBackup::Synthetics
show all
- Defined in:
- lib/datadog_backup/synthetics.rb
Overview
Synthetic specific overrides for backup and restore.
Instance Method Summary
collapse
Methods inherited from Core
#api_service, #api_url, #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, #force_restore, #output_format, #resources
#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
39
40
41
42
|
# File 'lib/datadog_backup/synthetics.rb', line 39
def initialize(options)
super(options)
@banlist = %w[creator created_at modified_at monitor_id public_id].freeze
end
|
Instance Method Details
#all ⇒ Object
6
7
8
|
# File 'lib/datadog_backup/synthetics.rb', line 6
def all
get_all.fetch('tests')
end
|
#api_resource_name(body = nil) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/datadog_backup/synthetics.rb', line 14
def api_resource_name(body = nil)
return 'synthetics/tests' if body.nil?
return 'synthetics/tests' if body['type'].nil?
return 'synthetics/tests/browser' if body['type'].to_s == 'browser'
return 'synthetics/tests/api' if body['type'].to_s == 'api'
raise "Unknown type #{body['type']}"
end
|
#api_version ⇒ Object
10
11
12
|
# File 'lib/datadog_backup/synthetics.rb', line 10
def api_version
'v1'
end
|
#backup ⇒ Object
27
28
29
30
31
32
|
# File 'lib/datadog_backup/synthetics.rb', line 27
def backup
all.map do |synthetic|
id = synthetic[id_keyname]
get_and_write_file(id)
end
end
|
#create(body) ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/datadog_backup/synthetics.rb', line 44
def create(body)
create_api_resource_name = api_resource_name(body)
= {}
response = api_service.post("/api/#{api_version}/#{create_api_resource_name}", body, )
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
34
35
36
37
|
# File 'lib/datadog_backup/synthetics.rb', line 34
def get_by_id(id)
synthetic = all.select { |s| s[id_keyname].to_s == id.to_s }.first
synthetic.nil? ? {} : except(synthetic)
end
|
#id_keyname ⇒ Object
23
24
25
|
# File 'lib/datadog_backup/synthetics.rb', line 23
def id_keyname
'public_id'
end
|
#update(id, body) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/datadog_backup/synthetics.rb', line 55
def update(id, body)
update_api_resource_name = api_resource_name(body)
= {}
response = api_service.put("/api/#{api_version}/#{update_api_resource_name}/#{id}", body, )
resbody = body_with_2xx(response)
LOGGER.warn "Successfully restored #{id} to datadog."
LOGGER.info 'Invalidating cache'
@get_all = nil
resbody
end
|